This code starts by creating the Animal class, and then adds a method named initialize: : initialize class « Class « Ruby






This code starts by creating the Animal class, and then adds a method named initialize:


# In Ruby, the initialize method is called automatically when you use a class to create an object. 

class Animal
  def initialize

  end
end

 








Related examples in the same category

1.the code adds an instance variable named @color that stores the color of the animal to the initialize method:
2.initializes the instance variable @name with the standard initialize method.
3.Define constructor for a class
4.Initialize three attributes