January 1, 2015 by Daniel P. Clark

When to use Ampersand and/or Colon with Proc, Map, and Inject

So with Ruby permitting Procs called on Objects I’ve found sometimes a Colon Method will work, and sometimes you need a Ampersand Colon Method.  For example, when I map &:upcase on a list of strings it works. [“a”,”b”,”c”].map(&:upcase) # = > [“A”, “B”, “C”] But if I try without the Ampersand I get: [“a”,”b”,”c”].map(:upcase) #…

Continue Reading »