-
-
Save pivotal-legacy/111534 to your computer and use it in GitHub Desktop.
This file contains 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
# Require slash | |
# by Aaron Patterson | |
# inspired by Josh Susser | |
# use to require files relative to the current file: | |
# | |
# require __FILE__/"lib"/"foo" | |
# require __FILE__/%{lib foo} | |
class String | |
def / *parts | |
File.expand_path( | |
File.join(File.file?(self) ? File.dirname(self) : self, *parts) | |
) | |
end | |
end | |
require 'test/unit' | |
class TestAwesome < Test::Unit::TestCase | |
def test_slashes | |
assert_equal( | |
File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'foo')), | |
__FILE__/"lib"/"foo" | |
) | |
end | |
def test_array | |
assert_equal( | |
File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'foo')), | |
__FILE__ / %w{lib foo} | |
) | |
end | |
def test_strings_with_slashes | |
assert_equal( | |
File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'foo')), | |
__FILE__/"lib/foo" | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment