What about doing error checking on the type first?

```ruby
unless args[0].is_a? Array or args[0].is_a? Hash
  raise Puppet::ParseError, "delete_undef_values(): expected an array or hash, got a #{args[0]}"
end

result = args[0].dup
# ...
```