Method: Path#initialize

Defined in:
lib/epath/identity.rb

#initialize(*parts) ⇒ Path

Creates a new Path. If multiple arguments are given, they are joined with File.join. The path will have File::ALT_SEPARATOR replaced with ‘/’ and if it begins with a ‘~’, it will be expanded (using File.expand_path). Accepts an Array of Strings, a Tempfile, anything that respond to #path, #to_path or #to_str with a String and defaults to calling #to_s.

Parameters:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/epath/identity.rb', line 57

def initialize(*parts)
  path = parts.size > 1 ? File.join(*parts) : parts.first
  @path = case path
  when Tempfile
    @_tmpfile = path # We would not want it to be GC'd
    path.path.dup
  when String
    path.dup
  else
    if path.respond_to? :to_path and String === path.to_path
      path.to_path.dup
    elsif path.respond_to? :path and String === path.path
      path.path.dup
    elsif path.respond_to? :to_str and String === path.to_str
      path.to_str.dup
    else
      path.to_s.dup
    end
  end

  init
end