Somewhere I saw a way to simplify ruby blocks with one argument, it basically omitted vertical bars and argument declaration, because it was somehow inlined.
I cannot find it anymore or remember any names to search for.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is a simplifications that works in a few situations.
If you have something like:
You can simplify it to:
The
&converts the symbol to a proc by callingSymbol#to_proc. It doesn’t work with additional arguments, and it only works if you want to invoke a method directly on the block argument. It was introduced in Rails (ActiveSupport), but made its way into core Ruby 1.8.7 and 1.9.