Chapter 7. Methods

image with no caption

You’ve used numerous methods throughout this book. On the whole, they aren’t particularly complicated things, so you may wonder why this chapter, which is all about methods, is so long. As you will discover, there is much more to methods than meets the eye.

Class Methods

The methods you’ve been using so far have been instance methods. An instance method belongs to a specific instance of a class—in other words, to an individual object. It is also possible to write class methods. (Some other languages refer to this kind of method as a static method.) A class method belongs to the class itself. To define a class method, you must precede ...

Get The Book of Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.