# Something strange about assignement

**URL:** <https://www.ruby-forum.com/t/something-strange-about-assignement/99962>\
**Category:** Ruby\
**Created:** [July 26, 2006, 11:51am UTC](https://www.ruby-forum.com/t/something-strange-about-assignement/99962 "2006-07-26T11:51:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 26, 2006, 11:51am UTC](https://www.ruby-forum.com/t/something-strange-about-assignement/99962/1 "2006-07-26T11:51:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 26, 2006, 12:04pm UTC](https://www.ruby-forum.com/t/something-strange-about-assignement/99962/2 "2006-07-26T12:04:15Z")

</div>

Hello !

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 26, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/something-strange-about-assignement/99962/3 "2006-07-26T16:51:41Z")

</div>

Vincent F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 !
