1

I wrote a case expression like

case x
when "one" "I"
when "two" "II"
end

It does not cause a syntax error, and always returns nil regardless of the value of x. I think it should cause a syntax error, but the reality is not the case. Why?

sawa
  • 165,429
  • 45
  • 277
  • 381
anqooqie
  • 435
  • 3
  • 17

1 Answers1

4

The white-space separated string literals get concatenated (see this post). That turns your when statements into legitimate potential matches with no action to be performed, which is why you always get nil.

Community
  • 1
  • 1
pjs
  • 18,696
  • 4
  • 27
  • 56