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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 28, 11:44 am, Ale Ds <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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) >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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On May 28, 11:44�am, Ale Ds <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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. > > FredI will carefully use ''and'' next time, or maybe I will use only && :) After your reply, I''ve found this http://www.themomorohoax.com/2008/12/08/and-vs-amperand-in-ruby Thank you very much ! Alessandro DS -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.