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 |
Explain about variables?
How would you create getter and setter methods in ruby?
What is ruby software and where and when it is usefull.
Explain Ruby module?
What are the only two values that are falsy?
Explain about the defined operator in ruby?
How to check whether a directory exist or not in Ruby?
Explain about portability?
What is a struct in ruby?
Tell me the role of modules and mixins in ruby?
What are the operators available in ruby?
What is ruby class?