Yukihiro - Please ensure backwards compatibility

J

Joseph Benik

having recently migrated one of my machines from a 1.6 flavor to the
new 1.8 i must say i was surprised to see problems with


blah.gsub!("testing", ' ')



i got a message that it was going to ignore(?) this statement as
"testing" was not a regexp..... this hit me on more than one script,
forcing me into a quick-fix mode as i definitely was not anticipating
this script-debilitating "ignore" of my code...


i don't understand the need to nitpick the regexp in this case, if
someone passes a string it seems quite a simple task for you to
_ENSURE BACKWARDS COMPATIBILITY_ and convert it internally to a regexp
 
E

Elias Athanasopoulos

This is a deprecation warning. It will no longer be backwards compatible in
1.9 and later, IIRC (maybe as early as 1.8.1).

In 1.8.0, however, it's just a warning.

I had this "problem", too. I can't see why Ruby is so verbose on that
and doesn't interpret foo.gsub[!]("bar", ...) as foo.gsub[!](/bar/, ...)
automagically...

Regards,
 
A

Ara.T.Howard

Date: Fri, 19 Dec 2003 03:12:57 +0900
From: Elias Athanasopoulos <[email protected]>
Newsgroups: comp.lang.ruby
Subject: Re: Yukihiro - Please ensure backwards compatibility

This is a deprecation warning. It will no longer be backwards compatible in
1.9 and later, IIRC (maybe as early as 1.8.1).

In 1.8.0, however, it's just a warning.

I had this "problem", too. I can't see why Ruby is so verbose on that
and doesn't interpret foo.gsub[!]("bar", ...) as foo.gsub[!](/bar/, ...)
automagically...
^^^^^^^^^^^^^
^^^^^^^^^^^^^

this word is the reason for many, many, many hours spent debugging perl
scripts. if you have done much perl programming you will know exactly what i
mean.

i'm all for backward compatibility - unless the 'old' way wasn't all that good.
IMHO, it wasn't all that good to be able to do this (same situation as gsub)


# why doesn't this work, after all my string does start with an 'a'?

~ > ruby16 -e 'puts( ("^a" =~ "ara") && "matched!" )'
nil


# oh right, wrong dang order - there went 10 minutes!

~ > ruby16 -e 'puts( ("ara" =~ "^a") && "matched!" )'
matched!



# now under ruby18 we are notified and have plenty of time to correct before
# 1.9. backward compat is also preserved.

~ > ruby18 -e 'puts( ("ara" =~ "^a") && "matched!" )'
-e:1: warning: string =~ string will be obsolete; use explicit regexp
matched!

~ > ruby18 -e 'puts( ("^a" =~ "ara") && "matched!" )'
-e:1: warning: string =~ string will be obsolete; use explicit regexp
nil


i'm all for this break of backward compat... my 2 cents.

-a
--

ATTN: please update your address books with address below!

===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
 
F

Florian Gross

Joseph said:
blah.gsub!("testing", ' ')
i got a message that it was going to ignore(?) this statement as
"testing" was not a regexp..... this hit me on more than one script,
forcing me into a quick-fix mode as i definitely was not anticipating
this script-debilitating "ignore" of my code...

Your statement won't be ignored, there will just be that warning. Why?
Because "...bar".gsub(".", "foo") produces "foofoofoobar" and not
"foofoofoofoofoofoo". This wasn't always this way -- in Ruby 1.6.8
Strings were handled just like Regexps in this case. I myself really
prefer the current behaviour to the old one because the old one is still
available (use /#{foo}/) and this allows you to easily substitute user
input without using the longish Regexp.escape() which would be forgotten
way to often and thus cause security risks anyway.

The warning will go away in 1.9.0, AFAIK. I'd suggest either using
/#{Regexp.escape(foo)}/ or disabling the warnings via the
-W0-command-line-option or $-w = nil for now.

Regards,
Florian Gross
 
M

Martin DeMello

Elias Athanasopoulos said:
I had this "problem", too. I can't see why Ruby is so verbose on that
and doesn't interpret foo.gsub[!]("bar", ...) as foo.gsub[!](/bar/, ...)
automagically...

Well, for one, I think more people would expect it to be interpreted as
foo.gsub(Regexp.quote(bar), ...)

martin
 
A

Alexander Kellett

Elias Athanasopoulos said:
I had this "problem", too. I can't see why Ruby is so verbose on that
and doesn't interpret foo.gsub[!]("bar", ...) as foo.gsub[!](/bar/, ...)
automagically...

Well, for one, I think more people would expect it to be interpreted as
foo.gsub(Regexp.quote(bar), ...)

/me nods
i use this same paradigm frequently.
its a bit icky for such a common action.

Alex
 
A

Alexander Kellett

Elias Athanasopoulos said:
I had this "problem", too. I can't see why Ruby is so verbose on that
and doesn't interpret foo.gsub[!]("bar", ...) as foo.gsub[!](/bar/, ...)
automagically...

Well, for one, I think more people would expect it to be interpreted as
foo.gsub(Regexp.quote(bar), ...)

/me nods
i use this same paradigm frequently.
its a bit icky for such a common action.

Alex
 
J

John W. Long

Alexander said:
/me nods
i use this same paradigm frequently.
its a bit icky for such a common action.
how about:

foo.gsub!(/#{bar}/, ...)

fairly concise.
 
M

Mauricio Fernández

how about:

foo.gsub!(/#{bar}/, ...)

fairly concise.
=> nil

--
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

* JHM wonders what Joey did to earn "I'd just like to say, for the record,
that Joey rules."
-- Seen on #Debian
 
J

James F. Hranicky

I had this "problem", too. I can't see why Ruby is so verbose on that
and doesn't interpret foo.gsub[!]("bar", ...) as foo.gsub[!](/bar/, ...)
automagically...

The main reason I like this

line.match('/usr/local/lib/blah/blah/blah')

is so I don't have to escape forward slashes:

line.match(/\/usr\/local\/lib\/blah\/blah/)

I suppose writing this

line.match(Regexp.new("/usr/local/lib/blah/blah/blah"))

works, though a touch less elegant. No biggie, though. Perhaps there's a
better way than that?

Jim
 
T

ts

J> line.match(/\/usr\/local\/lib\/blah\/blah/)

svg% ruby -e 'p %r"/usr/local/lib/blah/blah/blah"'
/\/usr\/local\/lib\/blah\/blah\/blah/
svg%


Guy Decoux
 
J

Jamis Buck

James said:
The main reason I like this

line.match('/usr/local/lib/blah/blah/blah')

is so I don't have to escape forward slashes:

line.match(/\/usr\/local\/lib\/blah\/blah/)

I suppose writing this

line.match(Regexp.new("/usr/local/lib/blah/blah/blah"))

works, though a touch less elegant. No biggie, though. Perhaps there's a
better way than that?

Jim

You can use %r, and then specify your own delimiter:

line.match( %r|/usr/local/lib/blah/blah| )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top