January 2024
Intermediate to advanced
718 pages
20h 15m
English
This creates a new name that refers to an existing method, operator, global variable, or regular expression backreference ($&, $“, $’, and $+). Local variables, instance variables, class variables, and constants may not be aliased. The parameters to alias may be names or symbols.
| | class Integer |
| | alias plus + |
| | end |
| | 1.plus(3) # => 4 |
| | |
| | alias $prematch $` |
| | "string" =~ /i/ # => 3 |
| | $prematch # => "str" |
| | |
| | alias :cmd :` |
| | cmd "date" # => "Thu Nov 2 17:16:30 CDT 2023\n" |
When a method is aliased, the new name refers to a copy of the original method’s body. If the original method is subsequently redefined, the aliased name will still invoke the original implementation. ...
Read now
Unlock full access