Aliasing class methods

B

Bryan Richardson

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
 
S

Stefano Crocco

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top