New classes on inheritance

Discussion in 'Ruby' started by Jeff Turcotte, Jan 25, 2008.

  1. I'm trying to create a new globally available subclass upon the
    inheritance of another class. This code isn't close to complete, but I
    think I'm on the right track.

    class PersonHelper; end

    class Person
    def self.inherited(klass)
    helper = Object.const_get(klass.to_s + 'Helper')
    # define class here?
    end
    end

    class Employee < Person; end

    Basically, I'm trying to accomplish this:

    class EmployeeHelper < PersonHelper; end

    ...by defining class Employee. Any help would be appreciated. Thanks in
    advance!
    --
    Posted via http://www.ruby-forum.com/.
     
    Jeff Turcotte, Jan 25, 2008
    #1
    1. Advertising

  2. On Jan 25, 2008 3:00 PM, Jeff Turcotte <> wrote:
    > I'm trying to create a new globally available subclass upon the
    > inheritance of another class. This code isn't close to complete, but I
    > think I'm on the right track.
    >
    > class PersonHelper; end
    >
    > class Person
    > def self.inherited(klass)
    > helper = Object.const_get(klass.to_s + 'Helper')

    Instead try:
    const_set(klass.to_s + 'Helper', class.new(PersonHelper))

    > # define class here?

    yes :)

    klass.class_eval do
    ...
    end

    --
    Your subnet is currently 169.254.0.0/16. You are likely to be eaten by a grue.
     
    Judson Lester, Jan 25, 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. cppsks
    Replies:
    0
    Views:
    854
    cppsks
    Oct 27, 2004
  2. Greg Copeland

    inheritance with new-style classes - help

    Greg Copeland, May 6, 2005, in forum: Python
    Replies:
    3
    Views:
    293
    Terry Reedy
    May 6, 2005
  3. Isaac Rodriguez

    Are all classes new-style classes in 2.4+?

    Isaac Rodriguez, Dec 31, 2006, in forum: Python
    Replies:
    4
    Views:
    403
    Steven D'Aprano
    Dec 31, 2006
  4. Quek
    Replies:
    3
    Views:
    353
  5. Replies:
    2
    Views:
    512
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page