Ruby makes creating readable attribute easier with attr_reader : Readable attributes « Class « Ruby






Ruby makes creating readable attribute easier with attr_reader



class Animal
  attr_reader :color

  def initialize(color)
    @color = color
  end
end

animal = Animal.new("brown")
puts "The new animal is " + animal.color

 








Related examples in the same category

1.Creating Readable Attributes