I have a ruby hash like { :user_id => nil }
.
I print out:
puts params.key? :user_id
puts params[:user_id].nil?
puts params.key? :user_id && params[:user_id].nil?
The output is:
true
true
false
How come && chaning of 2 true results return false?
CodePudding user response:
sometimes you need parantheses
puts params.key? :user_id && params[:user_id].nil?
it's like
puts params.key?(:user_id && params[:user_id].nil?)
try
puts params.key?(:user_id) && params[:user_id].nil?