# Calling methons in subclass on extend

**URL:** <https://www.ruby-forum.com/t/calling-methons-in-subclass-on-extend/167821>\
**Category:** Ruby\
**Created:** [May 13, 2009, 12:07am UTC](https://www.ruby-forum.com/t/calling-methons-in-subclass-on-extend/167821 "2009-05-13T00:07:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sshaikh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@sshaikh](https://www.ruby-forum.com/u/sshaikh)\
**Post date:** [May 13, 2009, 12:07am UTC](https://www.ruby-forum.com/t/calling-methons-in-subclass-on-extend/167821/1 "2009-05-13T00:07:06Z")

</div>

In Rails, the Tableless plugin allows you to define tableless models:

class A \< ActiveRecord::Base  
include Mod  
tableless :columns =\> [[:id, :int]]  
column :name, :string  
end

I’m not clear what you call these methods being called in class  
definition. Static constructor calls perhaps? Anyway, let’s say I want a  
new model as A, but with an extra column:

class B \< A  
column :desc, :string  
end

How do I get the process of inheriting from A call the same static  
methods as in A’s definition? I tried something like this:

class A \< ActiveRecord::Base  
def A.setup(clazz)  
clazz.class\_eval{include Mod}  
clazz.tableless :columns =\> [[:id, :int]]  
clazz.column :name, :string  
end

def A.inherited(clazz)  
setup(clazz)  
end

setup(A)  
end

But this doesn’t seem to work - A seems to work as before, but B cannot  
be new’d for some reason (can’t dup NilClass). Any suggestions on how to  
get this working as intended?

Although I’m using this in Rails, I assume that this is a general Ruby  
meta programming question, but apologies if I’ve placed it in the wrong  
forum.

Shak
