DEV Community

Discussion on: Level Up Your Ruby Skillz: Working With Arrays

Collapse
 
codeandclay profile image
Oliver

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