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?
Answer / Dinesh Chandra Tripathi
This is called the symbolization shortcut in Ruby. It allows you to pass the method name as a symbol instead of a block. When using &, it dereferences the Proc object from the Symbol and applies it to each element in the array.
| Is This Answer Correct ? | 0 Yes | 0 No |
What is retry statement in ruby?
What is request.xhr?
What is ruby?
Explain about class libraries in ruby?
Explain ruby ranges. What are the ways to define ranges?
Explain about interpolation?
Do you know about dig, float and max?
What is the scope of a local variable in ruby?
How to open a file in Ruby?
Explain ruby strings.
Mention what is the command to create a migration?
Explain about operators in Ruby?