Class: Pathname

Inherits:
Object
  • Object
show all
Defined in:
lib/enhanced_prompt/token/dir.rb

Overview

Customized Pathname Appended convenient methods for abbreviation

Instance Method Summary collapse

Instance Method Details

#first(n: 1) ⇒ Object



20
21
22
# File 'lib/enhanced_prompt/token/dir.rb', line 20

def first(n:1)
  (length > n) ? self : self.class.new(self.to_s[0..n])
end

#lengthObject



8
9
10
11
# File 'lib/enhanced_prompt/token/dir.rb', line 8

def length
  #self.to_s.include?('/') ? self.to_s.size : self.to_s.count("^/")+1
  self.to_s.size
end

#split_pathsObject



13
14
15
16
17
18
# File 'lib/enhanced_prompt/token/dir.rb', line 13

def split_paths
  # have to delete empty string to exclude first /
  paths = self.to_s.split('/')
  paths.delete('')
  paths.map{|str| self.class.new(str)}
end