Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: pathname.rb
#
[0] Fix | Delete
# = pathname.rb
[1] Fix | Delete
#
[2] Fix | Delete
# Object-Oriented Pathname Class
[3] Fix | Delete
#
[4] Fix | Delete
# Author:: Tanaka Akira <akr@m17n.org>
[5] Fix | Delete
# Documentation:: Author and Gavin Sinclair
[6] Fix | Delete
#
[7] Fix | Delete
# For documentation, see class Pathname.
[8] Fix | Delete
#
[9] Fix | Delete
[10] Fix | Delete
require 'pathname.so'
[11] Fix | Delete
[12] Fix | Delete
class Pathname
[13] Fix | Delete
[14] Fix | Delete
# :stopdoc:
[15] Fix | Delete
if RUBY_VERSION < "1.9"
[16] Fix | Delete
TO_PATH = :to_str
[17] Fix | Delete
else
[18] Fix | Delete
# to_path is implemented so Pathname objects are usable with File.open, etc.
[19] Fix | Delete
TO_PATH = :to_path
[20] Fix | Delete
end
[21] Fix | Delete
[22] Fix | Delete
SAME_PATHS = if File::FNM_SYSCASE.nonzero?
[23] Fix | Delete
# Avoid #zero? here because #casecmp can return nil.
[24] Fix | Delete
proc {|a, b| a.casecmp(b) == 0}
[25] Fix | Delete
else
[26] Fix | Delete
proc {|a, b| a == b}
[27] Fix | Delete
end
[28] Fix | Delete
[29] Fix | Delete
[30] Fix | Delete
if File::ALT_SEPARATOR
[31] Fix | Delete
SEPARATOR_LIST = "#{Regexp.quote File::ALT_SEPARATOR}#{Regexp.quote File::SEPARATOR}"
[32] Fix | Delete
SEPARATOR_PAT = /[#{SEPARATOR_LIST}]/
[33] Fix | Delete
else
[34] Fix | Delete
SEPARATOR_LIST = "#{Regexp.quote File::SEPARATOR}"
[35] Fix | Delete
SEPARATOR_PAT = /#{Regexp.quote File::SEPARATOR}/
[36] Fix | Delete
end
[37] Fix | Delete
[38] Fix | Delete
# :startdoc:
[39] Fix | Delete
[40] Fix | Delete
# chop_basename(path) -> [pre-basename, basename] or nil
[41] Fix | Delete
def chop_basename(path) # :nodoc:
[42] Fix | Delete
base = File.basename(path)
[43] Fix | Delete
if /\A#{SEPARATOR_PAT}?\z/o =~ base
[44] Fix | Delete
return nil
[45] Fix | Delete
else
[46] Fix | Delete
return path[0, path.rindex(base)], base
[47] Fix | Delete
end
[48] Fix | Delete
end
[49] Fix | Delete
private :chop_basename
[50] Fix | Delete
[51] Fix | Delete
# split_names(path) -> prefix, [name, ...]
[52] Fix | Delete
def split_names(path) # :nodoc:
[53] Fix | Delete
names = []
[54] Fix | Delete
while r = chop_basename(path)
[55] Fix | Delete
path, basename = r
[56] Fix | Delete
names.unshift basename
[57] Fix | Delete
end
[58] Fix | Delete
return path, names
[59] Fix | Delete
end
[60] Fix | Delete
private :split_names
[61] Fix | Delete
[62] Fix | Delete
def prepend_prefix(prefix, relpath) # :nodoc:
[63] Fix | Delete
if relpath.empty?
[64] Fix | Delete
File.dirname(prefix)
[65] Fix | Delete
elsif /#{SEPARATOR_PAT}/o =~ prefix
[66] Fix | Delete
prefix = File.dirname(prefix)
[67] Fix | Delete
prefix = File.join(prefix, "") if File.basename(prefix + 'a') != 'a'
[68] Fix | Delete
prefix + relpath
[69] Fix | Delete
else
[70] Fix | Delete
prefix + relpath
[71] Fix | Delete
end
[72] Fix | Delete
end
[73] Fix | Delete
private :prepend_prefix
[74] Fix | Delete
[75] Fix | Delete
# Returns clean pathname of +self+ with consecutive slashes and useless dots
[76] Fix | Delete
# removed. The filesystem is not accessed.
[77] Fix | Delete
#
[78] Fix | Delete
# If +consider_symlink+ is +true+, then a more conservative algorithm is used
[79] Fix | Delete
# to avoid breaking symbolic linkages. This may retain more +..+
[80] Fix | Delete
# entries than absolutely necessary, but without accessing the filesystem,
[81] Fix | Delete
# this can't be avoided.
[82] Fix | Delete
#
[83] Fix | Delete
# See Pathname#realpath.
[84] Fix | Delete
#
[85] Fix | Delete
def cleanpath(consider_symlink=false)
[86] Fix | Delete
if consider_symlink
[87] Fix | Delete
cleanpath_conservative
[88] Fix | Delete
else
[89] Fix | Delete
cleanpath_aggressive
[90] Fix | Delete
end
[91] Fix | Delete
end
[92] Fix | Delete
[93] Fix | Delete
#
[94] Fix | Delete
# Clean the path simply by resolving and removing excess +.+ and +..+ entries.
[95] Fix | Delete
# Nothing more, nothing less.
[96] Fix | Delete
#
[97] Fix | Delete
def cleanpath_aggressive # :nodoc:
[98] Fix | Delete
path = @path
[99] Fix | Delete
names = []
[100] Fix | Delete
pre = path
[101] Fix | Delete
while r = chop_basename(pre)
[102] Fix | Delete
pre, base = r
[103] Fix | Delete
case base
[104] Fix | Delete
when '.'
[105] Fix | Delete
when '..'
[106] Fix | Delete
names.unshift base
[107] Fix | Delete
else
[108] Fix | Delete
if names[0] == '..'
[109] Fix | Delete
names.shift
[110] Fix | Delete
else
[111] Fix | Delete
names.unshift base
[112] Fix | Delete
end
[113] Fix | Delete
end
[114] Fix | Delete
end
[115] Fix | Delete
pre.tr!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
[116] Fix | Delete
if /#{SEPARATOR_PAT}/o =~ File.basename(pre)
[117] Fix | Delete
names.shift while names[0] == '..'
[118] Fix | Delete
end
[119] Fix | Delete
self.class.new(prepend_prefix(pre, File.join(*names)))
[120] Fix | Delete
end
[121] Fix | Delete
private :cleanpath_aggressive
[122] Fix | Delete
[123] Fix | Delete
# has_trailing_separator?(path) -> bool
[124] Fix | Delete
def has_trailing_separator?(path) # :nodoc:
[125] Fix | Delete
if r = chop_basename(path)
[126] Fix | Delete
pre, basename = r
[127] Fix | Delete
pre.length + basename.length < path.length
[128] Fix | Delete
else
[129] Fix | Delete
false
[130] Fix | Delete
end
[131] Fix | Delete
end
[132] Fix | Delete
private :has_trailing_separator?
[133] Fix | Delete
[134] Fix | Delete
# add_trailing_separator(path) -> path
[135] Fix | Delete
def add_trailing_separator(path) # :nodoc:
[136] Fix | Delete
if File.basename(path + 'a') == 'a'
[137] Fix | Delete
path
[138] Fix | Delete
else
[139] Fix | Delete
File.join(path, "") # xxx: Is File.join is appropriate to add separator?
[140] Fix | Delete
end
[141] Fix | Delete
end
[142] Fix | Delete
private :add_trailing_separator
[143] Fix | Delete
[144] Fix | Delete
def del_trailing_separator(path) # :nodoc:
[145] Fix | Delete
if r = chop_basename(path)
[146] Fix | Delete
pre, basename = r
[147] Fix | Delete
pre + basename
[148] Fix | Delete
elsif /#{SEPARATOR_PAT}+\z/o =~ path
[149] Fix | Delete
$` + File.dirname(path)[/#{SEPARATOR_PAT}*\z/o]
[150] Fix | Delete
else
[151] Fix | Delete
path
[152] Fix | Delete
end
[153] Fix | Delete
end
[154] Fix | Delete
private :del_trailing_separator
[155] Fix | Delete
[156] Fix | Delete
def cleanpath_conservative # :nodoc:
[157] Fix | Delete
path = @path
[158] Fix | Delete
names = []
[159] Fix | Delete
pre = path
[160] Fix | Delete
while r = chop_basename(pre)
[161] Fix | Delete
pre, base = r
[162] Fix | Delete
names.unshift base if base != '.'
[163] Fix | Delete
end
[164] Fix | Delete
pre.tr!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
[165] Fix | Delete
if /#{SEPARATOR_PAT}/o =~ File.basename(pre)
[166] Fix | Delete
names.shift while names[0] == '..'
[167] Fix | Delete
end
[168] Fix | Delete
if names.empty?
[169] Fix | Delete
self.class.new(File.dirname(pre))
[170] Fix | Delete
else
[171] Fix | Delete
if names.last != '..' && File.basename(path) == '.'
[172] Fix | Delete
names << '.'
[173] Fix | Delete
end
[174] Fix | Delete
result = prepend_prefix(pre, File.join(*names))
[175] Fix | Delete
if /\A(?:\.|\.\.)\z/ !~ names.last && has_trailing_separator?(path)
[176] Fix | Delete
self.class.new(add_trailing_separator(result))
[177] Fix | Delete
else
[178] Fix | Delete
self.class.new(result)
[179] Fix | Delete
end
[180] Fix | Delete
end
[181] Fix | Delete
end
[182] Fix | Delete
private :cleanpath_conservative
[183] Fix | Delete
[184] Fix | Delete
# Returns the parent directory.
[185] Fix | Delete
#
[186] Fix | Delete
# This is same as <code>self + '..'</code>.
[187] Fix | Delete
def parent
[188] Fix | Delete
self + '..'
[189] Fix | Delete
end
[190] Fix | Delete
[191] Fix | Delete
# Returns +true+ if +self+ points to a mountpoint.
[192] Fix | Delete
def mountpoint?
[193] Fix | Delete
begin
[194] Fix | Delete
stat1 = self.lstat
[195] Fix | Delete
stat2 = self.parent.lstat
[196] Fix | Delete
stat1.dev == stat2.dev && stat1.ino == stat2.ino ||
[197] Fix | Delete
stat1.dev != stat2.dev
[198] Fix | Delete
rescue Errno::ENOENT
[199] Fix | Delete
false
[200] Fix | Delete
end
[201] Fix | Delete
end
[202] Fix | Delete
[203] Fix | Delete
#
[204] Fix | Delete
# Predicate method for root directories. Returns +true+ if the
[205] Fix | Delete
# pathname consists of consecutive slashes.
[206] Fix | Delete
#
[207] Fix | Delete
# It doesn't access the filesystem. So it may return +false+ for some
[208] Fix | Delete
# pathnames which points to roots such as <tt>/usr/..</tt>.
[209] Fix | Delete
#
[210] Fix | Delete
def root?
[211] Fix | Delete
!!(chop_basename(@path) == nil && /#{SEPARATOR_PAT}/o =~ @path)
[212] Fix | Delete
end
[213] Fix | Delete
[214] Fix | Delete
# Predicate method for testing whether a path is absolute.
[215] Fix | Delete
#
[216] Fix | Delete
# It returns +true+ if the pathname begins with a slash.
[217] Fix | Delete
#
[218] Fix | Delete
# p = Pathname.new('/im/sure')
[219] Fix | Delete
# p.absolute?
[220] Fix | Delete
# #=> true
[221] Fix | Delete
#
[222] Fix | Delete
# p = Pathname.new('not/so/sure')
[223] Fix | Delete
# p.absolute?
[224] Fix | Delete
# #=> false
[225] Fix | Delete
def absolute?
[226] Fix | Delete
!relative?
[227] Fix | Delete
end
[228] Fix | Delete
[229] Fix | Delete
# The opposite of Pathname#absolute?
[230] Fix | Delete
#
[231] Fix | Delete
# It returns +false+ if the pathname begins with a slash.
[232] Fix | Delete
#
[233] Fix | Delete
# p = Pathname.new('/im/sure')
[234] Fix | Delete
# p.relative?
[235] Fix | Delete
# #=> false
[236] Fix | Delete
#
[237] Fix | Delete
# p = Pathname.new('not/so/sure')
[238] Fix | Delete
# p.relative?
[239] Fix | Delete
# #=> true
[240] Fix | Delete
def relative?
[241] Fix | Delete
path = @path
[242] Fix | Delete
while r = chop_basename(path)
[243] Fix | Delete
path, = r
[244] Fix | Delete
end
[245] Fix | Delete
path == ''
[246] Fix | Delete
end
[247] Fix | Delete
[248] Fix | Delete
#
[249] Fix | Delete
# Iterates over each component of the path.
[250] Fix | Delete
#
[251] Fix | Delete
# Pathname.new("/usr/bin/ruby").each_filename {|filename| ... }
[252] Fix | Delete
# # yields "usr", "bin", and "ruby".
[253] Fix | Delete
#
[254] Fix | Delete
# Returns an Enumerator if no block was given.
[255] Fix | Delete
#
[256] Fix | Delete
# enum = Pathname.new("/usr/bin/ruby").each_filename
[257] Fix | Delete
# # ... do stuff ...
[258] Fix | Delete
# enum.each { |e| ... }
[259] Fix | Delete
# # yields "usr", "bin", and "ruby".
[260] Fix | Delete
#
[261] Fix | Delete
def each_filename # :yield: filename
[262] Fix | Delete
return to_enum(__method__) unless block_given?
[263] Fix | Delete
_, names = split_names(@path)
[264] Fix | Delete
names.each {|filename| yield filename }
[265] Fix | Delete
nil
[266] Fix | Delete
end
[267] Fix | Delete
[268] Fix | Delete
# Iterates over and yields a new Pathname object
[269] Fix | Delete
# for each element in the given path in descending order.
[270] Fix | Delete
#
[271] Fix | Delete
# Pathname.new('/path/to/some/file.rb').descend {|v| p v}
[272] Fix | Delete
# #<Pathname:/>
[273] Fix | Delete
# #<Pathname:/path>
[274] Fix | Delete
# #<Pathname:/path/to>
[275] Fix | Delete
# #<Pathname:/path/to/some>
[276] Fix | Delete
# #<Pathname:/path/to/some/file.rb>
[277] Fix | Delete
#
[278] Fix | Delete
# Pathname.new('path/to/some/file.rb').descend {|v| p v}
[279] Fix | Delete
# #<Pathname:path>
[280] Fix | Delete
# #<Pathname:path/to>
[281] Fix | Delete
# #<Pathname:path/to/some>
[282] Fix | Delete
# #<Pathname:path/to/some/file.rb>
[283] Fix | Delete
#
[284] Fix | Delete
# It doesn't access the filesystem.
[285] Fix | Delete
#
[286] Fix | Delete
def descend
[287] Fix | Delete
vs = []
[288] Fix | Delete
ascend {|v| vs << v }
[289] Fix | Delete
vs.reverse_each {|v| yield v }
[290] Fix | Delete
nil
[291] Fix | Delete
end
[292] Fix | Delete
[293] Fix | Delete
# Iterates over and yields a new Pathname object
[294] Fix | Delete
# for each element in the given path in ascending order.
[295] Fix | Delete
#
[296] Fix | Delete
# Pathname.new('/path/to/some/file.rb').ascend {|v| p v}
[297] Fix | Delete
# #<Pathname:/path/to/some/file.rb>
[298] Fix | Delete
# #<Pathname:/path/to/some>
[299] Fix | Delete
# #<Pathname:/path/to>
[300] Fix | Delete
# #<Pathname:/path>
[301] Fix | Delete
# #<Pathname:/>
[302] Fix | Delete
#
[303] Fix | Delete
# Pathname.new('path/to/some/file.rb').ascend {|v| p v}
[304] Fix | Delete
# #<Pathname:path/to/some/file.rb>
[305] Fix | Delete
# #<Pathname:path/to/some>
[306] Fix | Delete
# #<Pathname:path/to>
[307] Fix | Delete
# #<Pathname:path>
[308] Fix | Delete
#
[309] Fix | Delete
# It doesn't access the filesystem.
[310] Fix | Delete
#
[311] Fix | Delete
def ascend
[312] Fix | Delete
path = @path
[313] Fix | Delete
yield self
[314] Fix | Delete
while r = chop_basename(path)
[315] Fix | Delete
path, = r
[316] Fix | Delete
break if path.empty?
[317] Fix | Delete
yield self.class.new(del_trailing_separator(path))
[318] Fix | Delete
end
[319] Fix | Delete
end
[320] Fix | Delete
[321] Fix | Delete
#
[322] Fix | Delete
# Appends a pathname fragment to +self+ to produce a new Pathname object.
[323] Fix | Delete
#
[324] Fix | Delete
# p1 = Pathname.new("/usr") # Pathname:/usr
[325] Fix | Delete
# p2 = p1 + "bin/ruby" # Pathname:/usr/bin/ruby
[326] Fix | Delete
# p3 = p1 + "/etc/passwd" # Pathname:/etc/passwd
[327] Fix | Delete
#
[328] Fix | Delete
# # / is aliased to +.
[329] Fix | Delete
# p4 = p1 / "bin/ruby" # Pathname:/usr/bin/ruby
[330] Fix | Delete
# p5 = p1 / "/etc/passwd" # Pathname:/etc/passwd
[331] Fix | Delete
#
[332] Fix | Delete
# This method doesn't access the file system; it is pure string manipulation.
[333] Fix | Delete
#
[334] Fix | Delete
def +(other)
[335] Fix | Delete
other = Pathname.new(other) unless Pathname === other
[336] Fix | Delete
Pathname.new(plus(@path, other.to_s))
[337] Fix | Delete
end
[338] Fix | Delete
alias / +
[339] Fix | Delete
[340] Fix | Delete
def plus(path1, path2) # -> path # :nodoc:
[341] Fix | Delete
prefix2 = path2
[342] Fix | Delete
index_list2 = []
[343] Fix | Delete
basename_list2 = []
[344] Fix | Delete
while r2 = chop_basename(prefix2)
[345] Fix | Delete
prefix2, basename2 = r2
[346] Fix | Delete
index_list2.unshift prefix2.length
[347] Fix | Delete
basename_list2.unshift basename2
[348] Fix | Delete
end
[349] Fix | Delete
return path2 if prefix2 != ''
[350] Fix | Delete
prefix1 = path1
[351] Fix | Delete
while true
[352] Fix | Delete
while !basename_list2.empty? && basename_list2.first == '.'
[353] Fix | Delete
index_list2.shift
[354] Fix | Delete
basename_list2.shift
[355] Fix | Delete
end
[356] Fix | Delete
break unless r1 = chop_basename(prefix1)
[357] Fix | Delete
prefix1, basename1 = r1
[358] Fix | Delete
next if basename1 == '.'
[359] Fix | Delete
if basename1 == '..' || basename_list2.empty? || basename_list2.first != '..'
[360] Fix | Delete
prefix1 = prefix1 + basename1
[361] Fix | Delete
break
[362] Fix | Delete
end
[363] Fix | Delete
index_list2.shift
[364] Fix | Delete
basename_list2.shift
[365] Fix | Delete
end
[366] Fix | Delete
r1 = chop_basename(prefix1)
[367] Fix | Delete
if !r1 && /#{SEPARATOR_PAT}/o =~ File.basename(prefix1)
[368] Fix | Delete
while !basename_list2.empty? && basename_list2.first == '..'
[369] Fix | Delete
index_list2.shift
[370] Fix | Delete
basename_list2.shift
[371] Fix | Delete
end
[372] Fix | Delete
end
[373] Fix | Delete
if !basename_list2.empty?
[374] Fix | Delete
suffix2 = path2[index_list2.first..-1]
[375] Fix | Delete
r1 ? File.join(prefix1, suffix2) : prefix1 + suffix2
[376] Fix | Delete
else
[377] Fix | Delete
r1 ? prefix1 : File.dirname(prefix1)
[378] Fix | Delete
end
[379] Fix | Delete
end
[380] Fix | Delete
private :plus
[381] Fix | Delete
[382] Fix | Delete
#
[383] Fix | Delete
# Joins the given pathnames onto +self+ to create a new Pathname object.
[384] Fix | Delete
#
[385] Fix | Delete
# path0 = Pathname.new("/usr") # Pathname:/usr
[386] Fix | Delete
# path0 = path0.join("bin/ruby") # Pathname:/usr/bin/ruby
[387] Fix | Delete
# # is the same as
[388] Fix | Delete
# path1 = Pathname.new("/usr") + "bin/ruby" # Pathname:/usr/bin/ruby
[389] Fix | Delete
# path0 == path1
[390] Fix | Delete
# #=> true
[391] Fix | Delete
#
[392] Fix | Delete
def join(*args)
[393] Fix | Delete
return self if args.empty?
[394] Fix | Delete
result = args.pop
[395] Fix | Delete
result = Pathname.new(result) unless Pathname === result
[396] Fix | Delete
return result if result.absolute?
[397] Fix | Delete
args.reverse_each {|arg|
[398] Fix | Delete
arg = Pathname.new(arg) unless Pathname === arg
[399] Fix | Delete
result = arg + result
[400] Fix | Delete
return result if result.absolute?
[401] Fix | Delete
}
[402] Fix | Delete
self + result
[403] Fix | Delete
end
[404] Fix | Delete
[405] Fix | Delete
#
[406] Fix | Delete
# Returns the children of the directory (files and subdirectories, not
[407] Fix | Delete
# recursive) as an array of Pathname objects.
[408] Fix | Delete
#
[409] Fix | Delete
# By default, the returned pathnames will have enough information to access
[410] Fix | Delete
# the files. If you set +with_directory+ to +false+, then the returned
[411] Fix | Delete
# pathnames will contain the filename only.
[412] Fix | Delete
#
[413] Fix | Delete
# For example:
[414] Fix | Delete
# pn = Pathname("/usr/lib/ruby/1.8")
[415] Fix | Delete
# pn.children
[416] Fix | Delete
# # -> [ Pathname:/usr/lib/ruby/1.8/English.rb,
[417] Fix | Delete
# Pathname:/usr/lib/ruby/1.8/Env.rb,
[418] Fix | Delete
# Pathname:/usr/lib/ruby/1.8/abbrev.rb, ... ]
[419] Fix | Delete
# pn.children(false)
[420] Fix | Delete
# # -> [ Pathname:English.rb, Pathname:Env.rb, Pathname:abbrev.rb, ... ]
[421] Fix | Delete
#
[422] Fix | Delete
# Note that the results never contain the entries +.+ and +..+ in
[423] Fix | Delete
# the directory because they are not children.
[424] Fix | Delete
#
[425] Fix | Delete
def children(with_directory=true)
[426] Fix | Delete
with_directory = false if @path == '.'
[427] Fix | Delete
result = []
[428] Fix | Delete
Dir.foreach(@path) {|e|
[429] Fix | Delete
next if e == '.' || e == '..'
[430] Fix | Delete
if with_directory
[431] Fix | Delete
result << self.class.new(File.join(@path, e))
[432] Fix | Delete
else
[433] Fix | Delete
result << self.class.new(e)
[434] Fix | Delete
end
[435] Fix | Delete
}
[436] Fix | Delete
result
[437] Fix | Delete
end
[438] Fix | Delete
[439] Fix | Delete
# Iterates over the children of the directory
[440] Fix | Delete
# (files and subdirectories, not recursive).
[441] Fix | Delete
#
[442] Fix | Delete
# It yields Pathname object for each child.
[443] Fix | Delete
#
[444] Fix | Delete
# By default, the yielded pathnames will have enough information to access
[445] Fix | Delete
# the files.
[446] Fix | Delete
#
[447] Fix | Delete
# If you set +with_directory+ to +false+, then the returned pathnames will
[448] Fix | Delete
# contain the filename only.
[449] Fix | Delete
#
[450] Fix | Delete
# Pathname("/usr/local").each_child {|f| p f }
[451] Fix | Delete
# #=> #<Pathname:/usr/local/share>
[452] Fix | Delete
# # #<Pathname:/usr/local/bin>
[453] Fix | Delete
# # #<Pathname:/usr/local/games>
[454] Fix | Delete
# # #<Pathname:/usr/local/lib>
[455] Fix | Delete
# # #<Pathname:/usr/local/include>
[456] Fix | Delete
# # #<Pathname:/usr/local/sbin>
[457] Fix | Delete
# # #<Pathname:/usr/local/src>
[458] Fix | Delete
# # #<Pathname:/usr/local/man>
[459] Fix | Delete
#
[460] Fix | Delete
# Pathname("/usr/local").each_child(false) {|f| p f }
[461] Fix | Delete
# #=> #<Pathname:share>
[462] Fix | Delete
# # #<Pathname:bin>
[463] Fix | Delete
# # #<Pathname:games>
[464] Fix | Delete
# # #<Pathname:lib>
[465] Fix | Delete
# # #<Pathname:include>
[466] Fix | Delete
# # #<Pathname:sbin>
[467] Fix | Delete
# # #<Pathname:src>
[468] Fix | Delete
# # #<Pathname:man>
[469] Fix | Delete
#
[470] Fix | Delete
# Note that the results never contain the entries +.+ and +..+ in
[471] Fix | Delete
# the directory because they are not children.
[472] Fix | Delete
#
[473] Fix | Delete
# See Pathname#children
[474] Fix | Delete
#
[475] Fix | Delete
def each_child(with_directory=true, &b)
[476] Fix | Delete
children(with_directory).each(&b)
[477] Fix | Delete
end
[478] Fix | Delete
[479] Fix | Delete
#
[480] Fix | Delete
# Returns a relative path from the given +base_directory+ to the receiver.
[481] Fix | Delete
#
[482] Fix | Delete
# If +self+ is absolute, then +base_directory+ must be absolute too.
[483] Fix | Delete
#
[484] Fix | Delete
# If +self+ is relative, then +base_directory+ must be relative too.
[485] Fix | Delete
#
[486] Fix | Delete
# This method doesn't access the filesystem. It assumes no symlinks.
[487] Fix | Delete
#
[488] Fix | Delete
# ArgumentError is raised when it cannot find a relative path.
[489] Fix | Delete
#
[490] Fix | Delete
def relative_path_from(base_directory)
[491] Fix | Delete
dest_directory = self.cleanpath.to_s
[492] Fix | Delete
base_directory = base_directory.cleanpath.to_s
[493] Fix | Delete
dest_prefix = dest_directory
[494] Fix | Delete
dest_names = []
[495] Fix | Delete
while r = chop_basename(dest_prefix)
[496] Fix | Delete
dest_prefix, basename = r
[497] Fix | Delete
dest_names.unshift basename if basename != '.'
[498] Fix | Delete
end
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function