Module: ProcToLambda
- Defined in:
- lib/proc-to-lambda.rb
Constant Summary collapse
- VERSION =
'0.1.0'.freeze
Class Method Summary collapse
-
.to_lambda(source_proc) ⇒ Object
Convert proc to lambda, retain the context.
Instance Method Summary collapse
-
#to_lambda(source_proc) ⇒ Object
Same as the class method
to_lambda
.
Class Method Details
.to_lambda(source_proc) ⇒ Object
Convert proc to lambda, retain the context.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/proc-to-lambda.rb', line 20 def self.to_lambda(source_proc) raise "Supplied argument must be a `Proc`" unless source_proc.is_a?(::Proc) return source_proc if source_proc.lambda? unbound_method = ::Module.new.module_eval do instance_method(define_method(:_, &source_proc)) end lambda do |*args, &block| unbound_method.bind(self).call(*args, &block) end end |
Instance Method Details
#to_lambda(source_proc) ⇒ Object
Same as the class method to_lambda
Use to include
8 9 10 |
# File 'lib/proc-to-lambda.rb', line 8 def to_lambda(source_proc) ::ProcToLambda.to_lambda(source_proc) end |