Module: Enumerable
- Defined in:
- lib/core_ext/enumerable.rb
Instance Method Summary collapse
- #mean ⇒ Object
-
#symbolize_keys_rec ⇒ Object
returns a new hash/array keeps object references in tact symbolize a hash recursivly if we encounter an array, we will also call symbolize for every hash or array found.
Instance Method Details
#mean ⇒ Object
2 3 4 |
# File 'lib/core_ext/enumerable.rb', line 2 def mean sum / size end |
#symbolize_keys_rec ⇒ Object
returns a new hash/array keeps object references in tact symbolize a hash recursivly if we encounter an array, we will also call symbolize for every hash or array found
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/core_ext/enumerable.rb', line 10 def symbolize_keys_rec if is_a?(Hash) inject({}) do |, (key, value)| [(key.to_sym rescue key) || key] = (value.is_a?(Hash)||value.is_a?(Array)) ? value.symbolize_keys_rec : value end elsif is_a?(Array) inject([]) do |, value| << ((value.is_a?(Hash)||value.is_a?(Array)) ? value.symbolize_keys_rec : value) end else raise Exception.new("Can't do that!") end end |