kamil89
Joined 3/6/2017
kamil89 said almost 8 years ago on Random Ruby Tips and Tricks :

There's also a trick with passing method instances:

def say_hello(name)
  puts "Hello #{name}"
end
names = ["James", "Jacob", "Jack"]

One way to call say_hello with args from array is:

names.map { |name| say_hello(name) }

And the shortened version with method instance would be:

names.map(&method(:say_hello))