Yukihiro - Please ensure backwards compatibility

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

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.

-austin

···

On Thu, 18 Dec 2003 11:01:56 +0900, Joseph Benik wrote:

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


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.12.17
* 22.39.07

Joseph Benik wrote:

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

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,

···

On Thu, Dec 18, 2003 at 12:39:53PM +0900, Austin Ziegler wrote:

On Thu, 18 Dec 2003 11:01:56 +0900, Joseph Benik wrote:

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

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.


University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky

^^^^^^^^^^^^^
^^^^^^^^^^^^^

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

···

On Fri, 19 Dec 2003, Elias Athanasopoulos wrote:

Date: Fri, 19 Dec 2003 03:12:57 +0900
From: Elias Athanasopoulos elathan@phys.uoa.gr
Newsgroups: comp.lang.ruby
Subject: Re: Yukihiro - Please ensure backwards compatibility

On Thu, Dec 18, 2003 at 12:39:53PM +0900, Austin Ziegler wrote:

On Thu, 18 Dec 2003 11:01:56 +0900, Joseph Benik wrote:

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

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…

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 :: Solar-Terrestrial Physics Data | NCEI
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’
===============================================================================

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

martin

···

Elias Athanasopoulos elathan@phys.uoa.gr wrote:

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

···

On Fri, 19 Dec 2003 03:12:57 +0900 Elias Athanasopoulos elathan@phys.uoa.gr wrote:

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…

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

Alex

···

On Sat, Dec 20, 2003 at 10:31:53PM +0900, Martin DeMello wrote:

Elias Athanasopoulos elathan@phys.uoa.gr wrote:

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

···

On Sat, Dec 20, 2003 at 10:31:53PM +0900, Martin DeMello wrote:

Elias Athanasopoulos elathan@phys.uoa.gr wrote:

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), …)

  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

James F. Hranicky wrote:

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| )

···


Jamis Buck
jgb3@email.byu.edu

ruby -h | ruby -e ‘a=;readlines.join.scan(/-(.)[e|Kk(\S*)|le.l(…)e|#!(\S*)/) {|r| a << r.compact.first };puts “\n>#{a.join(%q/ /)}<\n\n”’

Alexander Kellett wrote:

···

On Sat, Dec 20, 2003 at 10:31:53PM +0900, Martin DeMello wrote:

Elias Athanasopoulos elathan@phys.uoa.gr wrote:

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.

how about:

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

fairly concise.


John Long
contact: http://wiseheartdesign.com

Works for me – thanks, guys.

Jim

···

On Wed, 24 Dec 2003 01:14:09 +0900 Jamis Buck jgb3@email.byu.edu wrote:

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

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

Alexander Kellett wrote:

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.

how about:

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

fairly concise.

bar = “.”
=> “.”
/#{bar}/.match “a”
=> #MatchData:0x401f7d90
/#{Regexp.escape(bar)}/.match “a”
=> nil

···

On Tue, Dec 23, 2003 at 12:55:52AM +0900, John W. Long wrote:

On Sat, Dec 20, 2003 at 10:31:53PM +0900, Martin DeMello wrote:

Elias Athanasopoulos elathan@phys.uoa.gr wrote:


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
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