Skip to content

Instantly share code, notes, and snippets.

@edipofederle
Created January 1, 2011 14:38
Show Gist options
  • Select an option

  • Save edipofederle/761782 to your computer and use it in GitHub Desktop.

Select an option

Save edipofederle/761782 to your computer and use it in GitHub Desktop.
def fatorial(n)
raise TypeError, "Valor invalido, somente inteiros positivos" unless n.is_a? Integer
raise ArgumentError, "Esperava um argumento >= 1. Mas retornou #{n}", caller if n < 1
return 1 if n == 1
n * fatorial(n-1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment