Path


Data structures Strings Public

Hard  

30min


Write a function that provides change directory (cd) function for an abstract file system.

Notes:

  • Root path is '/'.
  • Path separator is '/'.
  • Parent directory is addressable as '..'.
  • Directory names consist only of English alphabet letters (A-Z and a-z).

For example:

path = Path.new('/a/b/c/d')
puts path.cd('../x').current_path

should display '/a/b/c/x'.

Note: Do not use built-in path-related functions.

Ruby 2.2.2
 
 


  •   Example case: NoMethodError: pathtest.rb:10:in `test1'
  •   Two times down: NoMethodError: pathtest.rb:21:in `test2'
  •   Two times up: NoMethodError: pathtest.rb:37:in `test3'
  •   Complex paths: NoMethodError: pathtest.rb:57:in `test4'