Why is this cause an infinite loop?

Why is this cause an infinite loop?

class X
def m; “m”; end
end

class Y < X
def self.method_added(sym)
alias_method("__#{sym}", sym)
remove_method(sym)
end
end

class Y
def m; m; end
end

Y.new.__m

T.

2008/7/17 Trans [email protected]:

Why is this cause an infinite loop?

class X
def m; “m”; end
end

class Y < X
def self.method_added(sym)

   p sym
 alias_method("__#{sym}", sym)
 remove_method(sym)

end
end

class Y
def m; m; end
end

Y.new.__m

Tom, see above. Creating an alias triggers method_added.

Regards,
Pit

On Jul 17, 10:55 am, “Pit C.” [email protected] wrote:

Y.new.__m

Tom, see above. Creating an alias triggers method_added.

Dooh!

Thanks, Pit.

T.

On Thu, Jul 17, 2008 at 7:23 PM, Trans [email protected] wrote:

On Jul 17, 10:55 am, “Pit C.” [email protected] wrote:

2008/7/17 Trans [email protected]:

class Y < X
def self.method_added(sym)
return if /^__/ === sym.to_s

But you probably figured that out by yourself ;).

Cheers
Robert


http://ruby-smalltalk.blogspot.com/


AALST (n.) One who changes his name to be further to the front
D.Adams; The Meaning of LIFF