私は次のような文字列を持っています:
str = "/some/path/to/some/file.ext"
結果は次のようになります。
[path, dir, file]
=> ["/some/path/to", "some", "file.ext"]
私の現在のコード:
chunks = str.split '/'
=> ["", "some", "path", "to", "some", "file.ext"]
file = chunks.pop
=> "file.ext"
dir = chunks.pop
=> "some"
path = chunks.join '/'
=> "/some/path/to"
しかし、それは醜くて遅いです。
正規表現も試しFile.split
ましたが、さらに醜い混乱が発生しました。
解決策は何ですか?