Complete the code to compare two numbers using the spaceship operator.
result = 5 [1] 3
The spaceship operator <=> compares two values and returns -1, 0, or 1.
Complete the code to compare two strings alphabetically using the spaceship operator.
result = 'apple' [1] 'banana'
The spaceship operator compares strings lexicographically and returns -1, 0, or 1.
Fix the error in the code by replacing the incorrect operator with the spaceship operator.
result = 10 [1] 10
The spaceship operator <=> correctly compares two values and returns 0 when they are equal.
Fill both blanks to create a hash that maps numbers to their comparison results with 7 using the spaceship operator.
comparisons = Hash[[5, 7, 9].map { |num| [num, num [1] 7] if num [2] 7 }.compact]
The first blank uses the spaceship operator to compare num with 7. The second blank filters numbers greater than 7.
Fill all three blanks to create a hash that maps words to their length comparison with 4 using the spaceship operator and a condition.
result = Hash[['cat', 'house', 'dog'].map { |word| [word, word.length [1] 4] if word.length [2] 4 and word [3] 'dog' }.compact]
The first blank uses the spaceship operator to compare lengths. The second blank filters words longer than 4. The third blank excludes the word 'dog'.