Reputation: 16285
I have the following two files: main.rb
and sort.rb
located in the same folder. In main.rb
I have the following code:
require 'sort'
Sort.insertion_sort([1,2,3,4]).each {|x| print "#{x}, "}
When I try and run this via ruby main.rb
I get the following error:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- sort (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from main.rb:1:in `<main>'
Any ideas why? Thanks
Upvotes: 4
Views: 15761
Reputation: 24627
The better way to use
require_relative "sort"
intead of
require "sort"
Thanks, @Jörg W Mittag.
Or you can add a path where ruby should search your files (can be a security risk):
$:.unshift File.join(File.dirname(__FILE__), ".") # current directory
require 'sort'
Upvotes: 5
Reputation: 81631
In Ruby 1.9.2, $:
doesn't include the current directory ('.'
). Either do relative_require
instead, or do .$: << '.'
Joerg Mittag says that $: << '.'
shouldn't be done because it's a security risk.
Upvotes: 0