Skip to content

Instantly share code, notes, and snippets.

@aarti
Created November 1, 2013 21:51
Show Gist options
  • Save aarti/7272523 to your computer and use it in GitHub Desktop.
Save aarti/7272523 to your computer and use it in GitHub Desktop.
Symbol#to_proc example
#http://pragdave.pragprog.com/pragdave/2005/11/symbolto_proc.html
#http://ruby-doc.org/core-2.0.0/Symbol.html#method-i-to_proc
2.0.0p247 :001 > a = ["first", "second", "third"]
=> ["first", "second", "third"]
2.0.0p247 :002 > a.collect(&:upcase)
=> ["FIRST", "SECOND", "THIRD"]
2.0.0p247 :003 > a.collect{ |n| n.upcase }
=> ["FIRST", "SECOND", "THIRD"]
2.0.0p247 :004 >
@aarti
Copy link
Author

aarti commented Nov 7, 2013

a.collect(&:upcase) works but a.collect(:upcase) does not work
however
a.reduce(&:+) and a.reduce(:+) both work
2.0.0p247 :008 > a.collect(:+)
ArgumentError: wrong number of arguments (1 for 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment