Method precedence

Method precedence is controlled by the following two method separators:

`.`

and `->`

.1

1 + 25.sqrt # means: 1 + sqrt(25)

2

1 + 25->sqrt # means: sqrt(1 + 25)

Copied!

The rules are the following:

`.`

binds the method to the object which precedes the dot`->`

makes everything from its left-side an expression and applies the method on the result

The infix backslash (

`\`

) removes any leading or trailing whitespace at that current position and it's useful for expanding method calls on multiple lines:1

say "abc".uc \

2

.reverse \

3

.chars

Copied!

is equivalent with:

1

say "abc".uc.reverse.chars

Copied!

Last modified 1yr ago

Copy link