This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Singleton aliases, C extensions
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Creating aliases for instance methods in Ruby is clear and easy. Creating aliases for class (singleton) methods is easy, but not as clear. Using pure Ruby you would do something like this:
class Foo
def self.test; "test"; end
class << self
alias test2 test
end
end
Foo.test => "test"
Foo.test2 => "test"
Doing this within a C extension is a little different. There's the rb_define_alias() function, but no rb_define_singleton_alias() function. Not to worry - the rb_define_alias() function takes a class or a singleton of the class and does the right thing: