Sha256: 2db42e15d4e91f6224e6f6c74ec7da859dd1dfc52c7e74371eda5b8cb6abcb5e
Contents?: true
Size: 548 Bytes
Versions: 2
Compression:
Stored size: 548 Bytes
Contents
# # A struct # but has an idea of what type attributes should be # # class TypedStruct < Struct def self.new attrs, convs struct = super *attrs struct_attr_convs = Hash.zip(attrs, convs).reject{|a,t| t.nil? } struct.class_eval do cattr_accessor :attr_convs self.attr_convs = struct_attr_convs def remap! attr_convs.each do |attr, conv| curr = self.send(attr) self.send("#{attr}=", curr.send(conv)) if curr.respond_to?(conv) end end end # class_eval struct end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
imw-0.1.1 | lib/imw/utils/extensions/typed_struct.rb |
imw-0.1.0 | lib/imw/utils/extensions/typed_struct.rb |