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
vim-jar-0.1.0 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/hash_with_object_id_key.rb
vim-jar-0.0.3 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/hash_with_object_id_key.rb
vim-jar-0.0.2 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/hash_with_object_id_key.rb
vim-jar-0.0.1 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/hash_with_object_id_key.rb
rr-1.0.2 lib/rr/hash_with_object_id_key.rb
rr-1.0.1 lib/rr/hash_with_object_id_key.rb
rr-1.0.0 lib/rr/hash_with_object_id_key.rb