Class: Hash
Instance Method Summary collapse
- #deep_stringify_keys! ⇒ Object
- #deep_symbolize_keys! ⇒ Object
-
#deep_transform_keys!(&block) ⇒ Object
Destructively convert all keys by using the block operation.
- #tsort_each_child(node, &block) ⇒ Object
Instance Method Details
#deep_stringify_keys! ⇒ Object
32 33 34 |
# File 'lib/yuyi/core.rb', line 32 def deep_stringify_keys! deep_transform_keys!{ |key| key.to_s rescue key } end |
#deep_symbolize_keys! ⇒ Object
Destructively convert all keys to symbols, as long as they respond to to_sym
. This includes the keys from the root hash and from all nested hashes.
DEPRECATION required for: ruby 1.8.7 can be replaced with activesupport ~4.0
28 29 30 |
# File 'lib/yuyi/core.rb', line 28 def deep_symbolize_keys! deep_transform_keys!{ |key| key.to_sym rescue key } end |
#deep_transform_keys!(&block) ⇒ Object
Destructively convert all keys by using the block operation. This includes the keys from the root hash and from all nested hashes.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/yuyi/core.rb', line 40 def deep_transform_keys! &block keys.each do |key| value = delete(key) self[yield(key)] = case value when Hash value.deep_transform_keys!(&block) when Array value.each{ |e| e.deep_transform_keys!(&block) rescue value } else value end end self end |
#tsort_each_child(node, &block) ⇒ Object
14 15 16 |
# File 'lib/yuyi/core.rb', line 14 def tsort_each_child(node, &block) fetch(node).each(&block) end |