From: Intransition Date: 2012-06-13T12:34:19+09:00 Subject: require_relative? why didn't we "relative do" ------=_Part_652_33438669.1339558456985 Content-Type: multipart/alternative; boundary="----=_Part_653_541444.1339558456985" ------=_Part_653_541444.1339558456985 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 Assuming `#relative` to be the name of such a method. This is actually quite easy to implement in pure Ruby and would not have required a C-based patch to Ruby core. ------=_Part_653_541444.1339558456985 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit 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

Assuming `#relative` to be the name of such a method.

This is actually quite easy to implement in pure Ruby and would not have required a C-based patch to Ruby core.


------=_Part_653_541444.1339558456985-- ------=_Part_652_33438669.1339558456985--