From: Justin Collins Date: 2005-12-29T14:25:57+09:00 Subject: Re: new to ruby, "requier" not working? David Just wrote: > Hello, > > I'm trying to learn ruby from the Poignant guide to Ruby > (http://poignantguide.net/ruby/chapter-4.html) and have run into a > problem. In chapter 4 the simple word replacement example is the > first use of the require statement. It does not work for me. I'm on > OS 10.3, ruby 1.8.2 and my directory structure is : > > ~/projects/test.rb > ~/projects/wordlist.rb > > > test.rb starts with: > require 'wordlist' > > and wordlist.rb just has: > words = { > 'starmonkeys' => 'Phil and Pete, those prickly chancellors of the > New Reich', > 'catapult' => 'chucky go-go', 'firebomb' => 'Heat-Assisted Living', > 'Nigeria' => "Ny and Jerry's Dry Cleaning (with Donuts)", > 'Put the kabosh on' => 'Put the cable box on' > } > This has come up on the list before... 'words' needs to be a global variable or constant. It's basically a typo in the tutorial. Changing it to Words will get you a constant, changing it to $words will get you a global variable. When you require a file, the local variables in that file stay in that scope, and are not imported into the current scope. To be able to access them, you must make them global. -Justin -- Posted via http://www.ruby-forum.com/.