Trying to Run Ruby script in terminal but get ERROR - ruby

I am trying to run a ruby script to rename some files but I get the following error:
Eccleshall$ ruby rename.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- ftools (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from rename.rb:45:in `<main>'
Thanks for the help.

Change to script to say:
require "fileutils"
instead of
require "ftools"
ftools has been deprecated.

Related

Loading files from a different partition

I'm working at C:\(...)\Desktop, and I need to require my scripts at G:\scripts. I tried to change the $LOAD_PATH:
$LOAD_PATH << 'G:\\scripts'
require 'filename'
and also the argument of require:
require 'G:\\scripts\\filename'
but I always get
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- dir_iterator (LoadError)
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from a.rb:2:in `<main>'
It works well if the directory is on C:\ partition. What's happening here?

`require': cannot load such file -- rsruby (LoarError)

I just used the code below to install rsruby on my Mac:
sudo gem install rsruby
Then I tried to load rsruby in my Ruby code:
require 'rsruby'
When running this I get this error:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- rsruby (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from graphz.rb:1:in `<main>'
Does the script with require 'rsruby' have to be in the same directory as the rsruby.rb file?

Ruby 2.0.0 cannot load such file even though gem is installed

I've tried all of the other solutions people have talked about on here, but none of them have helped / applied.
I've written a Ruby script that requires the spreadsheet gem. The requiring works fine when I execute the script normally with ruby myscript.rb, but after running chmod +x myscript.rb, and then trying to run the program with ./myscript.rb I get the following error....
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- spreadsheet (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/fcangialosi/dev/mTC/parse.rb:2:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/fcangialosi/dev/mTC/interpreter.rb:1:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from ./pmcnp.rb:7:in `<main>'
The beginning of my script looks like this:
#!/usr/bin/ruby
require 'rubygems'
require 'spreadsheet'
If anyone has any ideas, I would really appreciate it.
From your answers to the comments, the ruby you're running normally - and therefore the one in which your gems are installed - is /Users/fcangialosi/.rbenv/shims/ruby. When you make the script executable, it uses the hint in the script to know which program to use to execute the script. In your case, you have:
#!/usr/bin/ruby
So that's using whichever ruby version you have installed in /usr/bin/ruby. In order to use your rbenv ruby instead of /usr/bin/ruby, change the shebang line to:
#!/usr/bin/env ruby

Including Modules in Ruby

I am trying to include a Ruby module.
In the file helper.rb, I have this text
module Helper
...
end
In the file test.rb, I have this text:
....
require 'helper'
...
These files are on the same level of the directory yet I keep getting this error:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- helper (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from test.rb:4:in `<main>'
I have also tried
include Helper
in test.rb and get this error:
test.rb:4:in `<main>': uninitialized constant Object::Helper (NameError)
What am I doing wrong?
In Ruby 1.9 you should use
require_relative 'helper'
Try require './helper'. That should do it.

Help Getting Started with Mechanize

I'm new to Ruby and just installed Ruby for Windows.
I want to use the mechanize library (https://github.com/tenderlove/mechanize) and so I'm following the guide at https://github.com/tenderlove/mechanize/blob/master/GUIDE.rdoc.
On the Windows cmd line, I installed mechanize by using the cmd "gem install mechanize".
When I run the following code:
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
I get the error:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- net/http/digest_auth (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from C:/Ruby192/lib/ruby/1.9.1/mechanize.rb:5:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from helloworld.rb:2:in `<main>'
Anybody know what's going on?
It seems that some dependencies are missing. Try to install the net-http-digest_auth gem.
gem install net-http-digest_auth
If that solves this problem and another (related) pops up, it's probable that you are missing the net-http-persistent gem. If that's the case, you know what to do! Just install it too.

Resources