# 1.9 require problem

**URL:** <https://www.ruby-forum.com/t/1-9-require-problem/194353>\
**Category:** Ruby\
**Created:** [September 2, 2010, 10:07pm UTC](https://www.ruby-forum.com/t/1-9-require-problem/194353 "2010-09-02T22:07:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 2, 2010, 10:07pm UTC](https://www.ruby-forum.com/t/1-9-require-problem/194353/1 "2010-09-02T22:07:32Z")

</div>

As of this morning I am just starting to work with Ruby 1.9. I note  
that there seems to be some behaviour change between 1.8 and 1.9 with  
respect to require. Specifically, I have this construct.

#!/usr/bin/env ruby

require File.dirname( **FILE** ) + ‘/…/lib/deploy/pg\_access\_setup’

PGAccessSetup::Main.new(ARGV).execute

With ruby 1.8 this works exactly as I desire. With ruby 1.9.2-p0 I get  
this behaviour instead:

internal:lib/rubygems/custom\_require:29:in `require': no such file to load -- bin/../lib/deploy/pg_access_setup (LoadError) from <internal:lib/rubygems/custom_require>:29:in`require’  
from bin/pg\_access\_setup:3:in `’

I have spent some time googling for answers to this and I have checked  
this forum’s archives for hints. I am either using the wrong terms or  
not understanding what I am reading. Whatever the matter is, I cannot  
decipher what the difference is.

If anyone here can tell me what I need to change to get this to work  
under Ruby 1.9 AND Ruby 1.8 I would be most obliged,

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 2, 2010, 10:29pm UTC](https://www.ruby-forum.com/t/1-9-require-problem/194353/2 "2010-09-02T22:29:24Z")

</div>

James B. wrote:

> As of this morning I am just starting to work with Ruby 1.9. I note  
> that there seems to be some behaviour change between 1.8 and 1.9 with  
> respect to require.  
> . . .
> 
> If anyone here can tell me what I need to change to get this to work  
> under Ruby 1.9 AND Ruby 1.8 I would be most obliged,

I discover that if I do this:

require File.expand\_path(  
File.dirname( **FILE** ) + ‘/…/lib/deploy/pg\_access\_setup’)

Then the problem is resolved. However, I do not understand why this is  
now necessary or what benefit accrues from introducing this change in  
behaviour between 1.8 and 1.9.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 2, 2010, 10:50pm UTC](https://www.ruby-forum.com/t/1-9-require-problem/194353/3 "2010-09-02T22:50:54Z")

</div>

On 09/02/2010 10:32 PM, James B. wrote:

> require File.expand\_path(  
> File.dirname( **FILE** ) + ‘/…/lib/deploy/pg\_access\_setup’)

You can as well modify $: or set RUBYLIB in the environment.

> Then the problem is resolved. However, I do not understand why this is  
> now necessary or what benefit accrues from introducing this change in  
> behaviour between 1.8 and 1.9.

Maybe it’s not so much a change in behavior or rather a changed default  
setting of $:.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 2, 2010, 10:57pm UTC](https://www.ruby-forum.com/t/1-9-require-problem/194353/4 "2010-09-02T22:57:56Z")

</div>

On Sep 2, 5:32 pm, James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> require File.expand\_path(  
> File.dirname( **FILE** ) + ‘/…/lib/deploy/pg\_access\_setup’)
> 
> Then the problem is resolved. However, I do not understand why this is  
> now necessary or what benefit accrues from introducing this change in  
> behaviour between 1.8 and 1.9.

$LOADED\_FEATURES now tracks files with full paths to avoid requires  
with File.dirname( **FILE** ) load the same file twice.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 3, 2010, 3:41pm UTC](https://www.ruby-forum.com/t/1-9-require-problem/194353/5 "2010-09-03T15:41:19Z")

</div>

Luis L. wrote:

> On Sep 2, 5:32ï¿½pm, James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > require File.expand\_path(  
> > File.dirname( **FILE** ) + ‘/…/lib/deploy/pg\_access\_setup’)
> > 
> > Then the problem is resolved. However, I do not understand why this is  
> > now necessary or what benefit accrues from introducing this change in  
> > behaviour between 1.8 and 1.9.
> 
> $LOADED\_FEATURES now tracks files with full paths to avoid requires  
> with File.dirname( **FILE** ) load the same file twice.

I see. Is there some reason that require does not issue an error that an  
absolute path was not provided instead of just reporting that it cannot  
find the file? The error message that is presently given simply reports  
the path used by require and does so in such a way that the necessity to  
provide an absolute path is not evident at all. The fact that an ls -l  
of the path reported together with the .rb extension will actually find  
the file required adds to the confusion.

I understand the intent of the change. And I take it that  
require\_relative was provided to maintain the old behaviour. However,  
this situation does seem to require a little more in the way of an  
explicit explanation of the probable cause of the errors which  
inevitably result from using 1.8 code with 1.9.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 3, 2010, 4:08pm UTC](https://www.ruby-forum.com/t/1-9-require-problem/194353/6 "2010-09-03T16:08:34Z")

</div>

James B. wrote:

> I understand the intent of the change. And I take it that  
> require\_relative was provided to maintain the old behaviour. However,  
> this situation does seem to require a little more in the way of an  
> explicit explanation of the probable cause of the errors which  
> inevitably result from using 1.8 code with 1.9.

OK. This is not good. If I try to use require\_relative I discover that  
backtracks in the directory tree are ignored. For instance, given this  
code:

#!/usr/bin/env ruby

lib\_path = File.dirname( **FILE** ) + ‘/…/lib/forex/hll\_forex\_ca\_feed’  
puts lib\_path  
puts("Library file found? " + (File.file?(lib\_path + ‘.rb’)).to\_s)  
require\_relative lib\_path  
HLLForexCAFeed::Main.new(ARGV).execute

I would expect that the file ./bin/…/lib/forex/hll\_forex\_ca\_feed.rb  
would be found. Instead, when I run this program I see this:

$ bin/forex

bin/…/lib/forex/hll\_forex\_ca\_feed  
Library file found? true

bin/forex:9:in `require_relative': no such file to load -- /home/byrnejb/Software/Development/Projects/proforma.git/bin/lib/forex/hll_forex_ca_feed (LoadError) from bin/forex:9:in`

Note that the path determined by require\_relative:

home/byrnejb/Software/Development/Projects/proforma.git/bin/lib/forex/hll\_forex\_ca\_feed)

does not accommodate the /…/ portion of the relative path provided.  
It simply discards it.

In my opinion, the path should read:

home/byrnejb/Software/Development/Projects/proforma.git/lib/forex/hll\_forex\_ca\_feed

or

home/byrnejb/Software/Development/Projects/proforma.git/bin/…/lib/forex/hll\_forex\_ca\_feed

Is this intended behaviour?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [September 3, 2010, 4:16pm UTC](https://www.ruby-forum.com/t/1-9-require-problem/194353/7 "2010-09-03T16:16:01Z")

</div>

James B. wrote:

> OK. This is not good. If I try to use require\_relative I discover that  
> backtracks in the directory tree are ignored. For instance, given this  
> code:

Now I discover something even worse. If I change the the lib\_path by  
adding an additional /… then the thing works. That I do not  
understand.

$ bin/forex  
bin/…/…/lib/forex/hll\_forex\_ca\_feed  
Library file found? false  
$

If this is intended behaviour then I do not understand why the  
additional /… is necessary. As it stands, if this is intended, then it  
means that writing code to work with 1.8 and 1.9 ruby that uses  
require\_relative will need different relative paths to the same file.
