@@ -330,78 +330,102 @@ def prepend_prefix(prefix, relpath) # :nodoc:
330330 end
331331 private :prepend_prefix
332332
333+ # :markup: markdown
334+ #
333335 # call-seq:
334336 # cleanpath(symlinks = false) -> new_pathname
335337 #
336338 # Returns a new \Pathname object, "cleaned" of unnecessary separators,
337339 # single-dot entries, and double-dot entries.
338340 #
339- # When + self+ is empty, returns pathname with a single-dot entry:
341+ # When ` self` is empty, returns a pathname with a single-dot entry:
340342 #
341- # Pathname.new('').cleanpath # => #<Pathname:.>
343+ # ```
344+ # Pathname('').cleanpath # => #<Pathname:.>
345+ # ```
342346 #
343347 # <b>Separators</b>
344348 #
345349 # A lone separator is preserved:
346350 #
347- # Pathname.new('/').cleanpath # => #<Pathname:/>
351+ # ```
352+ # Pathname('/').cleanpath # => #<Pathname:/>
353+ # ```
348354 #
349- # Non-lone trailing separators are removed:
355+ # Multiple trailing separators are removed:
350356 #
351- # Pathname.new('foo/////').cleanpath # => #<Pathname:foo>
352- # Pathname.new('foo/').cleanpath # => #<Pathname:foo>
357+ # ```
358+ # Pathname('foo/////').cleanpath # => #<Pathname:foo>
359+ # Pathname('foo/').cleanpath # => #<Pathname:foo>
360+ # ```
353361 #
354362 # Multiple embedded separators are reduced to a single separator:
355363 #
356- # Pathname.new('foo///bar').cleanpath # => #<Pathname:foo/bar>
364+ # ```
365+ # Pathname('foo///bar').cleanpath # => #<Pathname:foo/bar>
366+ # ```
357367 #
358368 # Multiple leading separators are reduced:
359369 #
360- # # On Windows, where File.dirname('//') == '//'.
361- # Pathname.new('/////foo').cleanpath # => #<Pathname://foo>
362- # Pathname.new('/////').cleanpath # => #<Pathname://>
363- # # Otherwise, where File.dirname('//') == '/'.
364- # Pathname.new('/////foo').cleanpath # => #<Pathname:/foo>
365- # Pathname.new('/////').cleanpath # => #<Pathname:/>
370+ # ```
371+ # # On Windows, where File.dirname('//') == '//'.
372+ # Pathname('/////foo').cleanpath # => #<Pathname://foo>
373+ # Pathname('/////').cleanpath # => #<Pathname://>
374+ # # Otherwise, where File.dirname('//') == '/'.
375+ # Pathname('/////foo').cleanpath # => #<Pathname:/foo>
376+ # Pathname('/////').cleanpath # => #<Pathname:/>
377+ # ```
366378 #
367379 # <b>Single-Dot Entries</b>
368380 #
369381 # A lone single-dot entry is preserved:
370382 #
371- # Pathname.new('.').cleanpath # => #<Pathname:.>
383+ # ```
384+ # Pathname('.').cleanpath # => #<Pathname:.>
385+ # ```
372386 #
373387 # A non-lone single-dot entry, regardless of its location, is removed:
374388 #
375- # Pathname.new('foo/././././bar').cleanpath # => #<Pathname:foo/bar>
376- # Pathname.new('./foo/./././bar').cleanpath # => #<Pathname:foo/bar>
377- # Pathname.new('foo/./././bar/./').cleanpath # => #<Pathname:foo/bar>
389+ # ```
390+ # Pathname('foo/././././bar').cleanpath # => #<Pathname:foo/bar>
391+ # Pathname('./foo/./././bar').cleanpath # => #<Pathname:foo/bar>
392+ # Pathname('foo/./././bar/./').cleanpath # => #<Pathname:foo/bar>
393+ # ```
378394 #
379395 # <b>Double-Dot Entries</b>
380396 #
381397 # A lone double-dot entry is preserved:
382398 #
383- # Pathname.new('..').cleanpath # => #<Pathname:..>
399+ # ```
400+ # Pathname('..').cleanpath # => #<Pathname:..>
401+ # ```
384402 #
385403 # When a non-lone double-dot entry is preceded by a named entry, both are removed:
386404 #
387- # Pathname.new('foo/..').cleanpath # => #<Pathname:.>
388- # Pathname.new('foo/../bar').cleanpath # => #<Pathname:bar>
389- # Pathname.new('foo/../bar/..').cleanpath # => #<Pathname:.>
390- # Pathname.new('foo/bar/./../..').cleanpath # => #<Pathname:.>
405+ # ```
406+ # Pathname('foo/..').cleanpath # => #<Pathname:.>
407+ # Pathname('foo/../bar').cleanpath # => #<Pathname:bar>
408+ # Pathname('foo/../bar/..').cleanpath # => #<Pathname:.>
409+ # Pathname('foo/bar/./../..').cleanpath # => #<Pathname:.>
410+ # ```
391411 #
392412 # When a non-lone double-dot entry is _not_ preceded by a named entry,
393413 # it is preserved:
394414 #
395- # Pathname.new('../..').cleanpath # => #<Pathname:../..>
415+ # ```
416+ # Pathname('../..').cleanpath # => #<Pathname:../..>
417+ # ```
396418 #
397419 # A non-lone meaningless double-dot entry is removed:
398420 #
399- # Pathname.new('/..').cleanpath # => #<Pathname:/>
400- # Pathname.new('/../..').cleanpath # => #<Pathname:/>
421+ # ```
422+ # Pathname('/..').cleanpath # => #<Pathname:/>
423+ # Pathname('/../..').cleanpath # => #<Pathname:/>
424+ # ```
401425 #
402426 # <b> Symbolic Links</b>
403427 #
404- # If the path may contain { symbolic links}[https://en.wikipedia.org/wiki/Symbolic_link ],
428+ # If the path may contain [ symbolic links][symbolic link ],
405429 # consider give optional argument `symlinks` as `true`;
406430 # the method then uses a more conservative algorithm
407431 # that avoids breaking symbolic links.
@@ -410,25 +434,29 @@ def prepend_prefix(prefix, relpath) # :nodoc:
410434 #
411435 # Examples:
412436 #
413- # Pathname.new('a/').cleanpath # => #<Pathname:a>
414- # Pathname.new('a/').cleanpath(true) # => #<Pathname:a/>
437+ # ```
438+ # Pathname('a/').cleanpath # => #<Pathname:a>
439+ # Pathname('a/').cleanpath(true) # => #<Pathname:a/>
440+ #
441+ # Pathname('a/.').cleanpath # => #<Pathname:a>
442+ # Pathname('a/.').cleanpath(true) # => #<Pathname:a/.>
415443 #
416- # Pathname.new ('a/.').cleanpath # => #<Pathname:a>
417- # Pathname.new ('a/.').cleanpath(true) # => #<Pathname:a/.>
444+ # Pathname('a/./ ').cleanpath # => #<Pathname:a>
445+ # Pathname('a/./ ').cleanpath(true) # => #<Pathname:a/.>
418446 #
419- # Pathname.new ('a/./ ').cleanpath # => #<Pathname:a>
420- # Pathname.new ('a/./ ').cleanpath(true) # => #<Pathname:a/.>
447+ # Pathname('a/b/. ').cleanpath # => #<Pathname:a/b >
448+ # Pathname('a/b/. ').cleanpath(true) # => #<Pathname:a/b /.>
421449 #
422- # Pathname.new ('a/b /.').cleanpath # => #<Pathname:a/b >
423- # Pathname.new ('a/b /.').cleanpath(true) # => #<Pathname:a/b/ .>
450+ # Pathname('a/.. /.').cleanpath # => #<Pathname:. >
451+ # Pathname('a/.. /.').cleanpath(true) # => #<Pathname:a/. .>
424452 #
425- # Pathname.new('a/../.').cleanpath # => #<Pathname:.>
426- # Pathname.new('a/../.').cleanpath(true) # => #<Pathname:a/..>
453+ # Pathname('a/b/../../../../c/../d').cleanpath
454+ # # => #<Pathname:../../d>
455+ # Pathname('a/b/../../../../c/../d').cleanpath(true)
456+ # # => #<Pathname:a/b/../../../../c/../d>
457+ # ```
427458 #
428- # Pathname.new('a/b/../../../../c/../d').cleanpath
429- # # => #<Pathname:../../d>
430- # Pathname.new('a/b/../../../../c/../d').cleanpath(true)
431- # # => #<Pathname:a/b/../../../../c/../d>
459+ # [symbolic link]: https://en.wikipedia.org/wiki/Symbolic_link
432460 #
433461 def cleanpath ( consider_symlink = false )
434462 if consider_symlink
0 commit comments