cannot return negative value ?

J

Josselin

I got the following error :

parse error, unexpected tUMINUS_NUM

userCredential.flagged? ? return -1 : return 1

what's wrong ?

I tried also

userCredential.flagged? ? return (-1) : return 1

same problem.....
 
F

Farrel Lifson

I got the following error :

parse error, unexpected tUMINUS_NUM

userCredential.flagged? ? return -1 : return 1

what's wrong ?

I tried also

userCredential.flagged? ? return (-1) : return 1

same problem.....

This seems to work:

return userCredentials.flagged? ? -1 : 1

Farrel
 
P

Peter Szinek

Josselin said:
I got the following error :

parse error, unexpected tUMINUS_NUM

userCredential.flagged? ? return -1 : return 1
You mean

return userCredential.flagged? -1 : 1

?

I am not sure in Ruby, but if it's the same than in C or anywhere else,
the ternary operator evaluates to a value, and you can not really
execute things like this inside...

Cheers,
Peter

__
http://www.rubyrailways,com
 
J

Josselin

You mean

return userCredential.flagged? -1 : 1

?

I am not sure in Ruby, but if it's the same than in C or anywhere else,
the ternary operator evaluates to a value, and you can not really
execute things like this inside...

Cheers,
Peter

__
http://www.rubyrailways,com

thanks a lot first time I was using this kind of return... ;-))
 
F

Farrel Lifson

You mean

return userCredential.flagged? -1 : 1

?

I am not sure in Ruby, but if it's the same than in C or anywhere else,
the ternary operator evaluates to a value, and you can not really
execute things like this inside...

Cheers,
Peter

This seems to work though

userCredentials.flagged? ? (return -1) : (return 1)

Farrel
 
B

Bertram Scharpf

Hi,

Am Montag, 15. Jan 2007, 20:30:08 +0900 schrieb Josselin:
I got the following error :

parse error, unexpected tUMINUS_NUM

userCredential.flagged? ? return -1 : return 1

what's wrong ?

when saying

userCredential.flagged? ? (return -1) : (return 1)

or even

userCredential.flagged? ? begin return -1 end : begin return 1 end

you will probably see that the return statement is definitely in the
wrong place.

Bertram
 
N

Nobuyoshi Nakada

Hi,

At Mon, 15 Jan 2007 20:30:08 +0900,
Josselin wrote in [ruby-talk:234078]:
I got the following error :

parse error, unexpected tUMINUS_NUM

userCredential.flagged? ? return -1 : return 1

what's wrong ?

Because `return' is a statement. In Ruby, a "statement" is
defined as an expression which has lower precedence and can't
appear directly in another expression.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,085
Latest member
cryptooseoagencies

Latest Threads

Top