As to the style:

You seem to be coming from a language like Java or so. Note that Ruby 
does *not* have a "do-until" or a "do-while" loop. You have to use an 
endless loop with a conditional "break" at the end.

This "begin-end-until" actually looks like a "do-until" loop, but it's 
not. It's just the same as "until ... do ... end". I'd actually avoid 
this notion completely, because it's very ambiguous and hard to read. 
Use the appended "until", "while", "if" etc. only for single line 
statements.

Ruby obviously does have a "for-in" loop, but I'd avoid that, too. It's 
cumbersome, it doesn't introduce a new scope (loop variables are visible 
from the outside), and it's not very "Rubyish". Use "each" instead.

You generally use a very low level programming style with lots of loops 
and manually filling arrays. Of course, you can do that in Ruby. But 
Ruby also allows you to use a more highlevel approach with methods like 
"select", "reject", "map" etc.

For example, if you want to select all even numbers between 1 and 100, 
you can do that by writing

even_numbers = []
for i in 1..100
  if i % 2 == 0
    even_numbers << i
  end
end

This translates directly to Java code. But in Ruby you'd rather use the 
"select" method and let the computer do all the lowlevel stuff 
(initializing an array, looping over the numbers and checking for the 
condition):

even_numbers = (1..100).select {|i| i.even?}

or shorter

even_numbers = (1..100).select &:even?

As you can see, this is much more readable. Of course, you won't always 
find a suitable method for your specific problem.

But I think you should generally get away from this lowlevel procedural 
style and think in more highlevel terms like "selecting", "combining" 
etc.

This should lead to more compact and better readable code.

-- 
Posted via http://www.ruby-forum.com/.