[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: mixing in class methods

Anderson Eric A Civ 81 MDSS/SGSI

10/1/2003 9:09:00 PM

Mark J. Reed wrote:
> Okay, probably a dumb question, but: is there any way to define
> methods in a module which become class methods of any class which
> includes that module?

I can't remember the details off the top of my head by I think it involved
using "extend" instead of "include". So with your example:

module Foo;
class << self
def foo; puts "foo!"; end
end
end

class Bar
extend Foo
end

Bar.foo

When I get back to my desk at home I can check some code that I have where I
did the same thing.

Eric