Ask a Question related to Ruby, Design and Development.
-
Hal E. Fulton #1
Star in case statements
I just noticed something that I either didn't know
or just forgot. :)
You can use the *array notation to specify values
for the when clause in a case statement:
list1 = [1,2,6,8,9]
list2 = [3,4,5,7,10]
case item
when *list1
puts "in list 1"
when *list2
puts "in list 2"
end
Cool, eh?
Hal
--
Hal Fulton
[email]hal9000@hypermetrics.com[/email]
Hal E. Fulton Guest
-
M.I'5.Pe rsecution - how a nd wh y di d it star t?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -= how and why did. it start? -= -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The harassment didn't start by itself,. so... -
M-I 5`Persecutio n - h ow and w hy di d it star t?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -= how and why. did it start? -= -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The harassment didn't start by itself, so... -
M`I'5-Per secution . ho w a nd w hy did it star t?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -= how and. why did it start? -= -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The harassment didn't start by itself, so... -
Problem with Star Wars 3 DVD
Hi all, i've buy the star wars DVD and to play it he run macromedia projector,but after when i do "play movie" .... nothing. the movie don't start... -
#23026 [Com]: Make Zend case-sensitive (classes, functions, remove case-insensitive)
ID: 23026 Comment by: nvivo at mandic dot com dot br Reported By: mfischer@php.net Status: Open Bug Type: ... -
Martin DeMello #2
Re: Star in case statements
Hal E. Fulton <hal9000@hypermetrics.com> wrote:
Very neat! I was gratified when I first discovered you could splat a> I just noticed something that I either didn't know
> or just forgot. :)
>
> You can use the *array notation to specify values
> for the when clause in a case statement:
range too (as in a = *(1..10)).
martin
Martin DeMello Guest
-
Martin DeMello #3
Re: Star in case statements
Dave Brown <dagbrown@lart.ca> wrote:
*(1..10) doesn't expand to [1,2,3,4,5,6,7,8,9,10], it expands to>
> This is weird though:
>
> irb(main):001:0> *(1..10)
> SyntaxError: compile error
> (irb):1: syntax error
> from (irb):1
> irb(main):002:0> a=*(1..10)
> => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> irb(main):003:0>
>
> I wonder why that does that.
1,2,3,4,5,6,7,8,9,10. a = 1,2,3,4,5,6,7,8,9,10 does the right thing (see
the multiple assignment section of the pickaxe book). [*(1..10)] works
too.
martin
Martin DeMello Guest



Reply With Quote

