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 ruby names?
What are the key features of ruby?
Explain ruby strings.
How symbol is different from variables?
Tell us how would you implement hash in ruby internally?
Tell me how you define instance variable, global variable and class variable in ruby?
Is ruby a dying language?
Are ruby strings are mutable?
Do you know about dig, float and max?
How do you remove nil values in array using ruby?
Explain the use of retry statement in ruby?
what is the purpose of the rakefile available in the demo directory in ruby?