I am trying to create a condition statement in Ruby. If my array of various numbers is empty or nil, it should return an empty array otherwise it should sort the numbers. Th
To fix your code, change what you have to one of the following:
num.nil? || num.empty? ? [] : num.sort num.nil? ? [] : num.sort (num || []).sort num.to_a.sort
The latter two convert num to an empty array if num is nil, then sort the result. See NilClass.to_a.
num
nil