[#3006] mismatched quotation — "stevan apter" <apter@...>

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

[ruby-talk:02897] Funny unexpected match....

From: "David Douthitt" <DDouthitt@...>
Date: 2000-05-18 19:45:04 UTC
List: ruby-talk #2897
Put simply, using "||" as a match expression in gsub matches an empty =
line.  Say WHAT?  I want to match a literal "vertical-bar vertical-bar".

Here's the test code:

#!/opt/ruby/bin/ruby

# ruby 1.4.3 (1999-12-08) [hppa1.1-hpux10.20]

test =3D "||"
test2 =3D "\|\|"
line =3D ""

p line.gsub(/#{test}/, "*** ding ding ding ***")
p line.gsub(/#{test2}/, "*** dong dong dong ***")

To me, this should print

nil
nil

But the output instead is:

*** ding ding ding ***
*** dong dong dong ***

Why?

PS: This code came up in a pretty printer I'm writing - not a "reformatter"=
 but an HTML-based "pretty-printer" which highlights different sections =
and so on.  If you've read "Code Complete" you've seen something like it.  =
If you haven't read "Code Complete", YOU SHOULD (as well as any programmers=
 working for you, or any programmers you work for, or any programmers you =
know...... :-)

In This Thread

Prev Next