0.1 More Objects and Methods
Looking up methods
Ruby objects are happy to tell you what methods they provide.
As you can see, you get a listing of all the methods on the number 1
that you could invoke.
The names are prefixed with a colon (:
) that you can safely ignore for now.
If you find the results too muddled, you can easily sort them alphabetically.
Try it for yourself - simply call the method sort
on the result of methods
:
Invoking methods with arguments
When talking to an object via its methods, it is possible to give it additional information
so it can give you an appropriate response.
This additional information is called the "arguments to a method." The
name "argument" makes sense if you stop to think about the fact that
methods are the paths of communication between objects.
Here's an example of an argument to the method index
, which finds the position of the argument in the array:
Here, index
is the method and 'paper'
the argument.
If there is more than one argument, they can be passed to the method by simply separating them with commas.
Try using a method that takes two arguments -
Congratulations, guest!
Sign in to save your progress
or