GCD of two numbers in Ruby I am trying to implement a algorithm for the GCD of two numbers in a functional approach. Can this be improved further, also with regards to performance?

def gcd(a, b)
   return b if a ==0
   return a if b == 0
   return b if (a%b == 0)
   return a if (b%a == 0)
  (a &gt; b)? gcd(a, a%b) : gcd(b%a, b)
end
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.