Module: BoolAt::Macro::ClassMethods
- Defined in:
- lib/bool_at/macro.rb
Instance Method Summary collapse
Instance Method Details
#bool_at(*keys) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bool_at/macro.rb', line 6 def bool_at(*keys) keys.each do |key| unless key.to_s.include?("_at") raise ArgumentError, "bool_at keys should be prefixed with `_at'" end key_attribute = key method_name = key.to_s.remove("_at") define_method(:"#{method_name}?") do send(key_attribute).present? end define_method(:"#{method_name}!") do send(:"#{key_attribute}=", Time.zone.now) end end end |