From: Bertram Scharpf Date: 2009-12-10T21:18:43+09:00 Subject: Re: which is better? Hi, Am Donnerstag, 10. Dez 2009, 18:58:04 +0900 schrieb Robert Klemme: > 2009/12/10 Wybo Dekker : > > > > But why no parentheses?: > > irb > >>> $-w=true > > => true > >>> "abcd1234".gsub! /\d+/,'' > > (irb):13: warning: ambiguous first argument; put parentheses or even spaces > > => "abcd" > >>> "123ab".tr! "0-9","" > > => "ab" > > > > what is the ambiguity in the first case, and why is there no warning in the > > second case? > > Seems to be related to the regexp: > > 10:56:19 $ ruby19 -wce 'o.gsub! /\d/, ""' > -e:1: warning: ambiguous first argument; put parentheses or even spaces > Syntax OK > 10:56:42 $ ruby19 -wce 'o.gsub! "d", ""' > Syntax OK > 10:56:50 $ ruby19 -wce 'o.gsub!(/\d/, "")' > Syntax OK > 10:57:01 $ > > Why? No idea. The slash could also be a division operator. Say: $ ruby -wce 'o.gsub! %r/\d/, ""' $ ruby -wce 'o.gsub! %r{\d}, ""' Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany * Discover String#notempty? at .