Sha256: e0a1de3cc55df837021e2961691650ced608283f04cec26456f15758f8e4c8ea
Contents?: true
Size: 577 Bytes
Versions: 20
Compression:
Stored size: 577 Bytes
Contents
require "virtus" # confession: i love virtus' coercion. module Disposable::Twin::Coercion module ClassMethods def property(name, options={}, &block) super(name, options, &block).tap do coercing_setter!(name, options[:type]) # define coercing setter after twin. end end def coercing_setter!(name, type) mod = Module.new do define_method("#{name}=") { |value| super Virtus::Attribute.build(type).coerce(value) } end include mod end end def self.included(includer) includer.extend ClassMethods end end
Version data entries
20 entries across 20 versions & 1 rubygems