Sha256: 98e38eee31f80007ed0ac37729993f20998f0ed35fe77c5bc0b53313994c1fc8

Contents?: true

Size: 453 Bytes

Versions: 3

Compression:

Stored size: 453 Bytes

Contents

module ResourceSet
  module InheritableAttribute
    def inheritable_attr(name)
      instance_eval <<-RUBY
        def #{name}=(v)
          @#{name} = v
        end

        def #{name}
          @#{name} ||= InheritableAttribute.inherit(self, :#{name})
        end
      RUBY
    end

    def self.inherit(klass, name)
      return unless klass.superclass.respond_to?(name) and value = klass.superclass.send(name)
      value.clone
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
resource_set-1.0.2 lib/resource_set/inheritable_attribute.rb
resource_set-1.0.1 lib/resource_set/inheritable_attribute.rb
resource_set-1.0.0 lib/resource_set/inheritable_attribute.rb