Hello Patrick,
Some help please - I've been learning Ruby on my system, running Windows, and have achieved some success. However, I've just tried running some of my scripts on my son's system, which has Mint Linux 17 installed - they all produce the same error message :-
daddy@gina-workstation:~/Documents/Ruby > ruby romantester.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- RomanConverter.rb (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from romantester.rb:1:in `<main>'
Does this imply that the Ruby require method does not work in Mint? Or is this a subtle difference due to the Windows/Linux divide?
If it helps the console reports :-
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
and the problem is definitely NOT that the required file is not present.
To avoid such issues, it's better to use "require_relative"[1] and "expand_path"[2] along with a reasonable directory structure. An example could be the following:
atma on leibniz.local in ~/tmp
$ tree project
project
├── lib
│ └── names.rb
└── project.rb
1 directory, 2 files
My program is called "project" and it has a file called "project.rb" where the program resides. There's a sub-directory called "lib", which is short of 'library', where all files that should be loaded are placed.
In the 'lib' directory there is a 'names.rb' 'file.
Now all I have to do is add the following line to "project.rb": require_relative File.expand_path("../lib/names", __FILE__)
If you have more than say 4 files to load, you could automate the procedure like:
path = File.dirname(__FILE__)
Dir["#{path}/lib/*.rb"].each {|f| require_relative f }
Hope this helps!
[1] Module: Kernel (Ruby 1.9.3)
[2] Class: File (Ruby 1.9.3)
--
Patrick Bayford Tel : 020 8265 8376 E-mail : pbayford@talktalk.net
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Panagiotis (atmosx) Atmatzidis
email: atma@convalesco.org
URL: http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5
"Everyone thinks of changing the world, but no one thinks of changing himself.” - Leo Tolstoy
···
On 13 Jul 2016, at 01:26, Patrick Bayford <pbayford@talktalk.net> wrote: