Skip to content

Instantly share code, notes, and snippets.

@yuki24
Created January 1, 2015 16:37
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 yuki24/201b0bfc582f41d5663d to your computer and use it in GitHub Desktop.
Save yuki24/201b0bfc582f41d5663d to your computer and use it in GitHub Desktop.
Array#to_proc
class Array
def to_proc
->(obj) { obj[first] }
end unless method_defined?(:to_proc)
end
users = [
{name: "Matz"},
{name: "DHH"},
{name: "Yuki"}
]
users.map(&[:name])
# => ["Matz", "DHH", "Yuki"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment