# Hash behavior query

**URL:** <https://www.ruby-forum.com/t/hash-behavior-query/105494>\
**Category:** Ruby\
**Created:** [May 30, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/hash-behavior-query/105494 "2007-05-30T13:45:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhisek\_Datta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f17d59/32.png) [@Abhisek\_Datta](https://www.ruby-forum.com/u/Abhisek_Datta)\
**Post date:** [May 30, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/hash-behavior-query/105494/1 "2007-05-30T13:45:39Z")

</div>

irb(main):001:0\> d = [1,2,3,4]  
=\> [1, 2, 3, 4]  
irb(main):002:0\> h = Hash.new  
=\> {}  
irb(main):003:0\> h[d] = “hello”  
=\> “hello”  
irb(main):004:0\> h  
=\> {[1, 2, 3, 4]=\>“hello”}  
irb(main):005:0\> h[d]  
=\> “hello”  
irb(main):006:0\> d.push(5)  
=\> [1, 2, 3, 4, 5]  
irb(main):007:0\> h[d]  
=\> nil  
irb(main):008:0\> h  
=\> {[1, 2, 3, 4, 5]=\>“hello”}  
irb(main):009:0\> d  
=\> [1, 2, 3, 4, 5]  
irb(main):010:0\> h[d]  
=\> nil  
irb(main):011:0\> h.rehash  
=\> {[1, 2, 3, 4, 5]=\>“hello”}  
irb(main):012:0\> h[d]  
=\> “hello”  
irb(main):013:0\>

Is this expected or a bug?

-abhisek

---

<div class="post-metadata">

**Author:** ![Abhisek\_Datta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f17d59/32.png) [@Abhisek\_Datta](https://www.ruby-forum.com/u/Abhisek_Datta)\
**Post date:** [May 30, 2007, 1:54pm UTC](https://www.ruby-forum.com/t/hash-behavior-query/105494/2 "2007-05-30T13:54:40Z")

</div>

Hi –

On Wed, 30 May 2007, Abhisek Datta wrote:

> irb(main):006:0\> d.push(5)  
> =\> {[1, 2, 3, 4, 5]=\>“hello”}  
> irb(main):012:0\> h[d]  
> =\> “hello”  
> irb(main):013:0\>
> 
> Is this expected or a bug?

You’ve pretty much reproduced the documented example from the source  
code, so I’d say it’s expected 🙂

David

---

<div class="post-metadata">

**Author:** ![Abhisek\_Datta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f17d59/32.png) [@Abhisek\_Datta](https://www.ruby-forum.com/u/Abhisek_Datta)\
**Post date:** [May 30, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/hash-behavior-query/105494/3 "2007-05-30T13:58:41Z")

</div>

On 5/30/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > irb(main):004:0\> h  
> > =\> [1, 2, 3, 4, 5]
> 
> You’ve pretty much reproduced the documented example from the source  
> code, so I’d say it’s expected 🙂  
> … and furthermore was there not somebody asking whether to prefer  
> Strings or Symbols as hash keys.  
> I think the example above gives you some hints, – sometimes Strings  
> are still a good choice, but only sometimes.

Cheers  
Robert
