Module: Puppet::Macros::ToLambda

Included in:
Puppet::Macros
Defined in:
lib/puppet/macros.rb

Instance Method Summary collapse

Instance Method Details

#to_lambda(block) ⇒ Object


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/puppet/macros.rb', line 126

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