Ruby Warnings

I have been getting complaints that the code in my tutorial generates
warnings (just in chapter 5). So, I’m looking into it, and I notice the
following:

irb(main):001:0> puts 'hello '.+ ‘world’
(irb):1: warning: parenthesize argument(s) for future version
hello world
=> nil
irb(main):002:0> puts 'hello ’ + 'world’
hello world
=> nil

So why the warning? It’s a shame, because the code won’t be nearly as
readable for newcomers to Ruby, littered as it will have to be with
parenthases.

Also, can we stop switching from “syntax error” to “parse error” and back?

Chris

PS: I tried sending this to the ML instead of the newsgroup, and nothing
happened. Not even a message telling me “no, thank you, chris”. What’s up?

Hi,

I have been getting complaints that the code in my tutorial generates
warnings (just in chapter 5). So, I’m looking into it, and I notice the
following:

irb(main):001:0> puts 'hello '.+ ‘world’
(irb):1: warning: parenthesize argument(s) for future version
hello world
=> nil
irb(main):002:0> puts 'hello ’ + ‘world’
hello world
=> nil

So why the warning?

'hello '.+ ‘world’

is a form of “recv.message arg”, i.e. parentheses around argument are
omitted apparently, and the expression itself is an argument to
“puts”. When you use method call as argument, don’t omit parentheses,
no exception.

It’s a shame, because the code won’t be nearly as
readable for newcomers to Ruby, littered as it will have to be with
parenthases.

I think newcomers can easily be confused by a dot before plus.

						matz.
···

In message “Ruby Warnings” on 04/02/12, “Chris Pine” newsgroups@hellotree.com writes:

This case is a bit unfortunate:

def foo(a); a end; puts(foo “a”)
-:1: warning: parenthesize argument(s) for future version

···

On Thu, Feb 12, 2004 at 11:44:15PM +0900, Yukihiro Matsumoto wrote:

So why the warning?

'hello '.+ ‘world’

is a form of “recv.message arg”, i.e. parentheses around argument are
omitted apparently, and the expression itself is an argument to
“puts”. When you use method call as argument, don’t omit parentheses,
no exception.


_ _

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

oh okay. my mistake.

Yafcot:atj(*),

mark