Ruby: how to "require" a file from the current working dir?

Matt Roberts picture Matt Roberts · Dec 14, 2011 · Viewed 13.5k times · Source

How do I require a file from the current folder?

I have a file called sql_parser.rb that contains a class. I want to include this in another file also in the same folder, so I used:

require 'sql_parser'

That fails when I run from that folder:

LoadError: no such file to load -- sql_parser

I tried using IRB in the folder where this file exists and requiring it from there, but had the same issue.

Answer

thoferon picture thoferon · Dec 14, 2011

In ruby 1.9.x, you can use the method require_relative. See http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-require_relative.