Class: RR::HashWithObjectIdKey
- Inherits:
-
Hash
- Object
- Hash
- RR::HashWithObjectIdKey
- Defined in:
- lib/rr/hash_with_object_id_key.rb
Overview
:nodoc:
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
- #each ⇒ Object
- #get_with_object_id ⇒ Object
- #include?(key) ⇒ Boolean
-
#initialize ⇒ HashWithObjectIdKey
constructor
A new instance of HashWithObjectIdKey.
- #keys ⇒ Object
- #set_with_object_id ⇒ Object
Constructor Details
#initialize ⇒ HashWithObjectIdKey
Returns a new instance of HashWithObjectIdKey.
3 4 5 6 7 8 |
# File 'lib/rr/hash_with_object_id_key.rb', line 3 def initialize @keys = {} super do |hash, subject_object| hash.set_with_object_id(subject_object, {}) end end |
Instance Method Details
#[](key) ⇒ Object
11 12 13 14 |
# File 'lib/rr/hash_with_object_id_key.rb', line 11 def [](key) @keys[key.__id__] = key super(key.__id__) end |
#[]=(key, value) ⇒ Object
17 18 19 20 |
# File 'lib/rr/hash_with_object_id_key.rb', line 17 def []=(key, value) @keys[key.__id__] = key super(key.__id__, value) end |
#delete(key) ⇒ Object
28 29 30 31 |
# File 'lib/rr/hash_with_object_id_key.rb', line 28 def delete(key) @keys.delete(key.__id__) super(key.__id__) end |
#each ⇒ Object
22 23 24 25 26 |
# File 'lib/rr/hash_with_object_id_key.rb', line 22 def each super do |object_id, value| yield @keys[object_id], value end end |
#get_with_object_id ⇒ Object
10 |
# File 'lib/rr/hash_with_object_id_key.rb', line 10 alias_method :get_with_object_id, :[] |
#include?(key) ⇒ Boolean
37 38 39 |
# File 'lib/rr/hash_with_object_id_key.rb', line 37 def include?(key) super(key.__id__) end |
#keys ⇒ Object
33 34 35 |
# File 'lib/rr/hash_with_object_id_key.rb', line 33 def keys @keys.values end |
#set_with_object_id ⇒ Object
16 |
# File 'lib/rr/hash_with_object_id_key.rb', line 16 alias_method :set_with_object_id, :[]= |