Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/happy_hash.rb
Instance Method Summary collapse
Instance Method Details
#happy_hash(down_case = false) ⇒ Object
5 6 7 |
# File 'lib/happy_hash.rb', line 5 def happy_hash(down_case=false) sym_keys(self, down_case) end |
#sym_keys(hash, down_case = false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/happy_hash.rb', line 10 def sym_keys(hash, down_case=false) hash.inject({}) { |result, (key, value)| new_key = case key when String then (down_case ? key.to_sym : key.underscore.to_sym) else key end new_value = case value when Hash then sym_keys(value, down_case) when Array then sym_array(value, down_case) else value end result[new_key] = new_value result } end |