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

To call a public method on an instance of a class in Ruby, you can use dot notation to call the method on the instance. For example, if you have a class called Person with a method called greet, you could create an instance of the Person class and call the greet method like so:

main.rb
class Person
  def greet
    puts "Hello!"
  end
end

person = Person.new
person.greet
87 chars
9 lines

This will output "Hello!" to the console. In this example, we create an instance of the Person class using the new method and save it to the person variable. We can then call the greet method on the instance using dot notation (person.greet). This will execute the code inside the greet method and output "Hello!" to the console.

gistlibby LogSnag