Take the 2-minute tour ×

I have a module as following,


module Main
 include Dad::Mam


in dad.rb:

module Dad
 module Mam
  puts "Mam is saying you are very lazy..."

How can I name this file? dad.rb is right?

but when running

$ ruby main.rb

I am getting an Error like,

main.rb:2:in <module:Main>': uninitialized constant Main::Dad (NameError) from main.rb:1:in'

I need to show the sentance inside the puts under Mam module while running ruby main.rb,

I am confused about using ruby's modules, please anyone help me and guide me..

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

In this case, since you're just writing a simple script, use #require_relative

require_relative 'dad'
module Main
 include Dad::Mam

For an actual app or library, you would want to manage the load path (a global variable holding an array that tells ruby where to look for files) and then use a normal require

share|improve this answer
thanks a lot cheek.... –  abhilash Sep 7 '12 at 7:34
add comment

Your Answer


