Skip to content

Instantly share code, notes, and snippets.

@burke
Created January 23, 2010 04:28
Show Gist options
  • Save burke/284426 to your computer and use it in GitHub Desktop.
Save burke/284426 to your computer and use it in GitHub Desktop.
# FileFind.here/:up/:tmp/:reports/'flat.txt'
# FileFind(__FILE__)/:blah/:foo/'baz.bar'
def FileFind(file)
FileFind::FileFinder.new(File.expand_path(File.dirname(file)))
end
module FileFind
def self.at_file(file)
FileFinder.new(File.expand_path(File.dirname(file)))
end
def self.here
FileFinder.new(File.expand_path('.'))
end
def self.root
return FileFinder.new('/')
end
def self.home
return FileFinder.new(File.expand_path('~/'))
end
class FileFinder < String
KEYWORDS = Hash.new{|k,v|v}.merge({'up' => '..'})
def /(nxt)
return FileFinder.new(File.expand_path(File.join(self, KEYWORDS[nxt.to_s])))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment