Skip to content

Instantly share code, notes, and snippets.

/a.rb Secret

Created October 11, 2012 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1b2ebb80e514196dd90d to your computer and use it in GitHub Desktop.
Save anonymous/1b2ebb80e514196dd90d to your computer and use it in GitHub Desktop.
define :factorial, :i => Integer do
if i < 1 then 1 else i * factorial(i - 1) end
end
# => #<Proc:0x00000001aaee10@type_assurance.rb:2 (lambda)>
factorial 5
# => 120
factorial 5.4
# => #<RuntimeError: Error, expected Integer as argument for i in factorial>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment