strange behaviour in 'and' with params

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

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

Frederick Cheung wrote: