Gary Wright
4/8/2007 11:29:00 PM
On Apr 8, 2007, at 7:10 PM, Thomas Hafner wrote:
> The first solution that I've found is to write Foo.rb like follows:
>
> module Foo
> def foo(s)
> "Hello, #{s}\n"
> end
> end
>
> class << Foo
> include Foo
> end
That is fine. There are several variations:
module Foo
def foo(s)
"Hello, #{s}\n"
end
extend self
end
Your example and my variation enable the module to
respond to *all* of its instance methods.
If you only want the module to respond to some of its instance
methods you'll want to look at the following variations:
module Foo
def foo(s)
"Hello, #{s}\n"
end
module_function :foo
end
or
module Foo;end
def Foo.foo(s)
"Hello, #{s}\n"
end
Gary Wright