Skip to content

Instantly share code, notes, and snippets.

@caius
Created August 25, 2017 22:01
Show Gist options
  • Save caius/20ab19b6b2bdd1c0d90ec5afb16a58b0 to your computer and use it in GitHub Desktop.
Save caius/20ab19b6b2bdd1c0d90ec5afb16a58b0 to your computer and use it in GitHub Desktop.
<%-
# Here be hax - we find all values that are integers masked as strings and
# turn them into actual integers. Thanks puppet.
numerify = lambda do |obj|
case obj
when lambda { |o| o.respond_to?(:to_i) && o.to_i.to_s == o.to_s }
begin
Integer(obj)
rescue ArgumentError
obj
end
when Array
obj.map { |e| numerify.call(e) }
when Hash
obj.merge(obj) { |k, val| numerify.call(val) }
else
obj
end
end
-%><%= JSON.pretty_generate({@name => numerify.call(@options)}) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment