Tim Pease
7/13/2007 2:43:00 PM
On 7/13/07, Pedro Cardoso <cardosojp@netcabo.pt> wrote:
> Hello
>
> I wan't to design a Module that defines some methods that I wan't as
> class methods in the classes that includes them. Is it possible?
>
> Thanks
>
module MyModule
module ClassMethods
def class_method_one( )
puts "you're in class method one"
end
def class_method_two( )
puts "you're in class method two"
end
end # module ClassMethods
def self.included( other )
other.extend ClassMethods if Class === other
end
def method_one( )
puts "you're in method one"
end
end
class C
include MyModule
end
C.new.method_one #=> you're in method one
C.class_method_one #=> you're in class method one
C.class_method_two #=> you're in class method two
Blessings,
TwP