Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/wnm_support/core_ext/halved.rb,
lib/wnm_support/core_ext/map_to_hash.rb

Instance Method Summary collapse

Instance Method Details

#halvedObject Also known as: split_to_half



2
3
4
5
# File 'lib/wnm_support/core_ext/halved.rb', line 2

def halved
  half = (size.to_f / 2).round
  [first(half), drop(half)]
end

#map_to_hashObject

usage: [1, 2, 3].map_to_hash { |e| => e + 100 } # => => 101, 2 => 102, 3 => 103



4
5
6
# File 'lib/wnm_support/core_ext/map_to_hash.rb', line 4

def map_to_hash
  map { |e| yield e }.inject({}) { |carry, e| carry.merge! e }
end