This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

Object-Oriented Programming
CodeExpectedActual
class Duck
  def quack
    'Quack!'
  end
  def swim
    'Paddle paddle paddle...'
  end
end
class Goose
  def honk
    'Honk!'
  end
  def swim
    'Splash splash splash...'
  end
end
class DuckRecording
  def quack
    play
  end
  def play
    'Quack!'
  end
end
def make_it_quack(Duck duck)
  duck.quack
end
make_it_quack(Duck.new)
"Quack!"
Error! (Exception?) Here's stdout:
SyntaxError: compile error
(irb):25: formal argument cannot be a constant
def make_it_quack(Duck duck)
                      ^
(irb):25: parse error, unexpected tIDENTIFIER, expecting ')'
def make_it_quack(Duck duck)
                           ^
	from (irb):25
NoMethodError: undefined method `make_it_quack' for main:Object
	from (irb):28
make_it_quack(DuckRecording.new)        
TypeException: object not of type Duck
Error! (Exception?) Here's stdout:
NoMethodError: undefined method `make_it_quack' for main:Object
	from (irb):29
def make_it_swim(Duck duck)
  duck.swim
end
make_it_swim(Duck.new)
"Paddle paddle paddle..."
Error! (Exception?) Here's stdout:
SyntaxError: compile error
(irb):30: formal argument cannot be a constant
def make_it_swim(Duck duck)
                     ^
(irb):30: parse error, unexpected tIDENTIFIER, expecting ')'
def make_it_swim(Duck duck)
                          ^
	from (irb):30
NoMethodError: undefined method `make_it_swim' for main:Object
	from (irb):33
make_it_swim(Goose.new)
TypeException: object not of type Goose
Error! (Exception?) Here's stdout:
NoMethodError: undefined method `make_it_swim' for main:Object
	from (irb):34
def make_it_quack(duck)
  duck.quack
end
make_it_quack(Duck.new)
"Quack!" "Quack!"
make_it_quack(DuckRecording.new)
"Quack!" "Quack!"
def make_it_swim(duck)
  duck.swim
end
make_it_swim(Duck.new)
"Paddle paddle paddle..." "Paddle paddle paddle..."
make_it_swim(Goose.new)
"Splash splash splash..." "Splash splash splash..."
make_it_quack(Goose.new)
NoMethodError: undefined method `quack' for #<Goose:0x2bb8a8>
Error! (Exception?) Here's stdout:
NoMethodError: undefined method `quack' for #<Goose:0xb7c08db4>
	from (irb):36:in `make_it_quack'
	from (irb):45
make_it_swim(DuckRecording.new)
NoMethodError: undefined method `swim' for #<DuckRecording:0x2b97d8>
Error! (Exception?) Here's stdout:
NoMethodError: undefined method `swim' for #<DuckRecording:0xb7c06b18>
	from (irb):41:in `make_it_swim'
	from (irb):46