[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

something strange about assignement

pere.noel

7/26/2006 9:45:00 AM

if i do an assignment like :

valid_path=valid_string and (/^\/.*$/ === s)

s being = to "path not starting with /" (invalid path)*

i get valid_path= true iff alid_string=true

the test "" doesn't take into account, why ???

because i've changed slightly the syntax to :

valid_path=(valid_string and (/^\/.*$/ === s))

(an enclosing parentheses couple more)

and then, rubically, i get the good result ;-)

any reason for such a behaviour ???
--
une bévue
2 Answers

Vincent Fourmond

7/26/2006 10:02:00 AM

0


Hello !

>
> valid_path=valid_string and (/^\/.*$/ === s)
>
> s being = to "path not starting with /" (invalid path)*
>
> i get valid_path= true iff alid_string=true
>
> the test "" doesn't take into account, why ???
>
> because i've changed slightly the syntax to :
>
> valid_path=(valid_string and (/^\/.*$/ === s))
>
> (an enclosing parentheses couple more)
>
> and then, rubically, i get the good result ;-)
>
> any reason for such a behaviour ???

and has got a much lower priority than anything else (including the
assignement), so that your first statement is interpreted as

(valid_path=valid_string) and (/^\/.*$/ === s)

You wouldn't get this problem with the && operator -- and as you did
if you parenthize correctly.

Enjoy

Vince

pere.noel

7/26/2006 2:48:00 PM

0

Vincent Fourmond <vincent.fourmond@9online.fr> wrote:

> and has got a much lower priority than anything else (including the
> assignement), so that your first statement is interpreted as

i didn't know that point ))

> (valid_path=valid_string) and (/^\/.*$/ === s)
>
> You wouldn't get this problem with the && operator -- and as you did
> if you parenthize correctly.

ok, thanks !

--
une bévue