Sha256: e3fc1b784f2c11e8dcdd8335f2a2f115d2ad39467bbe7ef53376d15b2a94a35f
Contents?: true
Size: 1.09 KB
Versions: 17
Compression:
Stored size: 1.09 KB
Contents
module QueueClassicPlus # From https://github.com/apotonick/uber/blob/master/lib/uber/inheritable_attr.rb which is MIT license module InheritableAttribute 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 tmp = [Symbol, TrueClass, FalseClass, NilClass] tmp += [Fixnum, Bignum] if RUBY_VERSION < '2.4.0' tmp end end end end
Version data entries
17 entries across 17 versions & 1 rubygems