attr_accessor add accessor to a class : attr_accessor « Class « Ruby






attr_accessor add accessor to a class


class Person
  attr_accessor :name, :age
end

x = Person.new
x.name = "Fred"
x.age = 10
puts x.name, x.age

 








Related examples in the same category

1.Creating Readable and Writable Attributes: use attr_accessor
2.Get new defined instance methods
3.Use attr_accessor to add a new attribute and set it
4.A logger