TODAY I LEARNED

How to replace a key in a Ruby hash

Deleting a key from a hash returns the value and you can quickly assigning it to a new key on the same hash

test[:questions] = test.delete('my_questions')

Tweet

Learned by jaime-loyola on Dec 9, 2024

Discover our latest blog posts
  • #ruby
  • view raw
  • permalink
  • 2 likes
previous TIL next TIL
  • Log in
  • ?

    TIL is an open-source project by MagmaLabs that exists to catalogue the sharing & accumulation of knowledge as it happens day-to-day. Posts have a 200-word limit, and posting is open to any MagmaLaber as well as selected friends of MagmaLabs. We hope you enjoy learning along with us.

    • /wearemagmalabs
  • statistics
  • search
  • Twitter