proc-to-lambda
Introduction
Convert proc to lambda, retain the context.
Install
gem install 'proc-to-lambda'Usage
You can use the method directly by invoke the method to_lambda of ProcToLambda.
my_proc = proc { return self + 1 }
my_lambda = ProcToLambda.to_lambda(my_proc)
# `return` works here, and can retain `self`
1.instance_exec(&my_lambda) # => 2Or, you can include or extend the ProcToLambda module.
include ProcToLambda
def foo
to_lambda(proc {})
end# beware, this is risky.
Proc.extend(ProcTolambda)
Proc.to_lambda(proc {})More
You can see also test cases.