开发者

What triggers the Ruby warning about ambiguous first argument?

开发者 https://www.devze.com 2023-02-15 11:47 出处:网络
In Ruby 1.9.1, if you do $VERBOSE = true puts /m/ , 42.to_s or i开发者_StackOverflowf I do $VERBOSE = true

In Ruby 1.9.1, if you do

$VERBOSE = true
puts /m/ , 42.to_s

or i开发者_StackOverflowf I do

$VERBOSE = true
puts /m/ , "42"

You get the warning

warning: ambiguous first argument; put parentheses or even spaces

But I don't get it if I do

$VERBOSE = true
puts "m" , 42.to_s

or

$VERBOSE = true
puts(/m/, 42.to_s)

So what specifically triggers this warning? And what more spaces could I have added to the original expression?


The "problem" is that / could signify division or a regular expression. The message is generic; the parser doesn't necessarily mean that spaces would have helped a given specific expression.

0

精彩评论

暂无评论...
验证码 换一张
取 消