O'Reilly logo

Ruby Quick Syntax Reference by Matt Clements

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 10

image

Functions and Methods

We have learned a lot about the Ruby programming language itself in the previous chapters along with its syntax and type characteristics. In this chapter we begin to look at “reusable code,” the ability to write a snippet of code that can be used multiple times during our application. This is sometimes known as the D.R.Y. (Don’t Repeat Yourself) principle.

Technically, because Ruby is a fully object-oriented language, Ruby’s functions are actually all methods, as they are all linked to objects.

Defining and Calling Methods

To call our Hello World multiple times, we will write a simple method named hello, and will ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required