From: Caleb Clausen Date: 2008-09-25T03:56:03+09:00 Subject: [ruby-core:18865] Re: tokenizing regular expressions when passed as method params Seth Dillingham wrote: > If the method call is parenthesized, there's no problem: > > foo.bar( /regex/, bat ) > > If the regular expression is not the first parameter, there's no problem: > > foo.bar bat, /regex/ > > However, if there are no parentheses and the regular expression is the > first parameter, there is definitely a problem: > > foo.bar /regex/, bat > > I can't figure out how to tell if that '/' is dividing foo.bar by > whatever comes next, or if it's a regular expression. Cases like this are mostly resolved by what I call the before but not after rule. If there is whitespace before, but not after the ambiguous character(s), (and a method call before the whitespace), then the ambiguous character(s) are considered to start a value (in this case a regex) rather than an operator. in short: foo/bar #operator foo /bar/ #regexp foo/ bar #operator foo / bar #operator I inferred this rule by playing around in irb; (unlike Ryan I am incapable of understanding the output of 'ruby -y'), so there may be more to it than that... in fact there seems to be an exception, which I posted about relatively recently (see [ruby-core:18555]). (I'm unhappy about this exception, as it makes no sense to me. But I got no replies, so maybe no-one else cares.)