Using attr_writer :color is the same as if you had done this: : attr_writer « Class « Ruby






Using attr_writer :color is the same as if you had done this:



class Animal
  attr_reader :color
  attr_writer :color

  def initialize(color)
    @color = color
  end
end

class Animal
  attr_reader :color

  def color=(color)
    @color = color
  end

  def initialize(color)
    @color = color
  end
end

 








Related examples in the same category

1.Readable attribute and writable attribute
2.Defining and Using an Employee Class