Skip to content

Instantly share code, notes, and snippets.

@rramsden
Created June 23, 2011 02:57
Show Gist options
  • Save rramsden/1041809 to your computer and use it in GitHub Desktop.
Save rramsden/1041809 to your computer and use it in GitHub Desktop.
# 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
@rramsden
Copy link
Author

very cool syntactic sugar :) !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment