Ruby's Spaceship Operator and Switch Statement (Case)

From SnOwy - Ed's Wiki Notebook

Jump to: navigation, search

I still love Ruby's spaceship operator.


case x <=> y

when -1

puts "x less than y"

when 0

puts "x equal to y"

when 1

puts "x greater than y"

else

puts "x, y not comparable"

end

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox