Sha256: f1558a9b2a6a16055359cc7007cb1001397612b00a1d05059beef746b77355de

Contents?: true

Size: 771 Bytes

Versions: 47

Compression:

Stored size: 771 Bytes

Contents

module RR
  # TODO: Refactor to a side-effect-free strategy.
  class HashWithObjectIdKey < ::Hash #:nodoc:
    def initialize
      @keys = {}
      super
    end

    alias_method :get_with_object_id, :[]

    def [](key)
      @keys[key.__id__] = key
      super(key.__id__)
    end

    def has_key?(key)
      super(key.__id__)
    end

    alias_method :set_with_object_id, :[]=

    def []=(key, value)
      @keys[key.__id__] = key
      super(key.__id__, value)
    end

    def each
      super do |object_id, value|
        yield @keys[object_id], value
      end
    end

    def delete(key)
      @keys.delete(key.__id__)
      super(key.__id__)
    end

    def keys
      @keys.values
    end

    def include?(key)
      super(key.__id__)
    end
  end
end

Version data entries

47 entries across 43 versions & 5 rubygems

Version Path
rr-3.1.1 lib/rr/hash_with_object_id_key.rb
rr-3.1.0 lib/rr/hash_with_object_id_key.rb
rr-3.0.9 lib/rr/hash_with_object_id_key.rb
rr-3.0.8 lib/rr/hash_with_object_id_key.rb
rr-3.0.7 lib/rr/hash_with_object_id_key.rb
rr-3.0.6 lib/rr/hash_with_object_id_key.rb
rr-3.0.5 lib/rr/hash_with_object_id_key.rb
rr-3.0.4 lib/rr/hash_with_object_id_key.rb
rr-3.0.3 lib/rr/hash_with_object_id_key.rb
rr-3.0.2 lib/rr/hash_with_object_id_key.rb
rr-3.0.1 lib/rr/hash_with_object_id_key.rb
rr-3.0.0 lib/rr/hash_with_object_id_key.rb
rr-1.2.1 lib/rr/hash_with_object_id_key.rb
rr-1.2.0 lib/rr/hash_with_object_id_key.rb
rr-1.1.2 lib/rr/hash_with_object_id_key.rb
rr-1.1.2.rc1 lib/rr/hash_with_object_id_key.rb
rr-1.1.1 lib/rr/hash_with_object_id_key.rb
rr-1.1.1.rc1 lib/rr/hash_with_object_id_key.rb
rr-1.1.0 lib/rr/hash_with_object_id_key.rb
rr-1.1.0.rc3 lib/rr/hash_with_object_id_key.rb