[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Undefined method: alias_method

Its Me

5/22/2006 8:57:00 PM

What am I doing wrong here?

C:\>irb
irb(main):001:0> def foo; "foo"; end
=> nil
irb(main):002:0> alias_method :old_foo,:foo
NoMethodError: undefined method `alias_method' for main:Object
from (irb):2
irb(main):003:0>

Thanks!


2 Answers

Its Me

5/22/2006 9:03:00 PM

0

Ah, I needed to get to the (singleton) class first. And then use #send due
to privacy.

irb(main):010:0> (class << self; self; end).send :alias_method, :old_foo,
:foo
=> #<Class:#<Object:0x28a9258>>

Sorry for the noise.

"itsme213" <itsme213@hotmail.com> wrote in message
news:ZApcg.51774$Qq.19574@tornado.texas.rr.com...
> What am I doing wrong here?
>
> C:\>irb
> irb(main):001:0> def foo; "foo"; end
> => nil
> irb(main):002:0> alias_method :old_foo,:foo
> NoMethodError: undefined method `alias_method' for main:Object
> from (irb):2
> irb(main):003:0>
>
> Thanks!
>
>


Ross Bamford

5/23/2006 7:38:00 AM

0

On Mon, 22 May 2006 22:03:28 +0100, itsme213 <itsme213@hotmail.com> wrote:

> Ah, I needed to get to the (singleton) class first. And then use #send
> due
> to privacy.
>
> irb(main):010:0> (class << self; self; end).send :alias_method, :old_foo,
> :foo
> => #<Class:#<Object:0x28a9258>>
>

Just a quick note, I'd tend to prefer something like:

(class << self; self; end).class_eval { alias_method :new, :old }

To prevent this from biting in the future:

RUBY_VERSION
# => "1.9.0"

(class << self; self; end).send :alias_method, :new, :old
NoMethodError: private method `alias_method' called for
#<Class:#<Object:0xb7efca9c>>
from (irb):4:in `Kernel#send'
from (irb):4:in `Kernel#binding'

--
Ross Bamford - rosco@roscopeco.remove.co.uk