Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Why is this cause an infinite loop?

Reply
Thread Tools

Why is this cause an infinite loop?

 
 
Trans
Guest
Posts: n/a
 
      07-17-2008
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.

 
Reply With Quote
 
 
 
 
Pit Capitain
Guest
Posts: n/a
 
      07-17-2008
2008/7/17 Trans <(E-Mail Removed)>:
> 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

 
Reply With Quote
 
 
 
 
Trans
Guest
Posts: n/a
 
      07-17-2008


On Jul 17, 10:55=A0am, "Pit Capitain" <(E-Mail Removed)> wrote:
> 2008/7/17 Trans <(E-Mail Removed)>:
>
> > Why is this cause an infinite loop?

>
> > =A0class X
> > =A0 =A0def m; "m"; end
> > =A0end

>
> > =A0class Y < X
> > =A0 =A0def self.method_added(sym)

>
> =A0 =A0 =A0 =A0p sym
>
> > =A0 =A0 =A0alias_method("__#{sym}", sym)
> > =A0 =A0 =A0remove_method(sym)
> > =A0 =A0end
> > =A0end

>
> > =A0class Y
> > =A0 =A0def m; m; end
> > =A0end

>
> > =A0Y.new.__m

>
> Tom, see above. Creating an alias triggers method_added.


Dooh!

Thanks, Pit.

T.

 
Reply With Quote
 
Robert Dober
Guest
Posts: n/a
 
      07-17-2008
On Thu, Jul 17, 2008 at 7:23 PM, Trans <(E-Mail Removed)> wrote:
>
>
> On Jul 17, 10:55 am, "Pit Capitain" <(E-Mail Removed)> wrote:
>> 2008/7/17 Trans <(E-Mail Removed)>:
>>
>> > 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
warning: redefining Object#initialize may cause infinite loop Trans Ruby 3 09-10-2006 02:23 PM
warning: redefining Object#initialize may cause infinite loop Stu Ruby 11 11-13-2004 12:34 AM
will all these messages cause a problem . I am a new subscriber and my computer is downloading 100,000 messages. Will this cause any kind of a problem with my ability to store other items?? Camille White Camille White Computer Support 9 11-08-2004 01:13 AM
Onblur() event cause infinite loop Bartosz Wegrzyn Javascript 2 09-08-2003 12:48 AM



Advertisments