Guest User

Untitled

a guest
Feb 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. class EigenProc < Proc
  2. def initialize(&prc)
  3. super
  4. (class << self; self end).class_eval { define_method(:call,&prc); alias_method :[], :call }
  5. end
  6. end
  7. module Kernel; def sproc &blk; EigenProc.new &blk end end
  8.  
  9. if $0 == __FILE__
  10. # recursivity
  11. fib = sproc { |n| n<2 ? n : self[n-2]+self[n-1] }
  12. p (0..10).map{|i|fib[i]}
  13.  
  14. # scope
  15. a = 'foo'
  16. sproc { |b| puts a+b }['bar']
  17. end
Add Comment
Please, Sign In to add comment