Daniel Schierbeck
6/19/2006 9:24:00 AM
Schüle Daniel wrote:
> one can generate modules with
>
> m = Module.new
>
> m.module_eval do
> def self.a;"a";end
> def b;"b";end
> end
>
> but how can I 'include' them in a class
>
> class A
> include m # this doesn't work
> end
As Tim said, you can assign the module to a constant. This isn't because
#include only accepts modules (that wouldn't even be possible, I think),
but rather it's a scoping issue.
class A
m = Module.new{define_method(:foo){"bar"}}
include m
end
Cheers,
Daniel