Answers

Question and Answer:

  Home  Ruby Developer

⟩ Tell me in Ruby code, often it is observed that coder uses a short hand form of using an expression like array.map(&method_name) instead of array.map { |element| element.method_name }. How this trick actually works?

When a parameter is passed with “&” in front of it. Ruby will call to_proc on it in an attempt to make it usable as a block. So, symbol to_Proc will invoke the method of the corresponding name on whatever is passed to it. Thus helping our shorthand trick to work.

 133 views

More Questions for you: