# \[ANN\] unique\_require 0.0.0a allow 1.8.x to never re-require

**URL:** <https://www.ruby-forum.com/t/ann-unique-require-0-0-0a-allow-1-8-x-to-never-re-require/160942>\
**Category:** Ruby\
**Created:** [February 21, 2009, 6:21am UTC](https://www.ruby-forum.com/t/ann-unique-require-0-0-0a-allow-1-8-x-to-never-re-require/160942 "2009-02-21T06:21:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [February 21, 2009, 6:21am UTC](https://www.ruby-forum.com/t/ann-unique-require-0-0-0a-allow-1-8-x-to-never-re-require/160942/1 "2009-02-21T06:21:17Z")

</div>

This has probably been done “1,000,000” times, but here’s another hack  
at it.

The background:  
If you’ve ever gotten a message like  
…/smart\_require/test.rb:1: warning: already initialized constant A

you know that ruby 1.8.x “re-requires” a file if you pass in a different  
paths to the same file.  
ex:  
require ‘test.rb’  
require ‘…/current\_dir/test.rb’

results in test.rb being loaded twice, despite the semantics of require  
being that it loads only once.

Ruby 1.9 overcomes this.  
This file overcomes this for 1.8.x  
ex:

c:\dev\>ruby example\_bad.rb  
…/dev/test.rb:1: warning: already initialized constant A

C:\dev\>ruby -runique\_require example\_bad.rb

# no warning is displayed

To use:  
download the unique\_require.rb file from  
[http://github.com/rogerdpack/roger-useful/tree/master](http://github.com/rogerdpack/roger-useful/tree/master)  
unique\_require folder  
require it [preferably first].

Feedback welcome.  
-=r
