Project

General

Profile

Bug #1613 » noclosure.rb

RobertDober (Robert Dober), 06/12/2009 09:20 AM

 
#!/usr/local/bin/ruby -w
# encoding: utf-8
# file: /home/robert/log/ruby/tmp/closure_segfault.rb

module Closing
define_method :fibo do | n, cache=[1,1] |
return cache[n] if cache[n]
(fibo( n.pred, cache ) + fibo( n.pred.pred, cache )).tap do | result |
cache[ n ] = result
end
end
end
include Closing
puts fibo( 42 * 42 * 5 )

# vim: sts=2 sw=2 ft=ruby expandtab nu :
(2-2/2)