Created
July 26, 2011 17:47
-
-
Save mark/1107342 to your computer and use it in GitHub Desktop.
New array methods
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
| class Array | |
| def hashify | |
| Hash.new.tap do |hash| | |
| each { |obj| hash[obj] = yield(obj) } | |
| end | |
| end | |
| def reverse_hashify | |
| Hash.new.tap do |hash| | |
| each { |obj| hash[ yield(obj) ] = obj } | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment