Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 30th, 2012  |  syntax: None  |  size: 0.54 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     # Find the named object in this tree's contents
  2.     #
  3.     # Examples
  4.     #   Repo.new('/path/to/grit').tree/'lib'
  5.     #   # => #<Grit::Tree "6cc23ee138be09ff8c28b07162720018b244e95e">
  6.     #   Repo.new('/path/to/grit').tree/'README.txt'
  7.     #   # => #<Grit::Blob "8b1e02c0fb554eed2ce2ef737a68bb369d7527df">
  8.     #
  9.     # Returns Grit::Blob or Grit::Tree or nil if not found
  10.     def /(file)
  11.       if file =~ /\//
  12.         file.split("/").inject(self) { |acc, x| acc/x } rescue nil
  13.       else
  14.         self.contents.find { |c| c.name == file }
  15.       end
  16.     end