Class: Zafu::OrderedHash
- Inherits:
-
Hash
- Object
- Hash
- Zafu::OrderedHash
- Defined in:
- lib/zafu/ordered_hash.rb
Instance Method Summary collapse
- #[]=(k, v) ⇒ Object
- #delete(k) ⇒ Object
- #dup ⇒ Object
- #each ⇒ Object
- #get_keys ⇒ Object
- #keys ⇒ Object
- #merge(hash) ⇒ Object
- #merge!(hash) ⇒ Object
- #o_keys ⇒ Object
Instance Method Details
#[]=(k, v) ⇒ Object
8 9 10 11 |
# File 'lib/zafu/ordered_hash.rb', line 8 def []=(k, v) get_keys << k unless get_keys.include?(k) super end |
#delete(k) ⇒ Object
41 42 43 44 |
# File 'lib/zafu/ordered_hash.rb', line 41 def delete(k) get_keys.delete(k) super end |
#dup ⇒ Object
46 47 48 49 50 |
# File 'lib/zafu/ordered_hash.rb', line 46 def dup copy = super copy.instance_variable_set(:@keys, keys) copy end |
#each ⇒ Object
35 36 37 38 39 |
# File 'lib/zafu/ordered_hash.rb', line 35 def each keys.each do |k| yield(k, self[k]) end end |
#get_keys ⇒ Object
27 28 29 |
# File 'lib/zafu/ordered_hash.rb', line 27 def get_keys @keys ||= o_keys end |
#keys ⇒ Object
31 32 33 |
# File 'lib/zafu/ordered_hash.rb', line 31 def keys get_keys.dup end |
#merge(hash) ⇒ Object
20 21 22 23 24 |
# File 'lib/zafu/ordered_hash.rb', line 20 def merge(hash) res = dup res.merge!(hash) res end |
#merge!(hash) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/zafu/ordered_hash.rb', line 13 def merge!(hash) hash.keys.each do |k| get_keys << k unless get_keys.include?(k) end super end |
#o_keys ⇒ Object
26 |
# File 'lib/zafu/ordered_hash.rb', line 26 alias o_keys keys |