Ask a Question related to Ruby, Design and Development.
-
dblack@wobblini.net #1
Re: Backslash substitution question<Pine.LNX.4.44.0311111730390.16432-100000@ool-4355dfae.dyn.optonline.net>
Hi --
On Wed, 12 Nov 2003, Ron Coutts wrote:
Are you doing this in irb? If so, you'll get a quoted and escaped> I'm having trouble with backslashes and I don't know what is wrong. I
> can't seem to write and expression that will evaluate to a string
> containing a single backslash character as in "\". It seems that "\\"
> in Ruby evaluates to "\\" not to "\" as I would expect. Below are a few
> things I've tried. If anyone could send back a quick answer it would be
> much appreciated.
>
> res = "c:/foo/bar".gsub(/\//, "\\") # -> c:\\foo\\bar
> res = "c:/foo/bar".gsub(/\//, '\\') # -> c:\\foo\\bar
> #res = "c:/foo/bar".gsub(/\//, "\") # -> syntax error - unterminated
> string meets end of file
> #res = "c:/foo/bar".gsub(/\//, '\') # -> syntax error - unterminated
> string meets end of file
> res = "c:/foo/bar".gsub(/\//) { "\\"} # -> c:\\foo\\bar
version of the new string which shows you \\ where the string actually
has \
irb(main):005:0> res = "c:/foo/bar".gsub(/\//, "\\")
=> "c:\\foo\\bar"
irb(main):006:0> puts res
c:\foo\bar
irb(main):007:0> res.size
=> 10
David
--
David Alan Black
home: [email]dblack@wobblini.net[/email] # New email address
work: [email]blackdav@shu.edu[/email]
Web: [url]http://pirate.shu.edu/~blackdav[/url]
dblack@wobblini.net Guest
-
learning the "Ruby way"<Pine.LNX.4.44.0311201150530.4491-100000@ool-4355dfae.dyn.optonline.net><Pine.LNX.4.44.0311201137580.4435-100000@ool-4355dfae.dyn.optonline.net>
Hi -- On Fri, 21 Nov 2003 dblack@wobblini.net wrote: Just to clarify: "This" means my solution, not your question :-) David -
"stereotyping" (was: Strong Typing (Managing metadata aboutattribute types))<Pine.LNX.4.44.0311171402340.1133-100000@ool-4355dfae.dyn.optonline.net><Pine.LNX.4.44.0311181524130.2236-100000@ool-4355dfae.dyn.optonline.net>
Hi -- On Tue, 18 Nov 2003, Thien Vuong wrote: Class name checking doesn't ensure needed behavior. Actually, let me say first that while I... -
Prolly a simple question<Pine.LNX.4.44.0310111117330.29007-100000@ool-4355dfae.dyn.optonline.net><Pine.LNX.4.44.0310111103530.28872-100000@ool-4355dfae.dyn.optonline.net>
Whoops, that was a message from March I just replied to. We're getting another wave of old messages. David -- David Alan Black home:... -
Prolly a simple question<Pine.LNX.4.44.0310111103530.28872-100000@ool-4355dfae.dyn.optonline.net>
Hi -- Answering 2/3 of your questions :-) On Sat, 11 Oct 2003 ghost-no-spam@cotse.net wrote: No it doesn't: irb(main):001:0> w = nil -
Enumerable#inject is surprising me...<Pine.LNX.4.44.0310082145050.20002-100000@ool-4355dfae.dyn.optonline.net><Pine.LNX.4.44.0310082132090.19888-100000@ool-4355dfae.dyn.optonline.net>
On Thu, 9 Oct 2003 dblack@superlink.net wrote: Whoops, I mean how it gets into the second one at all. David -- David Alan Black



Reply With Quote

