Aliasing classes

Discussion in 'Ruby' started by Shak Shak, Jun 30, 2010.

  1. Shak Shak

    Shak Shak Guest

    Hi all,

    Is it possible to alias a class? That is for ClassA.run to call
    ClassB.run instead? I have a third party library requiring a dependency
    which I've already defined with my own name. I'm currently subclassing,
    but I was wondering if there was a better way.

    Shak
    --
    Posted via http://www.ruby-forum.com/.
     
    Shak Shak, Jun 30, 2010
    #1
    1. Advertising

  2. [Note: parts of this message were removed to make it a legal post.]

    Yes, you simply set some variable equal to the name of a class and then in
    that scope it's a class alias.

    class A
    attr_accessor :x
    def initialize
    @x = 2
    end
    end

    a = A.new
    puts a.x #=> 2

    B = A
    b = B.new
    puts b.x #=> 2
    puts b.class #=> A

    On Wed, Jun 30, 2010 at 10:55 AM, Shak Shak <> wrote:

    > Hi all,
    >
    > Is it possible to alias a class? That is for ClassA.run to call
    > ClassB.run instead? I have a third party library requiring a dependency
    > which I've already defined with my own name. I'm currently subclassing,
    > but I was wondering if there was a better way.
    >
    > Shak
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >
     
    Jacob Mitchell, Jun 30, 2010
    #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. Tim Tyler

    LCD anti-aliasing in Java

    Tim Tyler, Sep 4, 2003, in forum: Java
    Replies:
    2
    Views:
    1,287
    Tim Tyler
    Sep 5, 2003
  2. Kevin Bertman

    Anti-aliasing GIF Images

    Kevin Bertman, Nov 26, 2004, in forum: Java
    Replies:
    4
    Views:
    752
    marcus
    Nov 29, 2004
  3. Wesley T Perkins

    Aliasing a class name?

    Wesley T Perkins, Jun 28, 2005, in forum: Java
    Replies:
    8
    Views:
    1,965
    John Currier
    Jul 1, 2005
  4. Roedy Green

    More anti-aliasing puzzles

    Roedy Green, Aug 10, 2005, in forum: Java
    Replies:
    25
    Views:
    2,191
    Roedy Green
    Aug 16, 2005
  5. palmis

    aliasing

    palmis, Feb 2, 2006, in forum: Java
    Replies:
    0
    Views:
    730
    palmis
    Feb 2, 2006
Loading...

Share This Page