Aliasing class methods

Discussion in 'Ruby' started by Bryan Richardson, Jan 18, 2008.

  1. 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
    Bryan Richardson, Jan 18, 2008
    #1
    1. Advertising

  2. 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
    Stefano Crocco, Jan 18, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wesley T Perkins

    Aliasing a class name?

    Wesley T Perkins, Jun 28, 2005, in forum: Java
    Replies:
    8
    Views:
    1,959
    John Currier
    Jul 1, 2005
  2. Mathieu Benoit
    Replies:
    5
    Views:
    412
    Benoit Mathieu
    Jan 20, 2004
  3. toton

    aliasing a class

    toton, May 14, 2007, in forum: C++
    Replies:
    9
    Views:
    343
    toton
    May 21, 2007
  4. Oltmans
    Replies:
    6
    Views:
    342
    Terry Reedy
    Mar 11, 2009
  5. Kenneth McDonald
    Replies:
    5
    Views:
    315
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page