Module: Disposable::Twin::Coercion::ClassMethods
- Defined in:
- lib/disposable/twin/coercion.rb
Instance Method Summary collapse
- #coercing_setter!(name, type, nilify = false) ⇒ Object
- #property(name, options = {}, &block) ⇒ Object
Instance Method Details
#coercing_setter!(name, type, nilify = false) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/disposable/twin/coercion.rb', line 15 def coercing_setter!(name, type, nilify=false) type = type ? (Types::Form::Nil | type) : Types::Form::Nil if nilify mod = Module.new do define_method("#{name}=") do |value| super type.call(value) end end include mod end |
#property(name, options = {}, &block) ⇒ Object
9 10 11 12 13 |
# File 'lib/disposable/twin/coercion.rb', line 9 def property(name, ={}, &block) super(name, , &block).tap do coercing_setter!(name, [:type], [:nilify]) if [:type] || [:nilify] end end |