Ruby leaks on "special" use of include

Just tried to do some fancy (probably inappropriate)
things with include:

module Foo
    def foo
        puts "foo called"
    end
end

class MyClass
    class << self
        def include(*args)
            include *args
        end
    end
    def try_include
        self.class.include Foo
        puts "included Foo"
        self.foo
    end
end

obj = MyClass.new
obj.try_include

When I feed ruby with this code, it fills all available memory
(including swap) and the only way to stop it is per KILL.
BTW: "included Foo" is never printed.

% ruby -v
ruby 1.8.2 (2004-12-25) [i686-linux]

Is this a bug of ruby?

···

--
Stefan

        def include(*args)
            include *args

I hope that you have seen that ::include is recursive

Guy Decoux

module Foo
    def foo
        puts "foo called"
    end
end

class MyClass
    class << self
        def include(*args)
            include *args
        end
    end
    def try_include
        self.class.include Foo
        puts "included Foo"
        self.foo
    end
end

In the normal ruby way to do things, you should replace "self.class.include Foo" by "self.extend Foo".

But, yes, leaking on self.class.include is a bug. If it must not be possible, it should raise an exception instead.

Lionel Thiry

Thanks for the tip! I must have been blind....

···

Am Mittwoch, 29. Dezember 2004 17:09 schrieb ts:

> def include(*args)
> include *args

I hope that you have seen that ::include is recursive

Guy Decoux