Page MenuHomeSoftware Heritage

hashify.rb
No OneTemporary

hashify.rb

module Puppet::Parser::Functions
newfunction(:hashify, :type => :rvalue, :doc => <<-EOS
This function converts a key => value into a nested hash.
*Examples:*
hashify({'a' => 1, 'b' => 2})
Would return: {
'a' => {'value' => 1},
'b' => {'value' => 2}
}
EOS
) do |arguments|
raise(Puppet::ParseError, "hashify(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
hash = arguments[0]
unless hash.is_a?(Hash)
raise(Puppet::ParseError, 'hashify(): Requires hash to work with')
end
result = hash.reduce({}) { |acc, kv|
acc.inspect
kv.inspect
acc[kv[0]] = {'value' => kv[1]}
acc
}
return result
end
end

File Metadata

Mime Type
text/x-ruby
Expires
Jun 4 2025, 7:47 PM (11 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3399377

Event Timeline