What I was originally trying to do was use a CASE structure, but I couldn't figure out how to use multiple comparisons. That is, I tried something like this:
----
case array[ position ]
when 'foo' then start_col = 1
when 'green eggs' then start_col = 10
when 'ham' then start_col = 20
when 'bar', first_seen then start_col = 30; first_seen = false
when 'bar', ! first_seen then start_col = 40
end
----
But this doesn't work. Rereading the Programming Ruby 2nd edition several times, I eventually got it that the (multiple) comparisons are only applied to the original "array[ position ]" object at the top. Ah.
So I had to turn it into a series of "if" checks. Not as pretty to look at as the above might be (if it actually worked), but I'm happy that I just got it working. Not being a programmer by trade, I like to try new structures every now and then to see if I can simplify what I'm trying to do. Practice makes perfect, eh?
Cheers. Paul C.
On 29/10/06, Bret Pettichord <[EMAIL PROTECTED]> wrote:
This will do the same thing, somewhat more simply.
first_seen = true
array.each do |element|
...
if element == 'bar'
if first_seen
start_col = 30
first_seen = false
else
start_col = 40
end
end
...
end
_______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
