Last active
December 17, 2015 13:59
-
-
Save supaspoida/5620932 to your computer and use it in GitHub Desktop.
Symbol#to_proc_with_hash_support
This file contains 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
def key(k) | |
->(obj) { obj[k] } | |
end | |
[{ this: 'that' }].map &key(:this) |
This file contains 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 Symbol | |
def to_proc | |
proc(&method(:to_proc_with_hash_support)) | |
end | |
def to_proc_with_hash_support(obj) | |
case obj | |
when Hash then obj[self] else send(self) | |
end | |
end | |
end | |
[{ this: 'that' }].map &:this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment