[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

New classes on inheritance

Jeff Turcotte

1/25/2008 11:01:00 PM

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-....

1 Answer

Judson Lester

1/25/2008 11:34:00 PM

0

On Jan 25, 2008 3:00 PM, Jeff Turcotte <jeff.turcotte@gmail.com> 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.