ok, tanxs, however my pathes are comin’ from java-side (i’m using
JRuby), the reason i didn’t make use of File.[split|join], i’ve changed #compact to #delete(“”) and works fine
However, File.split and File.join are used much easier and I guess
they
are more appropriate in your case.
ok, tanxs, however my pathes are comin’ from java-side (i’m using
JRuby), the reason i didn’t make use of File.[split|join],
Why is that a reason to not use File.split and join? Are those paths
formatted differently? Normally Java uses the formatting of the platform
which Ruby does, too. The only case where they differ is a Windows box
with Ruby on cygwin IMHO.
i’ve changed #compact to #delete(“”) and works fine
I assume you changed it in class Array. That’s not a good idea since it
can break much code that depends on the standard functionality. You can
achieve the same much easier and less intrusive:
irb(main):001:0> ar = “/foo/bar”.split( ‘/’ ).select {|x| x.length > 0}
=> [“foo”, “bar”]
irb(main):002:0> ar = “/foo/bar”.split( ‘/’ ).select {|x| x != “”}
=> [“foo”, “bar”]
Or, to be sure to exlude possible Nils:
irb(main):003:0> ar = “/foo/bar”.split( ‘/’ ).select {|x| x && x.length >
0}
=> [“foo”, “bar”]
irb(main):004:0> ar = “/foo/bar”.split( ‘/’ ).select {|x| x && x != “”}
=> [“foo”, “bar”]
File.split doesn’t apply here, IMHO, because i do have “hard coded” path
parts (ie are attributes of an xml tag), the file separator is always
“/”, doesn’t depend upon platform.
then, i do right now :
pl = File.join(( context + path + “languages/bottles”).split(“/”).select
{|x| x && x != “”})
and i’m sure Ruby is aware of File::SEPARATOR, no more need to read the
java one…which is the same.
Why is that a reason to not use File.split and join? Are those paths
formatted differently? Normally Java uses the formatting of the platform
which Ruby does, too. The only case where they differ is a Windows box
with Ruby on cygwin IMHO.