Backport #3171: require '~/file.rb does not expand path before storing in $"
http://redmine.ruby-lang.org/issues/show/3171

Author: Brian Ford
Status: Open, Priority: Normal

Calling 'require "~/file.rb"' does not expand the path before storing it in $". However, 'require "~/file"' does expand the path. In both cases, the path is expanded for __FILE__.

$ cat ~/file.rb 
puts __FILE__

$ ruby1.8.7 -v -e 'require "~/file"; p $"'
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin9.8.0]
/Users/brian/file.rb
["enumerator.so", "/Users/brian/file.rb"]

$ ruby1.8.7 -v -e 'require "~/file.rb"; p $"'
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin9.8.0]
/Users/brian/file.rb
["enumerator.so", "~/file.rb"]

This bug has been fixed in 1.9.2, but I could not find a specific ticket for it. The fix should be backported to 1.8.

$ ruby1.9 -v -e 'require "~/file"; p $".grep(/file/)'
ruby 1.9.2dev (2010-03-30 trunk 27097) [i386-darwin9.8.0]
/Users/brian/file.rb
["/Users/brian/file.rb"]

$ ruby1.9 -v -e 'require "~/file.rb"; p $".grep(/file/)'
ruby 1.9.2dev (2010-03-30 trunk 27097) [i386-darwin9.8.0]
/Users/brian/file.rb
["/Users/brian/file.rb"]

Thanks,
Brian


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