GCD of two numbers in Ruby
It does not matter whether a &gt; b or b &gt; a, two cases should be enough for positive integers:

def gcd(a, b)
  b == 0 ? a : gcd(b, a.modulo(b))
end


Check also Integer#gcd.