3 ms·
I suppose the author was trying to be explicit for the sake of a reader unfamiliar with Ruby. The typical way to avoid that boilerplate is by using 'attr_acces
by pmahoney 13y ago
I suppose the author was trying to be explicit for the sake of a reader unfamiliar with Ruby. The typical way to avoid that boilerplate is by using 'attr_accessor :sanity', which defines those getter and setter methods (and it is possible to implement attr_accessor or similar directly in Ruby, should you need more boilerplate-reducing helpers).
- Skoofoo 13y agoThis is exactly it. I would commonly use the shorthand for something like this, but I felt that it would only deter from the point I was illustrating, which is that a couple methods can seamlessly act like a variable.