January 2024
Intermediate to advanced
718 pages
20h 15m
English
You call a method by optionally specifying a receiver, giving the name of the method, and optionally passing some arguments and an optional block. Here’s a code fragment that shows us calling a method with a receiver, a positional argument, a keyword argument, and a block:
| | connection.download_mp3("jitterbug", speed: :slow) { |p| show_progress(p) } |
In this example, the object connection is the receiver, download_mp3 is the name of the method, the string "jitterbug" is the positional parameter, the key/value pair speed: :slow is a keyword parameter, and the code between the braces is the associated block argument. When the method is called, Ruby invokes the method in that object, and inside that method, self is set to ...
Read now
Unlock full access