various #to_h methods
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.travis.yml
Gemfile
LICENSE
README.md
Rakefile
code_of_conduct.md
enum_to_h.gemspec

README.md

enum_to_h

Defines Enumerable#to_h, from feature #6669

Note: as of Ruby 2.1, Enumerable#to_h is already defined in a similar but not identical way. Please take care when mixing this gem with Ruby >=2.1.

Note: for Ruby < 2.0, the to_h gem may be required!

Converts enum to a Hash.

Each element of enum must be a single item, or an array of two items. Duplicate keys are overwritten in order.

[].to_h             #=> {}
[1,2].to_h          #=> {1=>nil, 2=>nil}
(1..2).to_h         #=> {1=>nil, 2=>nil}
[[1,2],[3,4]].to_h  #=> {1=>2, 3=>4}
[[1,2],[1,4]].to_h  #=> {1=>4}