Puppet Function: to_python
- Defined in:
-
lib/puppet/functions/to_python.rb
- Function type:
- Ruby 4.x API
Summary
Convert an object into a String containing its Python representation
Overview
to_python(Any $object) ⇒ Any
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/puppet/functions/to_python.rb', line 17
Puppet::Functions.create_function(:to_python) do
dispatch :to_python do
param 'Any', :object
end
def to_python(object)
case object
when true then 'True'
when false then 'False'
when :undef then 'None'
when Array then "[#{object.map { |x| to_python(x) }.join(', ')}]"
when Hash then "{#{object.map { |k, v| "#{to_python(k)}: #{to_python(v)}" }.join(', ')}}"
else object.inspect
end
end
end
|