If the results is nil then I get NoMethodError - undefined method 'length' for nil:NilClass:
Is there any way I don’t have to use two conditions? I thought that ruby won’t evaluate the second part of the condition in case results is empty because the condition can be never true.
if (not results.empty? && results[-1].length == 2)
(4-results[-1].length).times {|i| results[-1] << ""}
end
In ruby the
notoperator has lower precedence than&&so your code is being interpreted asYou probably want to use the ! operator instead which does the same as
notbut has higher precedence.