Ruby Warnings

C

Chris Pine

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?
 
Y

Yukihiro Matsumoto

Hi,

In message "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?

'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.
 
M

Mauricio Fernández

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.

This case is a bit unfortunate:

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

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

oh okay. my mistake.

Yafcot:atj(*),

mark

* Yet another fool coming over this: according to joey
-- (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top