Accessors For All
Today I learned that accessors like
attr_reader work in the
class Test def initialize(getter, reader) @getter = getter @reader = reader end private def getter @getter end attr_reader :reader end
2.2.3 :001 > t = Test.new('foo', 'bar') => #<Test:0x007f8f9b259bf8 @getter="foo", @reader="bar"> 2.2.3 :002 > t.send(:getter) => "foo" 2.2.3 :003 > t.send(:reader) => "bar"
This can produce warnings in tests, discussed here:
My current feeling is that these methods are a Ruby convention and should be used whenever appropriate, despite warnings in test.Tweet