1

I have a file called "go.rb" that contains:

require 'turboname'
dictionary = Turboname::Random.new

100999032982389.times do
  name = Turboname::Domain.new(:from => dictionary)
  name.save if name.length < 15 and name.available?
  tld = name.tldize
  name.save(tld) if tld and name.length < 15 and name.available?(tld)
end

turboname.rb is located in the same directory as go.rb. It's the same level. I just want to include this file in this script. I don't want to deal with gems or bundles.

./turboname.rb:1:in `require': no such file to load -- turboname/version (LoadError)
    from ./turboname.rb:1
    from go.rb:1:in `require'
    from go.rb:1
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

3 Answers3

3

Use a require_relative Statement

Recent Ruby versions no longer add . to the load path stored in $:. However, one solution is to use Kernel#require_relative to require a file relative to the current value of __FILE__. For example:

require_relative './turboname'

Note that this doesn't work in interactive REPL sessions with irb or pry, but works fine within actual source files.

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
3

The error isn't telling you it can't find ./turboname.rb. It's telling you that it found that file, but the first line of ./turboname.rb tries to require 'turboname/version', which Ruby can't find. Does ./turboname/version.rb exist? If so, is it readable by the current user?

If everything else checks out, then you have a load-path problem. At the top of go.rb, explicitly add the current working directory (or whichever directory contains turboname.rb and turboname/version.rb (possibly ./lib/) to your load path:

$LOAD_PATH << File.dirname(__FILE__) # for ./
# or
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib') # for ./lib/
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
1

With Ruby 2.0:

require "#{__dir__}/turboname"
sawa
  • 165,429
  • 45
  • 277
  • 381