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.push(mystr.split("/"))
  5. puts array
  6. for i in 0..array.length
  7. if array[i].to_s=="."
  8. array[i]=array[i+1]
  9. elseif array[i]==".."
  10. array[i-1]=array[i+2]
  11. elseif array[i]==" "
  12. array[i]="/"  # for double slash
  13. else
  14. array[i]=array[i]
  15. end
  16. end
  17. mystr1=array.join("/")
  18. puts mystr1