Ross Bamford
5/23/2006 7:38:00 AM
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