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 11

image

Classes and Modules

In the previous chapters we have discussed the basics of the Ruby programming language, without looking at it from an object- oriented point of view. Object orientation is an alternative to the procedural method of programming. Procedural code runs from top to bottom in a very simple and linear way. Object-oriented programming includes creating a set of classes, with associated methods (such as a class called Car, with a method called startEngine). We then initialize these classes by creating instance objects of the class in order to call the method.

#!/usr/bin/env rubyclass Car  def startEngine    puts "Engine Started" ...

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