[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

ruby leaks on "special" use of include

Stefan Lang

12/29/2004 4:05:00 PM

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


3 Answers

ts

12/29/2004 4:10:00 PM

0

>>>>> "S" == Stefan Lang <langstefan@gmx.at> writes:

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

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


Guy Decoux




Stefan Lang

12/29/2004 4:15:00 PM

0

Am Mittwoch, 29. Dezember 2004 17:09 schrieb ts:
> >>>>> "S" == Stefan Lang <langstefan@gmx.at> writes:
>
> 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....


Lionel Thiry

12/29/2004 4:18:00 PM

0

> 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