# Reverse keys and values in a hash

**URL:** <https://www.ruby-forum.com/t/reverse-keys-and-values-in-a-hash/152439>\
**Category:** Rails\
**Created:** [November 3, 2008, 11:35pm UTC](https://www.ruby-forum.com/t/reverse-keys-and-values-in-a-hash/152439 "2008-11-03T23:35:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neal\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/74df32/32.png) [@Neal\_L](https://www.ruby-forum.com/u/Neal_L)\
**Post date:** [November 3, 2008, 11:35pm UTC](https://www.ruby-forum.com/t/reverse-keys-and-values-in-a-hash/152439/1 "2008-11-03T23:35:41Z")

</div>

Hello all,

This is more of a ruby question than a rails question, but I’m  
wondering if it’s possible to reverse the keys and values in a hash.

I’m using a hash to map fields from one component of my app to  
another, and sometimes the data needs to go “the other way”…

Thanks!

---

<div class="post-metadata">

**Author:** ![Neal\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/74df32/32.png) [@Neal\_L](https://www.ruby-forum.com/u/Neal_L)\
**Post date:** [November 3, 2008, 11:58pm UTC](https://www.ruby-forum.com/t/reverse-keys-and-values-in-a-hash/152439/2 "2008-11-03T23:58:32Z")

</div>

[http://www.noobkit.com/show/ruby/ruby/ruby-core/hash/invert.html](http://www.noobkit.com/show/ruby/ruby/ruby-core/hash/invert.html)
