Loading .rb files in IRb

Hi..

I am trying to get IRb to load a file. I am running a fresh install of
Mac OS X Leopard and I have updated my gems and RubyGems. Below is the
Class file ( From the Pickaxe and saved under /Users/gudni/Song.rb ) and
the results from my previous attempts.

Attempt 1:

load '/Users/gudni/Song.rb'

--> LoadError: no such file to load -- /Users/gudni/Song.rb
  from (irb):3:in `load'
  from (irb):3

Attempt 2:

require '/Users/gudni/Song.rb'

-->LoadError: no such file to load -- /Users/gudni/Song.rb
  from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
  from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require'
  from (irb):5

I can't get it to work. According to the pickaxe it should be enough to
give the full path to the file, but it doesn't seem to work for me. Any
help would be much appreciated :smiley:

P.S. Happy holidays :smiley:

class Song
  def initialize(name, artist, duration)
    @name = name
    @artist = artist
    @duration = duration
  end

  def to_s
    "Song: #@name--#@artist (#@duration)"
  end
end

Content of my $:

puts $:

/Library/Ruby/Gems/1.8/gems/wirble-0.1.2/bin
/Library/Ruby/Gems/1.8/gems/wirble-0.1.2/.
/Library/Ruby/Site/1.8
/Library/Ruby/Site/1.8/powerpc-darwin9.0
/Library/Ruby/Site/1.8/universal-darwin9.0
/Library/Ruby/Site
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/powerpc-darwin9.0
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0
.
=> nil

and my irbrc

# Some default enhancements/settings for IRB, based on
# http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks

# Require RubyGems by default.
require 'rubygems'
require 'wirble'

# Activate auto-completion.
require 'irb/completion'

# Use the simple prompt if possible.
IRB.conf[:PROMPT_MODE] = :SIMPLE if IRB.conf[:PROMPT_MODE] == :DEFAULT

# Setup permanent history.
HISTFILE = "~/.irb_history"
MAXHISTSIZE = 100
begin
  histfile = File::expand_path(HISTFILE)
  if File::exists?(histfile)
    lines = IO::readlines(histfile).collect { |line| line.chomp }
    puts "Read #{lines.nitems} saved history commands from
'#{histfile}'." if $VERBOSE
    Readline::HISTORY.push(*lines)
  else
    puts "History file '#{histfile}' was empty or non-existant." if
$VERBOSE
  end
  Kernel::at_exit do
    lines = Readline::HISTORY.to_a.reverse.uniq.reverse
    lines = lines[-MAXHISTSIZE, MAXHISTSIZE] if lines.nitems >
MAXHISTSIZE
    puts "Saving #{lines.length} history lines to '#{histfile}'." if
$VERBOSE
    File::open(histfile, File::WRONLY|File::CREAT|File::TRUNC) { |io|
io.puts lines.join("\n") }
  end
end

···

--
Posted via http://www.ruby-forum.com/\.

Attempt 1:

load '/Users/gudni/Song.rb'

--> LoadError: no such file to load -- /Users/gudni/Song.rb
  from (irb):3:in `load'
  from (irb):3

It really should work. Note that path and file names are probably
case-sensitive, though. You can try to use Dir.glob to list the
contents of the directory :

Dir.glob('/home/fred/*.rb')

=> ["/home/fred/toto.rb", "/home/fred/main.rb"]

Fred

···

Le 24 décembre à 13:14, Gudni Hilmarsson a écrit :
--
I am standing up at the water's edge in my dream
I cannot make a single sound as you scream
it can't be that cold, the ground is still warm to touch
this place is so quiet, sensing that storm (Peter Gabriel, Red Rain)

Thanks for the Reply Fred...

I figured out that TextMate added a whitespace after .rb !

Dir.glob('/Users/gudni/*')
=> ["/Users/gudni/Desktop", "/Users/gudni/Documents",
"/Users/gudni/Downloads", "/Users/gudni/KaraokeSong.rb ",
"/Users/gudni/Library", "/Users/gudni/Movies", "/Users/gudni/Music",
"/Users/gudni/Pictures", "/Users/gudni/Public", "/Users/gudni/Sites",
"/Users/gudni/Song.rb ", "/Users/gudni/test.rb "]

That is whack :smiley:

Anyway thanks for pointing me in the right direction :smiley:

···

--
Posted via http://www.ruby-forum.com/.