# Strange behaviour in 'and' with params

**URL:** <https://www.ruby-forum.com/t/strange-behaviour-in-and-with-params/189304>\
**Category:** Rails\
**Created:** [May 28, 2010, 12:44pm UTC](https://www.ruby-forum.com/t/strange-behaviour-in-and-with-params/189304 "2010-05-28T12:44:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spitfire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@spitfire](https://www.ruby-forum.com/u/spitfire)\
**Post date:** [May 28, 2010, 12:44pm UTC](https://www.ruby-forum.com/t/strange-behaviour-in-and-with-params/189304/1 "2010-05-28T12:44:16Z")

</div>

I need to convert the user\_param HashWithIndifferentAccess in simple  
Hash (to convert it in YAML)

I noticed a weird behavior:

Why if I use (in a controller):  
user\_params = (params[:user\_param].to\_hash)

user\_params is a Hash  
as I expected

and if I use:

user\_params = (params[:user\_param]) and (params[:user\_param].to\_hash)

user\_params is a HashWithIndifferentAccess ?!?

params[:user\_param] is NOT empty !

I know that “and” should return the second params:  
(1 and 2) return 2

Do someone guess why user\_params is a HashWithIndifferentAccess in this  
instruction: (params[:user\_param]) and (params[:user\_param].to\_hash) ?

thank you,  
Alessandro

---

<div class="post-metadata">

**Author:** ![spitfire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@spitfire](https://www.ruby-forum.com/u/spitfire)\
**Post date:** [May 28, 2010, 2:20pm UTC](https://www.ruby-forum.com/t/strange-behaviour-in-and-with-params/189304/2 "2010-05-28T14:20:13Z")

</div>

On May 28, 11:44 am, Ale Ds [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> and if I use:
> 
> user\_params = (params[:user\_param]) and (params[:user\_param].to\_hash)

and has very low precedence, so ruby actually treats this as

(user\_params = (params[:user\_param])) and  
(params[:user\_param].to\_hash)

&& on the other hand binds more tightly and would do what you expect.

Fred

---

<div class="post-metadata">

**Author:** ![spitfire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@spitfire](https://www.ruby-forum.com/u/spitfire)\
**Post date:** [May 28, 2010, 3:14pm UTC](https://www.ruby-forum.com/t/strange-behaviour-in-and-with-params/189304/3 "2010-05-28T15:14:30Z")

</div>

Frederick C. wrote:

> On May 28, 11:44ï¿½am, Ale Ds [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> …  
> and has very low precedence, so ruby actually treats this as
> 
> (user\_params = (params[:user\_param])) and  
> (params[:user\_param].to\_hash)
> 
> && on the other hand binds more tightly and would do what you expect.
> 
> Fred

I will carefully use ‘and’ next time,  
or maybe I will use only && 🙂

After your reply, I’ve found this

> **[themomorohoax.com](http://ww38.themomorohoax.com/2008/12/08/and-vs-amperand-in-ruby)**
>
> This domain may be for sale!

Thank you very much !  
Alessandro DS
