Created
March 13, 2017 12:24
-
-
Save reggieb/5668bb1cfa6359a9e346f43e0ff9f55a to your computer and use it in GitHub Desktop.
Add a `to_h` method to pre 2.1 ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless [].respond_to? :to_h | |
class Array | |
def to_h | |
Hash[self] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://stackoverflow.com/questions/31683993/undefined-method-to-h-on-ruby-array/42763546#42763546