Created
January 28, 2014 16:12
-
-
Save ptomulik/8670700 to your computer and use it in GitHub Desktop.
Convert procs to lambdas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ToLambda | |
def to_lambda(block) | |
if Puppet::Util::Package.versioncmp(RUBY_VERSION,"1.9") >=0 | |
unless block.lambda? | |
# This code is based on: https://github.com/schneems/proc_to_lambda | |
# See also https://github.com/schneems/proc_to_lambda/issues/1 | |
if RUBY_ENGINE && RUBY_ENGINE == "jruby" | |
lambda(&block) | |
else | |
Object.new.define_singleton_method(:_, &block).to_proc | |
end | |
end | |
else | |
block | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment