O'Reilly logo

Sams Teach Yourself Ruby in 21 Days by Mark Slagell

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

Classes

We know how to create methods for individual objects, but that hardly begins to tap into the power of object-oriented programming. Now we can start thinking about how to mass-produce lots of objects from a single set of specifications.

Let's start with the problem of how to make several philosophers who all agree with each other. We could do it the hard way, telling each one what to say:

jane = Object.new
def jane.philosophize
  puts "People should behave ethically."
end
howard = Object.new
def howard.philosophize
  puts "People should behave ethically."
end
irma = Object.new
def irma.philosophize
  puts "People should behave ethically."
end
# ...

But that looks like a lot of unnecessary work at the keyboard, and of course it is. Since these ...

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