Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/wnm_support/core_ext/halved.rb,
lib/wnm_support/core_ext/map_to_hash.rb
Instance Method Summary collapse
- #halved ⇒ Object (also: #split_to_half)
-
#map_to_hash ⇒ Object
usage: [1, 2, 3].map_to_hash { |e| => e + 100 } # => => 101, 2 => 102, 3 => 103.
Instance Method Details
#halved ⇒ Object 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_hash ⇒ Object
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 |