Sha256: d9753df75dc563fdb04d19ff9f29f3d4fac3b5071f483cb48065d5374e175daa

Contents?: true

Size: 989 Bytes

Versions: 10

Compression:

Stored size: 989 Bytes

Contents

module Hashme
  module Attributes
    include Enumerable
    
    extend Forwardable

    def_delegators :_attributes, :to_a,
      :==, :eql?, :keys, :values, :each,
      :reject, :reject!, :empty?, :clear, :merge, :merge!,
      :encode_json, :as_json, :to_json, :to_hash,
      :frozen?

    def []=(key, value)
      _attributes[key.to_sym] = value
    end

    def [](key)
      _attributes[key.to_sym]
    end

    def has_key?(key)
      _attributes.has_key?(key.to_sym)
    end

    def delete(key)
      _attributes.delete(key.to_sym)
    end

    def dup
      new = super
      @_attributes = @_attributes.dup
      new
    end

    def clone
      new = super
      @_attributes = @_attributes.clone
      new
    end

    def inspect
      string = keys.collect{|key|
        "#{key}: #{self[key].inspect}"
      }.compact.join(", ")
      "#<#{self.class} #{string}>"
    end

    private

    def _attributes
      @_attributes ||= {}
      @_attributes
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hashme-0.2.6 lib/hashme/attributes.rb
hashme-0.2.5 lib/hashme/attributes.rb
hashme-0.2.4 lib/hashme/attributes.rb
hashme-0.2.3 lib/hashme/attributes.rb
hashme-0.2.2 lib/hashme/attributes.rb
hashme-0.2.1 lib/hashme/attributes.rb
hashme-0.2.0 lib/hashme/attributes.rb
hashme-0.1.2 lib/hashme/attributes.rb
hashme-0.1.1 lib/hashme/attributes.rb
hashme-0.1.0 lib/hashme/attributes.rb