Module: Enumerable

Defined in:
lib/core_ext/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#meanObject



2
3
4
# File 'lib/core_ext/enumerable.rb', line 2

def mean
  sum / size
end

#symbolize_keys_recObject

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 |options, (key, value)|
      options[(key.to_sym rescue key) || key] = (value.is_a?(Hash)||value.is_a?(Array)) ? value.symbolize_keys_rec : value
      options
    end
  elsif is_a?(Array)
    inject([]) do |options, value|
      options << ((value.is_a?(Hash)||value.is_a?(Array)) ? value.symbolize_keys_rec : value)
      options
    end
  else
    raise Exception.new("Can't do that!")
  end
end