0041 Endless_method

Methods without "end"

Originally a joke, to reduce the number of end and « V » code. Ruby 3 finally introduced endless methods when there’s only one expression.

0041-endless_method_1.png

Since Ruby 3.1, parentheses are no longer mandatory in the expression. However, they are for method parameters. The expression can be written on several lines if needed.

0041-endless_method_2.png

⚠️ The = corresponding to an assignment respects the priority rules. What do you think the following code produces?

0041-endless_method_3.png

Links to Ruby documentation for endless method and the history of issue 16746.