Problem with Ruby 1.9 on Mint Linux

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.

···

--
Patrick Bayford Tel : 020 8265 8376 E-mail : pbayford@talktalk.net

If you require your file like this

require './RomanConverter'

everything should work. At least on Linux the current path (.) is
not automatically included in the searchpath.
Oh, and of course filenames are case sensitive in Linux

Hope this helps
Sascha

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&gt;

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:

Many thanks for the suggestions - not able to check yet, but will try these suggestions when the Linux box is next available. I did feel that the problem was due to my lack of familiarity with the Linux path conventions, and that seems to be the case. I'm far less versed on Linux/Unix then Windows.

···

On 12/07/2016 11:26 PM, Patrick Bayford wrote:

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.
--
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&gt;

No virus found in this message.
Checked by AVG - www.avg.com <http://www.avg.com>
Version: 2016.0.7640 / Virus Database: 4627/12605 - Release Date: 07/12/16

--
Patrick Bayford Tel : 020 8265 8376 E-mail : pbayford@talktalk.net

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

[...]

Now all I have to do is add the following line to "project.rb": require_relative File.expand_path("../lib/names", __FILE__)-

I do not see why you would use require_relative together with
File.expand_path, which returns the _absolute_ path of the file,
whereas the very point of using require_relative is that it can
handle relative paths.

You could simply use

  require_relative "lib/names"

or (if you insist on expanding the path)

  require File.expand_path("../lib/names", __FILE__)

Regards,
Marcus

···

Am 13.07.2016 um 08:22 schrieb Panagiotis Atmatzidis: