Method: Module#attr_tester
- Defined in:
- lib/core/facets/module/attr_tester.rb
#attr_tester(*args) ⇒ Object
TODO:
This method will probably be deprecated.
Create an tester attribute. This creates a single method used to test the attribute for truth.
attr_tester :a
is equivalent to
def a?
@a ? true : @a
end
Note that this method is not a common core extension and is not loaded automatically when using require 'facets'.
CREDIT: Trans
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/core/facets/module/attr_tester.rb', line 24 def attr_tester(*args) code, made = '', [] args.each do |a| code << %{ def #{a}?(truth=nil) @#{a} ? truth || @#{a} : @#{a} end } made << "#{a}?".to_sym end module_eval code made end |