Module: CheckedAttributes::ClassMethods
- Defined in:
- lib/checked_attributes.rb
Overview
Creates the attr_checked method
Instance Method Summary collapse
-
#attr_checked(attribute, &validation) ⇒ Object
attr_checked evaluates whether the value is valid.
Instance Method Details
#attr_checked(attribute, &validation) ⇒ Object
attr_checked evaluates whether the value is valid
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/checked_attributes.rb', line 13 def attr_checked(attribute, &validation) define_method "#{attribute}=" do |value| raise ArgumentError unless validation.call(value) instance_variable_set("@#{attribute}", value) end define_method attribute do instance_variable_get "@#{attribute}" end end |