Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Aliasing class methods

Reply
Thread Tools

Aliasing class methods

 
 
Bryan Richardson
Guest
Posts: n/a
 
      01-18-2008
Hello all,

I'm having trouble aliasing class methods. I've tried the following,
but got errors saying the method being aliased doesn't exist for class
"Class".

Class Foo
class << self
alias bar bla
end

def self.bla
puts "Hello"
end
end

Foo.bar

Any suggestions? Thanks! -- BTR

 
Reply With Quote
 
 
 
 
Stefano Crocco
Guest
Posts: n/a
 
      01-18-2008
Alle Friday 18 January 2008, Bryan Richardson ha scritto:
> Hello all,
>
> I'm having trouble aliasing class methods. I've tried the following,
> but got errors saying the method being aliased doesn't exist for class
> "Class".
>
> Class Foo
> class << self
> alias bar bla
> end
>
> def self.bla
> puts "Hello"
> end
> end
>
> Foo.bar
>
> Any suggestions? Thanks! -- BTR


The alias statement is executed as soon as it's found, i.e before Foo.bla is
defined. Since you can't alias something which doesn't exist, you get an
error. Try switching the order:

Class Foo
class << self
alias bar bla
end

def self.bla
puts "Hello"
end
end

Foo.bar

Stefano

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling class methods from class methods, help? Oltmans Python 6 03-11-2009 07:59 PM
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Aliasing a class name? Wesley T Perkins Java 8 07-01-2005 01:56 AM
Array class and pointer aliasing problems Mathieu Benoit C++ 5 01-20-2004 09:51 PM



Advertisments