# Pushing up to Module or Class?

**URL:** <https://www.ruby-forum.com/t/pushing-up-to-module-or-class/158834>\
**Category:** Ruby\
**Created:** [January 28, 2009, 4:12pm UTC](https://www.ruby-forum.com/t/pushing-up-to-module-or-class/158834 "2009-01-28T16:12:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a3d4f5/32.png) [@Shak](https://www.ruby-forum.com/u/Shak)\
**Post date:** [January 28, 2009, 4:12pm UTC](https://www.ruby-forum.com/t/pushing-up-to-module-or-class/158834/1 "2009-01-28T16:12:05Z")

</div>

Hi all,

Yes, this question has been asked many times all over the Internet so  
I’m a  
bit embarrassed to admit that I still don’t know what the difference is.  
Apologies in advance for making you roll your eyes.

If I have a family of classes, each with a common method etc, should I  
push  
that common code up into a superclass or module? Right now I’m inclined  
to  
say the latter since I’ll be able to mixin further modules later on if  
required. But what would a superclass in Ruby provide that a module  
wouldn’t? In a ducktyped world I don’t see any benefits with  
type-polymorphism.

Alternatively: is there any reason why we shouldn’t use modules for  
single  
inheritance (seeing as that’s a special, trivial case of multiple  
inheritance)?

Sorry for boring you all,

Shak

---

<div class="post-metadata">

**Author:** ![Shak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a3d4f5/32.png) [@Shak](https://www.ruby-forum.com/u/Shak)\
**Post date:** [January 28, 2009, 4:45pm UTC](https://www.ruby-forum.com/t/pushing-up-to-module-or-class/158834/2 "2009-01-28T16:45:08Z")

</div>

2009/1/28 Shak [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> wouldn’t? In a ducktyped world I don’t see any benefits with  
> type-polymorphism.
> 
> Alternatively: is there any reason why we shouldn’t use modules for single  
> inheritance (seeing as that’s a special, trivial case of multiple  
> inheritance)?

I tend to view class inheritance in Ruby as “is a” relationship while  
module inclusion has a less strict relationship, i.e. the class  
including a module inherits particular behavior which does not mean  
that it can replace any other class including the module.

IMHO classical inheritance is overrated because there are not so many  
places where nested class hierarchies do actually make sense. Often,  
delegation is a superior approach because coupling is less strict.

There is probably generally more potential for implementation  
inheritance, i.e. sharing common code between multiple classes. The  
nice thing is that Ruby allows to do this via module inclusion which  
leaves class inheritance for true “is a” relationships.

My 0.02 EUR…

> Sorry for boring you all,

Not at all. These kinds of questions can be reasoned about a lot of  
time. One reason is probably that there is no clear cut answer to  
them.

Cheers

robert
