call a public property on an instance of a class in ruby

To call a public property on an instance of a class in Ruby, you can use the dot notation followed by the property name.

For instance:

main.rb
class Person
  attr_reader :name

  def initialize(name)
    @name = name
  end
end

# Create a new Person instance
person = Person.new("John")

# Call the public `name` property on the `person` instance
puts person.name
221 chars
14 lines

This code creates a Person class with a public name property and a constructor that sets the name property. It then creates a new Person instance and calls the name property using the dot notation (person.name). The name property returns the name of the person, which is then printed to the console.

gistlibby LogSnag