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