1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.



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.

  1. About.com
  2. Technology
  3. Ruby
  4. Beginning Ruby
  5. Ruby's Basic Features
  6. Modules

©2014 About.com. All rights reserved.