Revision: 38204
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 28, 2010 15:15 by Shamaoke
Initial Code
# encoding: utf-8 # Two ways of extending a class by class methods. module M module ClassMethods def one 'ok!' end def two 'ok two!' end end end # I class TestOne class << self include M::ClassMethods end end # II class TestTwo extend M::ClassMethods end puts [ TestOne.one, #=> ok! TestOne.two #=> ok two! ] puts [ TestTwo.one, #=> ok! TestTwo.two #=> ok two! ]
Initial URL
Initial Description
An example which illustrates the ways of extending a class by class methods.
Initial Title
Two ways of extending a class by class methods
Initial Tags
class
Initial Language
Ruby