Skip to content

Instantly share code, notes, and snippets.

@alh13
Created October 14, 2012 15:01
Show Gist options
  • Save alh13/3888844 to your computer and use it in GitHub Desktop.
Save alh13/3888844 to your computer and use it in GitHub Desktop.
Enable TC-Optimization in Ruby
# https://speakerdeck.com/u/jeg2/p/10-things-you-didnt-know-ruby-could-do
RubyVM::InstructionSequence.compile_option = { :tailcall_optimization => true,
:trace_instruction => false }
eval <<end
def factorial(n, result = 1)
if n == 1
result
else
factorial(n - 1, n * result)
end
end
end
p factorial(30_000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment