Cannot return negative value?

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…

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.

Josselin wrote:

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

On 15/01/07, Peter S. [email protected] wrote:

?

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

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

On 15/01/07, Josselin [email protected] wrote:

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

same problem…

This seems to work:

return userCredentials.flagged? ? -1 : 1

Farrel

On 2007-01-15 12:43:21 +0100, Peter S. [email protected]
said:

?

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… ;-))

On 2007-01-15 12:41:09 +0100, “Farrel L.” [email protected]
said:

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

same problem…

This seems to work:

return userCredentials.flagged? ? -1 : 1

Farrel

hanks a lot first time I was using this kind of return… ;-))

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs