From: Brian Candler Date: 2010-09-03T02:18:52+09:00 Subject: Re: uninitialized constant NArray (Name Error) Abder-Rahman Ali wrote: > Thanks Brian. > > I have renamed the .rb file as: nary.rb > > When I run the script, I get the following: > > C:\Users\Abder-Rahman\Desktop\Research>ruby nary.rb > nary.rb:1:in `require': no such file to load -- narray (LoadError) > from nary.rb:1 > > Provided that I have installed the "narray" gem using: > > gem install narray If you're running ruby 1.8.x, you'll need require "rubygems" # << THIS IS MISSING require "narray" > And, just a small thing. When you said: "Don't call your own script > 'narray.rb', because then Ruby will think it has already loaded the > narray library." > > Can you just clarify this point? Ruby keeps tracks of which libraries it has already loaded - actually in a variable called $LOADED_FEATURES - so that if you require the same library a second time, it doesn't get re-loaded. So when you do require 'narray' it will be skipped if narray.rb has already been loaded. Unfortunately, if your script is called narray.rb, and you run it from the command line, then narray.rb *has* already been loaded, so line 1 of your script is skipped. It then continues to line 2, where it tries to use NArray and finds it undefined. If you rename your script to nary.rb, then line 1 tries to find a file called narray.rb, and gives you a different error. You fix it by installing narray.rb somewhere in the library path (e.g. by installing the narray gem, and doing require 'rubygems') -- Posted via http://www.ruby-forum.com/.