Class: Path
- Inherits:
-
Object
- Object
- Path
- Defined in:
- lib/path2.rb
Instance Method Summary collapse
- #entries ⇒ Object
- #find(arg) ⇒ Object
- #grep(pattern) ⇒ Object
-
#initialize(*args) ⇒ Path
constructor
A new instance of Path.
- #join(path) ⇒ Object
- #pop(*args) ⇒ Object
- #push(*paths) ⇒ Object
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
#entries ⇒ Object
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.(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 |