Could someone please help me to understand what the \'send()\' method listed below is used for? The code below, when I am reading it, makes no sense what purpose it\'s serving.<
The send
method is the equivalent of calling the given method on the object. So if the selected_track
variable has a value of 1234, then @performer.send(selected_track)
is the same as @performer.1234
. Or, if selected_track
is "a_whiter_shade_of_pale" then it's like calling @performer.a_whiter_shade_of_pale
.
Presumably, then, the Performer class overrides method_missing
such that you can call it with any track (name or ID, it isn't clear from the above), and it will interpret that as a search for that track within that performer's tracks.