Method: Pathname#split_all

Defined in:
lib/quality_extensions/pathname.rb

#split_allObject

Better name? Would ‘dirs’ be better? ‘parents’?

Similar to split, but instead of only returning two parts ([dirname, basename]), returns an element for each directory/basename represented in the path.

Similar to PHP’s pathinfo()[‘parts’]?



191
192
193
194
195
196
197
198
199
200
201
# File 'lib/quality_extensions/pathname.rb', line 191

def split_all
  # Boundary condition for paths like '/usr' (['/', 'usr'] will be the result)
  if self.to_s == '/'
    [self]
  # Boundary condition for paths like 'usr' (we only want ['usr'], not ['.', 'usr'])
  elsif self.to_s == '.'
    []
  else
    parent.split_all + [self]
  end
end