Add a method named get_color, which returns the color of animal objects created from this class: : getter setter « Class « Ruby






Add a method named get_color, which returns the color of animal objects created from this class:



class Animal
  def initialize
    @color = "red"
  end

  def get_color
    return @color
  end
end

 








Related examples in the same category

1.Call a member method
2.getter and setter
3.Accessors
4.Define getter for a attribute
5.Make an attribute readable and writable by using attr_reader, attr_writer
6.Provide the getter
7.Setter with calculation
8.Setter with =