Skip to content

Instantly share code, notes, and snippets.

@elyscape elyscape/upcase.rb
Last active Aug 29, 2015

What would you like to do?
def deep_upcase(item)
if item.respond_to? :upcase
return item.upcase
case item
when Array { |i| deep_upcase(i) }
when Hash
Hash[ { |k,v| [deep_upcase(k), deep_upcase(v)] } ]
Puppet::Parser::Functions.newfunction(:upcase, :type => :rvalue) do |args|

This comment has been minimized.

Copy link

commented Feb 28, 2015

Realistically we can just do the same pattern to upcase instead of creating a new function that goes further but like the recursion


This comment has been minimized.

Copy link
Owner Author

commented Feb 28, 2015

The benefit to having the recursive function be a separate function is that then you can perform validation on the top-level object passed in and not on what's contained inside it, so upcase(4) is invalid but upcase({'a' => 4}) would still work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.