The initialize method is a special method in Ruby that is automatically called when an object is created. It can be used to set up or initialize any variables that the object will need when it is created.

For example, if you were creating a class to represent a Person, you might use the initialize method to set the person’s name and age:

class Person
def initialize(name, age)
@name = name
@age = age
end
end

person = Person.new(“John”, 30)
puts person.inspect #

Leave a Reply

Your email address will not be published. Required fields are marked *