[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

simple question re: ruby warning message

Tom Cloyd

2/19/2009 8:59:00 AM

I just set up my first ternary operator expression, and got a warning
from Ruby, as a reward! I don't see what the problem might be:

The expression:
db_type= 'n' ? db = @nodes_h : db = @links_h

The warning:
../lib/setnet/SN.rb:781: warning: string literal in condition

I use string literals all the time in case statements, and other places,
and have never had this objection.

Can someone explain the problem to me? I cannot imagine what it might be.

Thanks!

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


6 Answers

Peña, Botp

2/19/2009 9:04:00 AM

0

From: Tom Cloyd [mailto:tomcloyd@comcast.net]=20
# db_type=3D 'n' ? db =3D @nodes_h : db =3D @links_h

^^^

try replacing =3D with =3D=3D





Stefano Crocco

2/19/2009 9:04:00 AM

0

Alle Thursday 19 February 2009, Tom Cloyd ha scritto:
> I just set up my first ternary operator expression, and got a warning
> from Ruby, as a reward! I don't see what the problem might be:
>
> The expression:
> db_type= 'n' ? db = @nodes_h : db = @links_h
>
> The warning:
> ../lib/setnet/SN.rb:781: warning: string literal in condition
>
> I use string literals all the time in case statements, and other places,
> and have never had this objection.
>
> Can someone explain the problem to me? I cannot imagine what it might be.
>
> Thanks!
>
> t.

Ruby thinks you are likely to have written = instead of == in the condition.

Stefano


Tom Cloyd

2/19/2009 9:08:00 AM

0

Stefano Crocco wrote:
> Alle Thursday 19 February 2009, Tom Cloyd ha scritto:
>
>> I just set up my first ternary operator expression, and got a warning
>> from Ruby, as a reward! I don't see what the problem might be:
>>
>> The expression:
>> db_type= 'n' ? db = @nodes_h : db = @links_h
>>
>> The warning:
>> ../lib/setnet/SN.rb:781: warning: string literal in condition
>>
>> I use string literals all the time in case statements, and other places,
>> and have never had this objection.
>>
>> Can someone explain the problem to me? I cannot imagine what it might be.
>>
>> Thanks!
>>
>> t.
>>
>
> Ruby thinks you are likely to have written = instead of == in the condition.
>
> Stefano
>
>
>
>
Geee, I wonder why? Good Lord!

A real newbie mistake!

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Peña, Botp

2/19/2009 9:10:00 AM

0

From: Pe=F1a, Botp [mailto:botp@delmonte-phil.com]=20
#=20
# From: Tom Cloyd [mailto:tomcloyd@comcast.net]=20
# # db_type=3D 'n' ? db =3D @nodes_h : db =3D @links_h
#=20
# ^^^
#=20
# try replacing =3D with =3D=3D
#=20

or maybe better do some arrangement, like eg,

db =3D db_type=3D=3D'n' ? @nodes_h : @links_h

and wc clearly shows diff bw =3D and =3D=3D



=20

vimal

2/19/2009 9:16:00 AM

0

On Feb 19, 1:59 pm, Tom Cloyd <tomcl...@comcast.net> wrote:
> I just set up my first ternary operator expression, and got a warning
> from Ruby, as a reward! I don't see what the problem might be:
>
> The expression:
> db_type= 'n' ? db = @nodes_h : db = @links_h

I guess your representation (db_type= 'n')
doesn't look like a condition, its like performing an assignment.

If its a condition it should be db_type == 'n'

Your representation (db_type= 'n' ? db = @nodes_h : db = @links_h)

assigns db_type the result of the following:

checks a condition 'n'
if true
db = @nodes_h
else
db = @links_h
end

Regards,
Vimal Das

Rick DeNatale

2/19/2009 5:19:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Thu, Feb 19, 2009 at 4:19 AM, vimal <cool.vimalsmail@gmail.com> wrote:

>
> Your representation (db_type= 'n' ? db = @nodes_h : db = @links_h)
>
> assigns db_type the result of the following:
>
> checks a condition 'n'
> if true
> db = @nodes_h
> else
> db = @links_h
> end
>

Which, since any ruby object except nil and false is truthy is effectively
the same thing as

db_type = db = @nodes.h

which makes db_type, and db reference the same object, which is the return
valud of @nodes.h

--
Rick DeNatale

Blog: http://talklikeaduck.denh...
Twitter: http://twitter.com/Ri...
WWR: http://www.workingwithrails.com/person/9021-ric...
LinkedIn: http://www.linkedin.com/in/ri...