Jump to first non-false expression

Tags:

Ruby Idioms의 내용을 응용해서, x값이 even인지 odd인지 출력하는 루비 코드를 작성해봤습니다.

x = 2
puts case
when x % 2 == 0; "even"
when x % 2 == 1; "odd"
end

재밌군요. case뒤에 아무것도 없어도 된다는 것.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *