Readable attribute and writable attribute : attr_writer « Class « Ruby






Readable attribute and writable attribute


class Employee
 attr_reader :name
 attr_accessor  :title, :salary

 def initialize( name, title, salary )
   @name = name
   @title = title
   @salary = salary
 end
end

fred = Employee.new("Fred", "Operator", 30000.0)
fred.salary=35000.0

 








Related examples in the same category

1.Using attr_writer :color is the same as if you had done this:
2.Defining and Using an Employee Class