Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/glot/hash.rb

Overview

Mixin for hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#reference_namesObject

Returns the value of attribute reference_names.



23
24
25
# File 'lib/glot/hash.rb', line 23

def reference_names
  @reference_names
end

Instance Method Details

#deep_key_sort!Object



14
15
16
17
18
19
20
21
# File 'lib/glot/hash.rb', line 14

def deep_key_sort!
  orig = dup
  clear

  orig.map { |k, v| process(k, v) }.sort.each do |k, v|
    self[k] = v
  end
end

#deep_traverseObject



5
6
7
8
9
10
11
12
# File 'lib/glot/hash.rb', line 5

def deep_traverse
  stack = map { |k, v| [[k], v] }
  until stack.empty?
    key, value = stack.pop
    yield(key, value)
    value.each { |k, v| stack.push [key.dup << k, v] } if value.is_a? Hash
  end
end