Make an attribute readable and writable by using attr_reader, attr_writer
#!/usr/bin/env ruby
class Dog
attr_reader :bark
attr_writer :bark
end
dog = Dog.new
dog.bark="Woof!"
puts dog.bark # => Woof!
p dog.instance_variables.sort # => ["@bark"]
p Dog.instance_methods.sort - Object.instance_methods # => [ "bark", "bark=" ]
Related examples in the same category