Skip to content

Instantly share code, notes, and snippets.

@delba
Last active December 17, 2015 11:39
Show Gist options
  • Select an option

  • Save delba/5604101 to your computer and use it in GitHub Desktop.

Select an option

Save delba/5604101 to your computer and use it in GitHub Desktop.
Symbol#to_proc
values = [1, 2, 3, 4, 5]
values.inject(&:+) #=> 15
values.inject(10, &:+) #=> 25
values.map &1.method(:+) #=> [2, 3, 4, 5, 6]
class String
def translate(word)
"#{word} => #{self}"
end
end
greetings = ["hello", "hola"]
greetings.map &"bonjour".method(:translate)
#=> ["hello => bonjour", "hola => bonjour"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment