Created
June 23, 2011 02:57
-
-
Save rramsden/1041809 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
# Find the named object in this tree's contents | |
# | |
# Examples | |
# Repo.new('/path/to/grit').tree/'lib' | |
# # => #<Grit::Tree "6cc23ee138be09ff8c28b07162720018b244e95e"> | |
# Repo.new('/path/to/grit').tree/'README.txt' | |
# # => #<Grit::Blob "8b1e02c0fb554eed2ce2ef737a68bb369d7527df"> | |
# | |
# Returns Grit::Blob or Grit::Tree or nil if not found | |
def /(file) | |
if file =~ /\// | |
file.split("/").inject(self) { |acc, x| acc/x } rescue nil | |
else | |
self.contents.find { |c| c.name == file } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very cool syntactic sugar :) !