From: Eric Hodel Date: 2012-06-14T07:48:50+09:00 Subject: Re: require_relative? why didn't we "relative do" On Jun 12, 2012, at 20:34, Intransition wrote: > I wonder if it would been better if we had gone another route with the whole `#require_relative` thing. Instead of a special require method, we could have a method that adds the current file's directory to the top of the $LOAD_PATH temporarily while a block executes. > > For example, lets say we have a library `fruit_basket' with: > > lib/ > fruit_basket.rb > fruit_basket/ > grape.rb > orange.rb > > Then in `fruit_basket.rb`: > > relative do > require 'grape' > require 'orange' > end Say we also have the library "color": lib/ orange.rb And "flavor": lib/ grape.rb banana.rb Which files are loaded with: gem 'color' gem 'flavor' require 'fruit_basket' Say we have grafted fruits in fruit_basket such as lib/fruit_basket/lemon-orange.rb: # lemon seedling with orange grafted on require 'lemon' require 'orange' # … Note that this file depends on being loaded from inside fruit_basket.rb's relative block, but that is not explicitly stated: lib/fruit_basket.rb: relative do require 'lemon-orange' # ... end gem 'color' gem 'flavor' require 'fruit_basket' Which files were loaded? require_relative doesn't have the problem of the reader of the source needing external information to determine "which directory does this require operate in?" since it is explicit. I don't see how you make it explicit for require inside a relative block. Say you have two threads: gem 'color' gem 'flavor' Thread.start do require 'orange' end Thread.start do require 'fruit_basket' end Are one or two "orange.rb" files loaded? Which ones?