Simplify test for divisibility by all numbers 1…20 def divisible?(n)
  if n % 1 == 0 &amp;&amp;
    n % 2 == 0 &amp;&amp;
    n % 3 == 0 &amp;&amp;
    n % 4 == 0 &amp;&amp;
    n % 5 == 0 &amp;&amp;
    n % 6 == 0 &amp;&amp;
    n % 7 == 0 &amp;&amp;
    n % 8 == 0 &amp;&amp;
    n % 9 == 0 &amp;&amp;
    n % 10 == 0 &amp;&amp;
    n % 11 == 0 &amp;&amp;
    n % 12 == 0 &amp;&amp;
    n % 13 == 0 &amp;&amp;
    n % 14 == 0 &amp;&amp;
    n % 15 == 0 &amp;&amp;
    n % 16 == 0 &amp;&amp;
    n % 17 == 0 &amp;&amp;
    n % 18 == 0 &amp;&amp;
    n % 19 == 0 &amp;&amp;
    n % 20 == 0
    return true
  else 
    return false
  end
end
Ruby refactor: use Enumerable.all?:

def divisible?(n)
  (1..20).all? { |x| n % x == 0 }
end


Mathematical refactor:calculate the least common multiple of the integers in the range (Integer#lcm is available from Ruby 1.9):

def divisible?(n)
  n % (1..20).reduce(:lcm) == 0
end


This second snippet is, of course, more efficient once you pre-calculate (1..20).reduce(:lcm) only once and store it somewhere.