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
It is because you put return num within a ternary operator construction. Precedence rule does not parse it as you wanted. Remove return, and it will not raise an error (although it will not work as you want to; nil will be returned when num is nil). Or, if you want to use return only when the condition is satisfied, then you should do (return num).
But for your purpose, a better code is:
num.to_a.sort