[ruby-core:32772] [Ruby-Feature#3942][Open] File.dirname(__FILE__) should be on $: by default

From: Felipe Contreras <redmine@...>
Date: 2010-10-13 14:14:26 UTC
List: ruby-core #32772
Feature #3942: File.dirname(__FILE__) should be on $: by default
http://redmine.ruby-lang.org/issues/show/3942

Author: Felipe Contreras
Status: Open, Priority: Normal
Category: core

Basically:

 echo "p $:.include?('/tmp')" > /tmp/load && ruby /tmp/load

Should return 'true'.

= Reasons in favor =

1) People don't have to do:

 $: << File.expand_path(File.dirname(__FILE__))
 require File.join(File.dirname(__FILE__), requirement)

Or similar, which are very ugly already.

2) It's the principle of last surprise

I create a script called 'tools/full', then I decided to split it into 'tools/base' and 'tools/full', in order to re-use some of the code. I would expect "require 'base'" to work.

3) It doesn't cause any conflicts

Python does this:

  echo -e "import sys\nprint '/tmp' in sys.path" > /tmp/python_load && python /tmp/python_load

Presumably because it works.

= Reasons against =

1) People might not want to include File.dirname(__FILE__)

They can drop it from '$:'. The vast majority of people would rather have it in by default, we should cater for the majority.


----------------------------------------
http://redmine.ruby-lang.org

In This Thread

Prev Next