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.

Mixing in Class Methods (written by Phil Tomson)
CodeExpectedActual
module MyLib
  module ClassMethods
    def class_method
      puts "This method was first defined in MyLib::ClassMethods"
    end
  end
end
module MyLib
  def self.included(receiver)
    puts "MyLib is being included in #{receiver}!"
    receiver.extend(ClassMethods)
  end
end
class MyClass
  include MyLib
end
MyLib is being included in MyClass!
MyLib is being included in MyClass!
MyClass.class_method
This method was first defined in MyLib::ClassMethods
This method was first defined in MyLib::ClassMethods