ruby leaks on "special" use of include

S

Stefan Lang

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?
 
T

ts

S> def include(*args)
S> include *args

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


Guy Decoux
 
S

Stefan Lang

Am Mittwoch, 29. Dezember 2004 17:09 schrieb ts:
S> def include(*args)
S> include *args

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


Guy Decoux

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

Lionel Thiry

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top