[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: How do you "undef_method" for a class method?

Robert Dober

7/22/2007 5:48:00 PM

On 7/22/07, Chris Thiel <ccthiel@gmail.com> wrote:
> Well, not sure if there's a more elegant approach to this (and there
> probably is) but one way to do it would be to open up the class itself and
> redfine the method to do nothing or raise an exception. I'm curious to see
> if there *is* another way to do this, though.
Let me plead you not to top post first ;)
and then give you the answer

>
> Chris
>
>
> On 7/22/07, Dean Wampler <deanwampler@gmail.com> wrote:
> >
> > Module#undef_method and Module#remove_method work fine for instance
> > methods,
> > but if you specify a class method, your get an error that it doesn't
> > exist.
> > (I'm using ruby 1.8.6.)
> >
> > Is there a way to do this? TIA.
> >
> > Dean
> >
> > --
> > Dean Wampler
> > http://www.object...
> > http://www.aspectprogr...
> > http://www.cont...
> >
>
505/5 > cat remove_method.rb && ruby remove_method.rb
class A
def A.hi
"hello"
end
end

p A.hi
class << A
remove_method :hi
end
p A.hi
"hello"
remove_method.rb:11: undefined method `hi' for A:Class (NoMethodError)
robert@PC:~/log/ruby/ML 19:46:46

If memory serves you should not use undefine_method as it leaks.

HTH
Robert
--

We're on a mission from God. ~ Elwood,

2 Answers

Robert Dober

7/23/2007 9:21:00 AM

0

On 7/23/07, Chris Thiel <ccthiel@gmail.com> wrote:
> On 7/22/07, Robert Dober <robert.dober@gmail.com> wrote:
> >
> >
> > Let me plead you not to top post first ;)
> > and then give you the answer
> >
> > >
> >
> >
> What's that supposed to mean anyhow?
This is a bottom post, you posted at the end of the message you respond to,
99% of us prefer this if possible. Your first post was on top of the message.
It is completely standard to make the remark I made, and normally
nobody takes offense. Maybe there is something wrong with the applied
verb, "to plead" I thought it means "to ask strongly", if I offended
you by a bad choice of language I apologize.
On my behalf I thought that "What's that supposed to mean anyhow" is
quite bad, but surely I am mistaken.
> I was just trying to help...which if I'm not mistaken, is the whole point of
> this list.
No I would not reduce it to that, but it is an important point and I
do not think that I said you did not, did I?
>

Cheers and sorry for my bad English.

Robert
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck

Matthew Rudy Jacobs

7/23/2007 10:52:00 AM

0

Robert Dober wrote:
> On 7/23/07, Chris Thiel <ccthiel@gmail.com> wrote:
>> On 7/22/07, Robert Dober <robert.dober@gmail.com> wrote:
>> >
>> >
>> > Let me plead you not to top post first ;)
>> > and then give you the answer

> This is a bottom post, you posted at the end of the message you respond
> to,
> 99% of us prefer this if possible. Your first post was on top of the
> message.
>
>
> Cheers and sorry for my bad English.
>
> Robert

oh wow,
I didn't know about this.

I read it and thought "what does top posting mean?"
does it mean, "you shouldn't be the first to respond unless you have a
good answer"

but cool,
I'll be mindful of this in the future.
--
Posted via http://www.ruby-....