re: Level Up Your Ruby Skillz: Working With Arrays VIEW POST

TOP OF THREAD FULL DISCUSSION
re: For single methods without argument, you can use shorthand syntax (aka. "passing a proc"): [1, 2, 3, 4].count(&:even?) # => 2
 

You can also define your own methods and do something similar using &method.

def dog?(animal)
  ["spaniel", "schnauzer"].include? animal
end  
["perch", "spaniel", "haddock", "schnauzer", "cod"].count(&method(:dog?))
#=> 2
code of conduct - report abuse