0023 Rightward_assignment

The new assignment operator =>

Version 3.0 introduces Pattern matching, and in particular the rightward assignment operator.

0023-rightward_assignment_1.png

Useful after a long expression in a console or perhaps with a if else block to improve indentation.

0023-rightward_assignment_2.png

This has the advantage of reading the code in the same order of execution, with the assignment being made at the end. The possibility of writing the assignment on the next line has been abandoned, but you can still use \.

0023-rightward_assignment_3.png

⚠️ This is not the equivalent of the = operator. => does not return a value. In the case of multiple assignment, an exception is thrown (as in Python) if the number of elements does not match. Does not allow assignment to an array.

0023-rightward_assignment_4.png

Now waiting for the downward assignment?! https://bugs.ruby-lang.org/issues/17768

Link to Ruby documentation for pattern matching.