Module: Naplug::Helpers::Hashes
- Defined in:
- lib/naplug/helpers.rb
Instance Method Summary collapse
- #symbolify_keys(hash) ⇒ Object
-
#transform_hash(original, options = {}, &block) ⇒ Object
Thx Avdi Grimm! devblog.avdi.org/2009/11/20/hash-transforms-in-ruby/.
Instance Method Details
#symbolify_keys(hash) ⇒ Object
44 45 46 47 48 |
# File 'lib/naplug/helpers.rb', line 44 def symbolify_keys(hash) transform_hash(hash) {|h, key, value| h[key.to_sym] = value } end |
#transform_hash(original, options = {}, &block) ⇒ Object
Thx Avdi Grimm! devblog.avdi.org/2009/11/20/hash-transforms-in-ruby/
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/naplug/helpers.rb', line 32 def transform_hash(original, ={}, &block) original.inject({}){|result, (key,value)| value = if [:deep] && Hash === value transform_hash(value, , &block) else value end block.call(result,key,value) result } end |