...

/

Modules

Modules

This lesson discusses modules in Ruby and it explains how they relate with classes.

It now makes sense to introduce another language feature in Ruby: modules.

In Ruby, modules are somewhat similar to classes: they are things that hold methods, just like classes do. However:

Modules cannot be instantiated; i.e., it is not possible to create objects from a module. And modules, unlike classes, therefore do not have a method new.

What are modules useful for?

With modules you can share methods between classes:

Modules can be included into classes, and this makes their methods available on the class, just as if we’d copied and pasted these methods over to the class definition.

This is useful if we have methods that we want to ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy