Ruby Developer Question:

Download Job Interview Questions and Answers PDF

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?

Ruby Developer Interview Question
Ruby Developer Interview Question

Answer:

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.

Download Ruby Developer Interview Questions And Answers PDF

Previous QuestionNext Question
Please explain the role of thread pooling in relation to the thread lifecycle in Ruby?Tell me how you define Instance Variable, Global Variable and Class Variable in Ruby?