Skip to content

Instantly share code, notes, and snippets.

@alejandrobabio
Created November 29, 2017 11:37
Show Gist options
  • Save alejandrobabio/6a0f3ee0697d04587f4d3f4166d0cf58 to your computer and use it in GitHub Desktop.
Save alejandrobabio/6a0f3ee0697d04587f4d3f4166d0cf58 to your computer and use it in GitHub Desktop.
Recursive lambda that symbolize keys of a Hash
Symbolize = (l = ->(h) { h.inject({}) { |m, (k,v)| m[(String === k ? k.to_sym : k)] = (Hash === v ? l.(v) : v); m }})
# Example:
hash = { 'task' => { 'description' => 'Ab@ @example @cd', 'target' => { 'label' => 'cd' } } }
Symbolize.(hash)
# => { :task => { :description => "Ab@ @example @cd", :target => { :label => "cd" } } }
@alejandrobabio
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment