What I know:
I can call a method with object as parameter in ruby like this:
["1", "2", "3"].map(&method(:Integer))
#=> [1, 2, 3]
&method
(basically &
) tells its a proc and not an object. Based on it I can define and call my own method too. Like:
def res_str(val)
puts val
end
["1", "2", "3"].each(&method(:res_str))
# 1
# 2
# 3
#=> ["1", "2", "3"]
Now what if my method takes more than one argument?
def res_str(val, str)
puts "#{val} - #{str}"
end
My Questions:
- How can I pass more than one argument in the method using this technique?
- What is this technique called?
PS: I tried to frame my questions as per my understanding. If I am fundamentally wrong at it, please care to explain.