Chapter 8. Passing Arguments and Returning Values

image with no caption

In this chapter, you’ll be looking at many of the effects (and side effects) of passing arguments and returning values to and from methods. First, though, I’ll take a moment to summarize the types of methods you’ve used up to now.

Summarizing Instance, Class, and Singleton Methods

An instance method is declared inside a class definition and is intended for use by a specific object or “instance” of the class, like this:

methods.rb

class MyClass # declare instance method def instanceMethod puts( "This is an instance method" ) end end # create object ob = MyClass.new # use instance method ob.instanceMethod ...

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.