[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

cannot return negative value ?

Josselin

1/15/2007 11:29:00 AM

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

7 Answers

Farrel Lifson

1/15/2007 11:41:00 AM

0

On 15/01/07, Josselin <josselin@wanadoo.fr> wrote:
> 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

Peter Szinek

1/15/2007 11:43:00 AM

0

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.rubyra...


Josselin

1/15/2007 11:51:00 AM

0

On 2007-01-15 12:43:21 +0100, Peter Szinek <peter@rubyrailways.com> said:

> 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.rubyra...

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

Josselin

1/15/2007 11:51:00 AM

0

On 2007-01-15 12:41:09 +0100, "Farrel Lifson" <farrel.lifson@gmail.com> said:

> On 15/01/07, Josselin <josselin@wanadoo.fr> wrote:
>> 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

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


Farrel Lifson

1/15/2007 11:57:00 AM

0

On 15/01/07, Peter Szinek <peter@rubyrailways.com> wrote:
> 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

This seems to work though

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

Farrel

Bertram Scharpf

1/15/2007 12:08:00 PM

0

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


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

Nobuyoshi Nakada

1/15/2007 4:16:00 PM

0

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.

--
Nobu Nakada