Isn't a Windows pathname with surrounding double quotes a valid
pathname?!?!?
What's the best Ruby-esque way to stip out surrounding double quotes
if
they exist?
And ,yes, your example and Rob Biedenharn's example both work.
Thank you to both.
Well, perhaps you're thinking of the quotes that are needed/used to
supply a path containing spaces to a command-line program.
In any case, you could remove quotes with:
def unquote(string)
string.sub(/\A(['"])(.*)\1\z/, '\2')
end
unquote(IMAGEMAGICK_EXE_PATH)
irb> IMAGEMAGICK_EXE_PATH = '"f:\Program Files\ImageMagick-6.5.8-
Q16\convert.exe"'
=> "\"f:\\Program Files\\ImageMagick-6.5.8-Q16\\convert.exe\""
Note that the canonical representation of the string makes the
included double-quotes obvious.
irb> def unquote(string)
irb> string.sub(/\A(['"])(.*)\1\z/, '\2')
irb> end
=> nil
irb> unquote(IMAGEMAGICK_EXE_PATH)
=> "f:\\Program Files\\ImageMagick-6.5.8-Q16\\convert.exe"
Compare this result to the value of IMAGEMAGICK_EXE_PATH itself above.
irb> unquote(unquote(IMAGEMAGICK_EXE_PATH))
=> "f:\\Program Files\\ImageMagick-6.5.8-Q16\\convert.exe"
And this is save against a path without quotes, too.
-Rob
Rob Biedenharn
http://agileconsultingllc.com
(e-mail address removed)