Skip to content

Instantly share code, notes, and snippets.

@pointcom
Last active January 3, 2018 21:36
Show Gist options
  • Save pointcom/93608b917fd504e288e2fe3a25a296c5 to your computer and use it in GitHub Desktop.
Save pointcom/93608b917fd504e288e2fe3a25a296c5 to your computer and use it in GitHub Desktop.
Ruby 2.5
h = { a: 1, b: 2, c: 3 }
=> {:a=>1, :b=>2, :c=>3}
h.transform_keys {|k| k.to_s }
=> {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(&:to_s)
=> {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
=> {"a.0"=>1, "b.1"=>2, "c.2"=>3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment