Class: PathList

Inherits:
Array show all
Includes:
Finder
Defined in:
lib/more/facets/pathlist.rb

Overview

PathList

A PathList is an array containing 1..n paths. It is useful to regroup paths and make lookups on them.

Usage

path = PathList.new(ENV['PATH'])
path.find 'env'            #=> "/usr/bin/env"

# This is already done when including the library
$:.class                   #=> Array
$:.extend PathList::Finder
$:.find_ext = 'rb'

$:.find 'uri'              #=> "/usr/lib/ruby/1.8/uri.rb"

Defined Under Namespace

Modules: Finder

Instance Attribute Summary

Attributes included from Finder

#find_ext

Instance Method Summary collapse

Methods included from Finder

#find

Methods inherited from Array

#at_rand, #at_rand!, cast_from, #conjoin, #delete_unless, #delete_values, #delete_values_at, #each_iteration, #merge!, mutable_methods, #not_empty?, #only, #pad, #pad!, #pick, #pick!, #rand_index, #rand_subset, #restore_snapshot, #rotate, #rotate!, #select!, #shuffle, #shuffle!, #splice, #take_snapshot, #to_b, #to_console, #to_h, #to_path, #to_t

Methods included from Stackable

#peek, #poke, #pop, #pull, #push

Methods included from Indexable

#body, #ends, #first, #first!, #first=, #foot, #head, #index_of, #last, #last!, #last=, #mid, #middle, #pos, #range, #tail, #thru

Constructor Details

#initialize(paths, default_ext = nil) ⇒ PathList

Returns a new instance of PathList.



49
50
51
52
53
54
55
# File 'lib/more/facets/pathlist.rb', line 49

def initialize(paths, default_ext = nil)
  @find_ext = default_ext
  if paths.kind_of? String
    paths = paths.split(File::PATH_SEPARATOR)
  end
  super(paths)
end

Instance Method Details

#to_sObject



57
58
59
# File 'lib/more/facets/pathlist.rb', line 57

def to_s
  join(File::PATH_SEPARATOR)
end