Ask a Question related to Ruby, Design and Development.
-
Dmitry V. Sabanin #1
How to alias a class method
Hi!
I've run into problem aliasing a class method, i.e.
I have:
class Abc
self.get_abc arg
...
end
end
And later I need to this method, with saving of
original implementation.
Following code is not working:
alias
rig_get_abc, :get_abc
--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Dmitry V. Sabanin Guest
-
How to Alias a Function name within a Class?
How can I create within a CLASS aliases of a defined function, that is variables with another name which do the very same identical things of an... -
#25580 [WFx]: set_error_handler to a class/method resets class properties when error occurs
ID: 25580 Updated by: sniper@php.net Reported By: paul dot liversidge at recycledpixels dot com Status: Wont... -
#25580 [Opn->WFx]: set_error_handler to a class/method resets class properties when error occurs
ID: 25580 Updated by: sniper@php.net Reported By: paul dot liversidge at recycledpixels dot com -Status: Open... -
#25580 [Opn]: set_error_handler to a class/method resets class properties when error occurs
ID: 25580 User updated by: paul.liversidge@recycledpixels.com Reported By: paul dot liversidge at recycledpixels dot com... -
#25580 [NEW]: set_error_handler to a class/method resets class properties when error occurs
From: paul dot liversidge at recycledpixels dot com Operating system: Windows XP PHP version: 4.3.2 PHP Bug Type: ... -
ts #2
Re: How to alias a class method
>>>>> "D" == Dmitry V Sabanin <sdmitry@lrn.ru> writes:
D> Following code is not working:
D> alias
rig_get_abc, :get_abc
you need to be in the singleton class to make the alias
svg% cat b.rb
#!/usr/bin/ruby
class Abc
def self.get_abc arg
puts "abc"
end
class << self
alias orig_get_abc get_abc
end
end
Abc.orig_get_abc(12)
svg%
svg% b.rb
abc
svg%
Guy Decoux
ts Guest
-
Dmitry V. Sabanin #3
Re: How to alias a class method
On Tuesday 16 September 2003 23:43, ts wrote:
Very nice, thank you!> you need to be in the singleton class to make the alias
>
> svg% cat b.rb
> #!/usr/bin/ruby
> class Abc
> def self.get_abc arg
> puts "abc"
> end
> class << self
> alias orig_get_abc get_abc
> end
> end
>
> Abc.orig_get_abc(12)
> svg%
>
> svg% b.rb
> abc
> svg%
>
> Guy Decoux
--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Dmitry V. Sabanin Guest



Reply With Quote

