Listing and Chaining Methods

Learn how to find the methods defined for an object and how to call multiple methods on a single line of code.

We'll cover the following

Listing methods

As mentioned before, if you’re curious what methods are defined on a certain object, then you can check the Ruby documentation for the class. Usually, the right page conveniently shows up at the top when you search for “ruby” and the class name.

However, we can also quickly ask the object for its methods. That’s right, methods is a method defined on all objects, just like class and is_a?.

When we call it, it returns (responds with) an array with all method names that the object has.

It makes sense to sort the array to make it easier to read, like so:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy