case statement

S

Shai Rosenfeld

a = [1,2,3,4]
result = case
when a.include?(1): 'this is what i want'
when a.include?(11): 'not result'
when a.include?(15): 'no good'
end


ahhhhhhhhhhhhhhhh
perfect.

thanks.
 
D

dblack

Hi --

a = [1,2,3,4]
result = case
when a.include?(1): 'this is what i want'
when a.include?(11): 'not result'
when a.include?(15): 'no good'
end


ahhhhhhhhhhhhhhhh
perfect.

I'm curious about the fall-through case. If the array does not
include 1, 11, or 15, then result will be nil, which I assume is
equivalent to a "no good" result. That makes me wonder whether a
simple include? would work equally well. Or is there more to the
various error conditions?


David

--
* Books:
RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
& consulting: Ruby Power and Light, LLC (http://www.rubypal.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top