views:

56

answers:

2

When you import a module into a class, is it similar in nature to OOP composition?

+5  A: 

No, it's more like multiple inheritance, but not completely the same. Modules can be used to mix-in functionality, so you don't have to rewrite the same code for multiple classes. Composition is where objects hold references to other objects.

Wouter de Bie
A: 

I may be getting my design pattern terminology mixed up, but have you looked at def_delegator and def_delegators from Ruby's standard library forwardable?

Andrew Grimm