Skip to content

Instantly share code, notes, and snippets.

@franzejr
Created December 27, 2015 01:33
Show Gist options
  • Save franzejr/97a0842eb11a83a05481 to your computer and use it in GitHub Desktop.
Save franzejr/97a0842eb11a83a05481 to your computer and use it in GitHub Desktop.
Tail Call Optimization in Ruby
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment