Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/modesty/core_ext/array.rb

Instance Method Summary collapse

Instance Method Details

#hashmapObject



16
17
18
19
20
# File 'lib/modesty/core_ext/array.rb', line 16

def hashmap
  self.map do |e|
    [e, yield(e)]
  end.to_h
end

#histogramObject



3
4
5
6
7
8
9
# File 'lib/modesty/core_ext/array.rb', line 3

def histogram
  hsh = Hash.new(0)
  self.each do |e|
    hsh[e] += 1
  end
  hsh
end

#to_hObject



12
13
14
# File 'lib/modesty/core_ext/array.rb', line 12

def to_h
  Hash[self]
end