# New classes on inheritance

**URL:** <https://www.ruby-forum.com/t/new-classes-on-inheritance/127191>\
**Category:** Ruby\
**Created:** [January 26, 2008, 12:01am UTC](https://www.ruby-forum.com/t/new-classes-on-inheritance/127191 "2008-01-26T00:01:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![reversejt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@reversejt](https://www.ruby-forum.com/u/reversejt)\
**Post date:** [January 26, 2008, 12:01am UTC](https://www.ruby-forum.com/t/new-classes-on-inheritance/127191/1 "2008-01-26T00:01:02Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![reversejt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@reversejt](https://www.ruby-forum.com/u/reversejt)\
**Post date:** [January 26, 2008, 12:34am UTC](https://www.ruby-forum.com/t/new-classes-on-inheritance/127191/2 "2008-01-26T00:34:39Z")

</div>

On Jan 25, 2008 3:00 PM, Jeff T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
