Class: Path

Inherits:
Object
  • Object
show all
Defined in:
lib/path2.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Path

Returns a new instance of Path.



5
6
7
8
9
# File 'lib/path2.rb', line 5

def initialize(*args)
  @options              = args.last.is_a?(Hash) ? args.pop : {}
  @options[:recursive]  ||= false
  @entries              = build_entries(*args)
end

Instance Method Details

#entriesObject



23
24
25
# File 'lib/path2.rb', line 23

def entries
  @entries ||= []
end

#find(arg) ⇒ Object



11
12
13
# File 'lib/path2.rb', line 11

def find(arg)
  grep(/#{arg}/).first
end

#grep(pattern) ⇒ Object



19
20
21
# File 'lib/path2.rb', line 19

def grep(pattern)
  entries.grep(pattern)
end

#join(path) ⇒ Object



15
16
17
# File 'lib/path2.rb', line 15

def join(path)
  Path.new(find(path))
end

#pop(*args) ⇒ Object



31
32
33
34
35
# File 'lib/path2.rb', line 31

def pop(*args)
  args.each do |x|
    entries.delete_if {|y| File.expand_path(x) == y }
  end
end

#push(*paths) ⇒ Object



27
28
29
# File 'lib/path2.rb', line 27

def push(*paths)
  entries.concat(build_entries(*paths)).uniq!
end