Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class EigenProc < Proc
- def initialize(&prc)
- super
- (class << self; self end).class_eval { define_method(:call,&prc); alias_method :[], :call }
- end
- end
- module Kernel; def sproc &blk; EigenProc.new &blk end end
- if $0 == __FILE__
- # recursivity
- fib = sproc { |n| n<2 ? n : self[n-2]+self[n-1] }
- p (0..10).map{|i|fib[i]}
- # scope
- a = 'foo'
- sproc { |b| puts a+b }['bar']
- end
Add Comment
Please, Sign In to add comment