Class: Zafu::OrderedHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/zafu/ordered_hash.rb

Instance Method Summary collapse

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

#dupObject



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

#eachObject



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_keysObject



27
28
29
# File 'lib/zafu/ordered_hash.rb', line 27

def get_keys
  @keys ||= o_keys
end

#keysObject



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_keysObject



26
# File 'lib/zafu/ordered_hash.rb', line 26

alias o_keys keys