Created
April 23, 2010 01:37
-
-
Save xaviershay/376059 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Pathname/File require alternative? | |
| require File.instance_eval { | |
| expand_path(join(dirname(__FILE__), '..', 'bin', path)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like the way this code looks -- the core idea of sending messages to self is nice.
File.expand_pathtakes an optional second argument, so you could:or even
I had thought 1.9 was introducing a
File.relative_path, but I don't see it at http://ruby-doc.org/ruby-1.9/Barring context, another alternative (that I'm going for these days) is to Lean Hard on the
$LOAD_PATH. Let Something Else handle it -- explicitly at development time with Rake,ENV['RUBYLIB'],ruby -I, or implicitly in deployment via the package manager (RubyGems/Bundler, rip, ...).One trick to make development-time less cumbersome is to fall back to a relative path with a warning if the file can't be found on the
$LOAD_PATH. I first saw this inronn: http://github.com/rtomayko/ronn/blob/0.5/bin/ronn#L100-111