Why is this cause an infinite loop?

T

Trans

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.
 
P

Pit Capitain

2008/7/17 Trans said:
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
 
R

Robert Dober

return if /^__/ === sym.to_s

But you probably figured that out by yourself ;).

Cheers
Robert
 

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
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top