Skip to content

Instantly share code, notes, and snippets.

@roalcantara
Created June 28, 2017 20:04
Show Gist options
  • Save roalcantara/e576b68838ce9aeb9ef0df700ff6c284 to your computer and use it in GitHub Desktop.
Save roalcantara/e576b68838ce9aeb9ef0df700ff6c284 to your computer and use it in GitHub Desktop.
Ruby > Remove has values recursively
event = {
"level" => 99,
"msgid" => "97bf040b.ba1078",
"pid" => 21,
"source" => "f7d04af7b740/node-red",
"message" => {
"res" => {
"_res" => "[Circular]"
},
"payload" => "[Circular]"
}
}
def clean_up(event)
if event&.is_a?(Hash)
event.each_pair do |key, value|
if value == '[Circular]'
event.delete(key)
else
clean_up(value)
end
end
elsif event&.is_a?(Array)
event = event.collect { |item| clean_up(item) }
end
event
end
clean_up(event)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment