Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@supaspoida
Last active December 17, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supaspoida/5620932 to your computer and use it in GitHub Desktop.
Save supaspoida/5620932 to your computer and use it in GitHub Desktop.
Symbol#to_proc_with_hash_support
def key(k)
->(obj) { obj[k] }
end
[{ this: 'that' }].map &key(:this)
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