Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Modules Ruby Module Basics Write a Simple Module

Sean Flanagan
Sean Flanagan
33,235 Points

What's wrong with the IRB?

Input:

module SimpleModule
  VERSION = 1.0
end

Console:

irb(main):012:0* load "./simple_module.rb                                                        
irb(main):013:0" load "./simple_module.rb                                                        
NameError: undefined local variable or method `simple_module' for main:Object                    
        from (irb):13                                                                            
        from /usr/local/bin/irb:11:in `<main>'                                                   
irb(main):014:0> load "./simple_module.rb                                                        
irb(main):015:0"                                                                                 
irb(main):016:0"                                                                                 
irb(main):017:0" SimpleModule                                                                    
irb(main):018:0"                                                                                 

Can anyone tell me why this is please? Thanks.

1 Answer

Nathan Williams
seal-mask
.a{fill-rule:evenodd;}techdegree
Nathan Williams
Python Web Development Techdegree Student 6,851 Points

You need to quote-wrap your file-name, or ruby will treat it as a variable.

irb(main):002:0> load "./simple_module.rb"
=> true
irb(main):003:0> SimpleModule::VERSION
=> 1.0