attr-protected
Banishing the '@' symbol from my Ruby code, henceforth, by loading a gem.
Why does this exist?
Great question. Turns out doing
@attribute = "something"
is pretty weak-sauce stuff in Ruby. I'd rather call a method.
self.attribute = "something"
This way, if I have fat fingers and spell something wrong, the interpreter tells me. I never claimed to be that smart.
Installing
Just add
gem 'attr_protected'
to your Gemfile. Or
gem install attr_protected
if you aren't using Bundler.
Using
attr_protected
class Example
attr_protected :name, :age
end
This method gives you publically readable i-vars, internally read/writeable
attr_hidden
class Example
attr_protected :name
attr_hidden :age
end
This method gives you publically hidden i-vars, internally read/writeable
Enjoy