1. Home
  2. Computing & Technology
  3. Ruby

Modules

By , About.com Guide

In any programming language, you need some way to prevent naming clashes. This is especially true when you're using at least one third party library, where you have no control over the naming scheme. In the past, naming conventions would be used. It's not uncommon to see C programs with names like mylibrary_some_function. However, Ruby has a more powerful solution: modules.

A module is just a way to compartmentalize all of your methods, classes, constants, etc into a little section where they can't interfere with anything in another part of the program. So, library A might have a class called Car, but library B can also have a class called Car and they won't interfere as long as they're in different modules.

First think about what happens with name clashes in Ruby. If you define a method, then define another method with the same name, what happens? Ruby happily forgets about the first method and uses the second. Name clashes can be very confusing in Ruby, since there are no real alarm bells to go off.

Explore Ruby
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Ruby
  4. Beginning Ruby
  5. Ruby's Basic Features
  6. Modules

©2009 About.com, a part of The New York Times Company.

All rights reserved.