Creating an Object : object Creation « Class « Ruby






Creating an Object


# You use the new method to create an object in Ruby.

class Animal
  def initialize
    @color = "red"
  end
  def get_color
    return @color
  end
end

animal = Animal.new

 








Related examples in the same category

1.Alias method name
2.Add private method to Object and call it in instance class