# Ruby array inside hash is nil

**URL:** <https://www.ruby-forum.com/t/ruby-array-inside-hash-is-nil/185322>\
**Category:** Rails\
**Created:** [March 18, 2010, 7:19am UTC](https://www.ruby-forum.com/t/ruby-array-inside-hash-is-nil/185322 "2010-03-18T07:19:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 18, 2010, 7:19am UTC](https://www.ruby-forum.com/t/ruby-array-inside-hash-is-nil/185322/1 "2010-03-18T07:19:20Z")

</div>

I assign an array to a hash value. When I inspect it shows the array  
but when I try to access the array by the hash index it is nil.  
Ideas?

Here is the log output of the inspect hash:

{:has\_key=\>0, :ext\_array=\>[“Text file (.txt)  
”, “Rich Text Format  
(.rtf)  
”, “Word Document (.doc, .docx)  
”]}

When I do:

h[:ext\_array] it is nil.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 18, 2010, 9:27am UTC](https://www.ruby-forum.com/t/ruby-array-inside-hash-is-nil/185322/2 "2010-03-18T09:27:39Z")

</div>

Chris H. wrote:

> I assign an array to a hash value. When I inspect it shows the array  
> but when I try to access the array by the hash index it is nil.  
> Ideas?
> 
> Here is the log output of the inspect hash:
> 
> {:has\_key=\>0, :ext\_array=\>[“Text file (.txt)  
> ”, “Rich Text Format  
> (.rtf)  
> ”, “Word Document (.doc, .docx)  
> ”]}
> 
> When I do:
> 
> h[:ext\_array] it is nil.

If u don’t mind can u give me the whole code.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 18, 2010, 9:47am UTC](https://www.ruby-forum.com/t/ruby-array-inside-hash-is-nil/185322/3 "2010-03-18T09:47:25Z")

</div>

On 18 March 2010 06:18, Me [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I assign an array to a hash value.
> 
> h[:ext\_array] it is nil.

I copied your hash into IRB and it worked fine:

> > h = {:has\_key=\>0, :ext\_array=\>[“Text file (.txt)  
> > ”, “Rich Text Format  
> > (.rtf)  
> > ”, “Word Document (.doc, .docx)  
> > ”]}  
> > =\> {:has\_key=\>0, :ext\_array=\>[“Text file (.txt)  
> > ”, “Rich Text  
> > Format\n(.rtf)  
> > ”, “Word Document (.doc, .docx)  
> > ”]}  
> > h[:ext\_array]  
> > =\> [“Text file (.txt)  
> > ”, “Rich Text Format\n(.rtf)  
> > ”, “Word  
> > Document (.doc, .docx)  
> > ”]

Can you post the code where you’re accessing h[:ext\_array] and getting  
nil. I think you might be getting nil as the result of an expression  
rather than the value from the hash.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 18, 2010, 6:57pm UTC](https://www.ruby-forum.com/t/ruby-array-inside-hash-is-nil/185322/4 "2010-03-18T18:57:46Z")

</div>

i am getting this same exact error message when i try to do a  
User.find\_by\_username(‘array’). Im have twitter users signed up on my  
site and i am trying to find the the users on my site from a  
timeline.

When i try \<%= User.find\_by\_username(‘status.user.screen\_name’) %\> It  
returns nil, but if i use \<%= status.user.screen\_name %\> it returns  
all the user screen names so i can not figure out what is going wrong.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 18, 2010, 8:59pm UTC](https://www.ruby-forum.com/t/ruby-array-inside-hash-is-nil/185322/5 "2010-03-18T20:59:33Z")

</div>

Take out the single quotes.
