# \*hash is different from hash.to\_a?

**URL:** <https://www.ruby-forum.com/t/hash-is-different-from-hash-to-a/121550>\
**Category:** Ruby\
**Created:** [November 28, 2007, 9:47pm UTC](https://www.ruby-forum.com/t/hash-is-different-from-hash-to-a/121550 "2007-11-28T21:47:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [November 28, 2007, 9:47pm UTC](https://www.ruby-forum.com/t/hash-is-different-from-hash-to-a/121550/1 "2007-11-28T21:47:34Z")

</div>

Has this come up before? I don;t recall. But just the same. Does this  
seem inconsistent to you?

irb(main):003:0\> a = \*{:a=\>1}  
=\> [:a, 1]  
irb(main):004:0\> a = \*{:a=\>1,:b=\>2}  
=\> [[:b, 2], [:a, 1]]

vs.

irb(main):006:0\> a = {:a=\>1}.to\_a  
=\> [[:a, 1]]  
irb(main):007:0\> a = {:a=\>1,:b=\>2}.to\_a  
=\> [[:b, 2], [:a, 1]]

T.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [November 28, 2007, 10:03pm UTC](https://www.ruby-forum.com/t/hash-is-different-from-hash-to-a/121550/2 "2007-11-28T22:03:29Z")

</div>

Trans wrote:

> irb(main):006:0\> a = {:a=\>1}.to\_a  
> =\> [[:a, 1]]  
> irb(main):007:0\> a = {:a=\>1,:b=\>2}.to\_a  
> =\> [[:b, 2], [:a, 1]]

Not really inconsistent - \* unwraps its argument if it can. Observe:

irb(main):001:0\> a = \*[1,2]  
=\> [1, 2]  
irb(main):002:0\> a = \*[1]  
=\> 1

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [November 29, 2007, 12:35am UTC](https://www.ruby-forum.com/t/hash-is-different-from-hash-to-a/121550/3 "2007-11-29T00:35:40Z")

</div>

On Nov 28, 2:46 pm, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> irb(main):006:0\> a = {:a=\>1}.to\_a  
> =\> [[:a, 1]]  
> irb(main):007:0\> a = {:a=\>1,:b=\>2}.to\_a  
> =\> [[:b, 2], [:a, 1]]
> 
> T.

Splat behavior is going to be slightly different in 1.9 [1] (e.g.,  
splat just returns the whole hash, regardless of element count, inside  
a single array). Just thought you might like to know so you don’t end  
up writing brand new legacy code. 😉

[1]  
[http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/214897?214708-244931](http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/214897?214708-244931)

Regards,  
Jordan
