I would like to test a string foo against an array bar in as case...
when clause and would like to know the best way to do this. I am sure
why_ did something neat with an * operator, but can't find any
reference. I could do it long hand, but that just aint rubyish.
e.g.
foo = "that"
bar = %(this that other)
case foo
when (some clever way of test for foo in the array bar)
.
.
else
I would like to test a string foo against an array bar in as case...
when clause and would like to know the best way to do this. I am sure
why_ did something neat with an * operator, but can't find any
reference. I could do it long hand, but that just aint rubyish.
e.g.
foo = "that"
bar = %(this that other)
You don't have an array in bar, just a string. You need to use %w:
bar = %w(this that other)
case foo
when (some clever way of test for foo in the array bar)
On 10/11/06, J2M <james2mccarthy@gmail.com> wrote:
Hi,
I would like to test a string foo against an array bar in as case...
when clause and would like to know the best way to do this. I am sure
why_ did something neat with an * operator, but can't find any
reference. I could do it long hand, but that just aint rubyish.
e.g.
foo = "that"
bar = %(this that other)
case foo
when (some clever way of test for foo in the array bar)
.
else
The semantics are different. Your approach may be valid in some cases,
I'm not discounting it altogether, but the two approaches do yield
different results in the edge cases.
Jacob Fugal
···
On 10/11/06, Drew Olson <olsonas@gmail.com> wrote:
If you just want to check if the array contains that string somewhere,
can you just use: