Skip to content

Instantly share code, notes, and snippets.

@ptomulik
Created January 28, 2014 16:12
Show Gist options
  • Save ptomulik/8670700 to your computer and use it in GitHub Desktop.
Save ptomulik/8670700 to your computer and use it in GitHub Desktop.
Convert procs to lambdas
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