Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 0.35 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/ruby -w
  2. array=Array.new
  3. mystr=String.new("foo/./bar")
  4. array=mystr.split("/")
  5. for i in 0..(array.length-1)
  6. if array[i].to_s=="."
  7. array[i]=array[i+1]
  8. elsif array[i].to_s==".."
  9. array[i-1]=array[i+2]
  10. elsif array[i].to_s==""
  11. array[i]="/"  # for double slash
  12. else
  13. array[i]=array[i]
  14. end
  15. end
  16. puts array
  17. mystr1=array.join("/")
  18. puts mystr1