From: Intransition Date: 2011-06-12T21:23:18+09:00 Subject: Re: RFC - One word alias for require_relative On Jun 12, 5:59 am, Josh Cheek wrote: > Back in the blissful days before I understood the `$LOAD_PATH` or the > difference between `Dir.pwd` and `File.dirname(__FILE__)`, I could `require > "file"` and it would work (unless I was in another dir). `require_relative` > isn't universally implemented, and doesn't seem to play well with others. > It's just generally been unavailable / not worked right for me to the point > that I prefer to use `File.dirname(__FILE__) + "/file"` > > What if, instead of having CWD in the load path, we had > `File.dirname(__FILE__)`? Essentially, CWD of the file that the require > statement is originated through. In the same way that every file has its own > `__FILE__` variable, what if the `$LOAD_PATH` included the current file's > dir, for any given file? Then the old interface would work again, it would > be simpler to think about, security risks of CWD in the load path would be > addressed, and most importantly, I could write beautiful code again (I die a > little bit inside each time I write __FILE__). > > Of course, I have no idea if it's even possible, and it's not immediately > clear to me how it would affect gems. Still, thought I'd put it out there. Hi Josh, your idea is essentially the basis to what I was suggesting in my earlier comments. By adding the current files path to $LOAD_PATH you make #require and #relative_require one and the same. But that can cause problems if you have name conflicts between a local file and a file in another library. Consider the example I gave. If you wanted to create an extension for OpenStruct, and created a file called `ostruct.rb` in your project, how would you load Ruby's 'ostruct.rb' file?