Sha256: 2bf4c8fe06cee67c58d6b1f5e2ffcf62bc9e9eaff8b31e263c4d4d975d795cac
Contents?: true
Size: 963 Bytes
Versions: 12
Compression:
Stored size: 963 Bytes
Contents
module Uber module InheritableAttr def inheritable_attr(name) instance_eval %Q{ def #{name}=(v) @#{name} = v end def #{name} return @#{name} if instance_variable_defined?(:@#{name}) @#{name} = InheritableAttribute.inherit_for(self, :#{name}) end } end def self.inherit_for(klass, name) return unless klass.superclass.respond_to?(name) value = klass.superclass.send(name) # could be nil. Clone.(value) # this could be dynamic, allowing other inheritance strategies. end class Clone # The second argument allows injecting more types. def self.call(value, uncloneable=uncloneable()) uncloneable.each { |klass| return value if value.kind_of?(klass) } value.clone end def self.uncloneable [Symbol, TrueClass, FalseClass, NilClass] end end end InheritableAttribute = InheritableAttr end
Version data entries
12 entries across 12 versions & 2 rubygems