I always meet this Ruby problem, I want to write it more cleanly.
var a can be nil
a.value can also be nil
a.value has possible true or false value
if (not a.nil?) && (not a.value.nil?) && a.value == false
puts "a value is not available"
else
puts "a value is true"
end
The problem is that the conditional statement is too clumsy and hard to read.
How can I improve the checking nil and false conditional statement?
Thanks, I am a Ruby newbie
a.valuebeingnilwould raise an error, then why do you put that in the condition? It does not make sense because the error would be raised anyway.ais nil, not ifa.valueis nil.ais a class andvalueis not defined.