Forum: Ruby on Rails question about case statement

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F0cb673a145d7630718c4729297f60df?d=identicon&s=25 Pesho Petrov (pesho318i)
on 2009-05-20 16:57
hello,

i'd like to combine to clauses of my case statement, and I do this:

case check
when value1
   //do something
when value2
   //do something (the same as in the first when)
end


But how can I combine the two "when"-s. It is redundant to write the
same code to "do something"

I tried to find the syntax, but couldn't.
I tried something like:

case check
when value1
when value2
   //do the thing
end

but this only works when check = value2


Thanks!
675475d0b65710be6d992eb5eb2c61c2?d=identicon&s=25 Gregory Seidman (Guest)
on 2009-05-20 17:03
(Received via mailing list)
On Wed, May 20, 2009 at 04:57:08PM +0200, Pesho Petrov wrote:
> end
>
>
> But how can I combine the two "when"-s. It is redundant to write the
> same code to "do something"
[...]

case check
when value1, value2
   //do something
end

> Thanks!
--Greg
F0cb673a145d7630718c4729297f60df?d=identicon&s=25 Pesho Petrov (pesho318i)
on 2009-05-20 18:57
Thanks, Greg!
This topic is locked and can not be replied to.