Ilya
Ilya

Reputation: 1223

Why am I unable to load my file in Ruby?

Edited for clarity

From

puts $LOAD_PATH

I am able to see my load paths. I do

$LOAD_PATH << 'C:/rubyfiles'

to add ruby files to my search path. I then put some random custom rb file in there and do

require 'ya'

LoadError - No such file to load

What am I doing wrong?

Upvotes: 0

Views: 322

Answers (4)

edthix
edthix

Reputation: 1752

You can put your custom .rb files in lib/ folder inside your rails project

p/s: assuming it's a rails project

Upvotes: 0

Ilya
Ilya

Reputation: 1223

Guess I trusted too much in someone elses code which had an error. Still somewhat new with ruby thus I mistook the loaderror for issues with the main file without bothering to look in the code itself. Thanks anyways.

Upvotes: 0

Andrew Grimm
Andrew Grimm

Reputation: 81430

Try doing

puts "$LOAD_PATH is #{$LOAD_PATH.inspect}"
puts "Files in rubyfiles is #{Dir.entries('C:/rubyfiles').inspect}"

and add the output of that debugging to the question.

Upvotes: 1

sawa
sawa

Reputation: 168071

When you want to load the file name with xxx.rb, you have load xxx.rb, not load xxx. This is one difference from require. Are you clear with that?

Upvotes: 0

Related Questions