Is it possible to change the superclass of one class dynamic

Discussion in 'Ruby' started by Sean Liu, Jul 28, 2008.

  1. Sean Liu

    Sean Liu Guest

    I want to change the super class of one class in one of plugins, for
    example,
    in plugin
    class A < B

    end
    in rails initialization configuration file,
    class A < C

    end

    but when i did this, the error: "TypeError: superclass mismatch"
    appreared.

    So can we change the super class of one class dynamically?

    Thanks.
    --
    Posted via http://www.ruby-forum.com/.
    Sean Liu, Jul 28, 2008
    #1
    1. Advertising

  2. Sean Liu

    Chris Shea Guest

    On Jul 27, 9:47 pm, Sean Liu <> wrote:
    > I want to change the super class of one class in one of plugins, for
    > example,
    > in plugin
    > class A < B
    >
    > end
    > in rails initialization configuration file,
    > class A < C
    >
    > end
    >
    > but when i did this, the error: "TypeError: superclass mismatch"
    > appreared.
    >
    > So can we change the super class of one class dynamically?
    >
    > Thanks.
    > --
    > Posted viahttp://www.ruby-forum.com/.


    No. That is not possible. It is, however, possible to include (and
    extend) modules into a class to change its method and constant lookup
    hierarchy.

    What is it you're actually trying to accomplish by changing the
    superclass?

    Chris
    Chris Shea, Jul 28, 2008
    #2
    1. Advertising

  3. Sean Liu

    Sean Liu Guest

    Re: Is it possible to change the superclass of one class dyn

    Chris Shea wrote:
    > On Jul 27, 9:47�pm, Sean Liu <> wrote:
    >>
    >> but when i did this, the error: "TypeError: superclass mismatch"
    >> appreared.
    >>
    >> So can we change the super class of one class dynamically?
    >>
    >> Thanks.
    >> --
    >> Posted viahttp://www.ruby-forum.com/.

    >
    > No. That is not possible. It is, however, possible to include (and
    > extend) modules into a class to change its method and constant lookup
    > hierarchy.
    >
    > What is it you're actually trying to accomplish by changing the
    > superclass?
    >
    > Chris


    Thanks for quick reply, Chris.
    I just want to change the behavior of one plugin without changing it's
    source code. I think changing the original source code of that plugin
    isn't too bad if we can't change the super class dynamically.
    --
    Posted via http://www.ruby-forum.com/.
    Sean Liu, Jul 28, 2008
    #3
    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. Alexander Stante

    How to change the superclass of an instance?

    Alexander Stante, Sep 13, 2004, in forum: Python
    Replies:
    1
    Views:
    261
    Alex Martelli
    Sep 13, 2004
  2. Replies:
    5
    Views:
    334
    Patricia Shanahan
    Oct 7, 2006
  3. Evan Klitzke
    Replies:
    0
    Views:
    348
    Evan Klitzke
    Aug 2, 2007
  4. seanacais
    Replies:
    1
    Views:
    306
    Bruno Desthuilliers
    Sep 9, 2008
  5. bart van deenen
    Replies:
    6
    Views:
    735
    bart van deenen
    Mar 3, 2009
Loading...

Share This Page