Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Forked from joshsusser/File.here.rb
Created May 14, 2009 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tenderlove/111519 to your computer and use it in GitHub Desktop.
Save tenderlove/111519 to your computer and use it in GitHub Desktop.
# 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 setup
@target = File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'foo'))
end
def test_slashes
assert_equal(@target, __FILE__/"lib"/"foo")
end
def test_array
assert_equal(@target, __FILE__ / %w{lib foo})
end
def test_strings_with_slashes
assert_equal(@target, __FILE__/"lib/foo")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment