# ruby array inside hash is nil.

**URL:** <https://discuss.rubyonrails.org/t/ruby-array-inside-hash-is-nil/50205>\
**Category:** rubyonrails-talk\
**Created:** [March 18, 2010, 6:18am UTC](https://discuss.rubyonrails.org/t/ruby-array-inside-hash-is-nil/50205 "2010-03-18T06:18:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Habgood](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@Chris\_Habgood](https://discuss.rubyonrails.org/u/Chris_Habgood)\
**Post date:** [March 18, 2010, 6:18am UTC](https://discuss.rubyonrails.org/t/ruby-array-inside-hash-is-nil/50205/1 "2010-03-18T06:18: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)\<br/\>", "Rich Text Format (.rtf)\<br/\>", "Word Document (.doc, .docx)\<br/\>"]}

When I do:

h[:ext\_array] it is nil.

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [March 18, 2010, 8:27am UTC](https://discuss.rubyonrails.org/t/ruby-array-inside-hash-is-nil/50205/2 "2010-03-18T08:27:39Z")

</div>

Chris Habgood 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)\<br/\>", "Rich Text Format (.rtf)\<br/\>", "Word Document (.doc, .docx)\<br/\>"]}
> 
> 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:** ![Michael\_Pavling](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@Michael\_Pavling](https://discuss.rubyonrails.org/u/Michael_Pavling)\
**Post date:** [March 18, 2010, 8:45am UTC](https://discuss.rubyonrails.org/t/ruby-array-inside-hash-is-nil/50205/3 "2010-03-18T08:45:38Z")

</div>

> 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)\<br/\>", "Rich Text Format

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

> > h[:ext\_array]

=\> ["Text file (.txt)\<br/\>", "Rich Text Format\n(.rtf)\<br/\>", "Word Document (.doc, .docx)\<br/\>"]

> >

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:** ![mastermike2580](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@mastermike2580](https://discuss.rubyonrails.org/u/mastermike2580)\
**Post date:** [March 18, 2010, 4:47pm UTC](https://discuss.rubyonrails.org/t/ruby-array-inside-hash-is-nil/50205/4 "2010-03-18T16:47:18Z")

</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:** ![Chris\_Habgood](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@Chris\_Habgood](https://discuss.rubyonrails.org/u/Chris_Habgood)\
**Post date:** [March 18, 2010, 7:57pm UTC](https://discuss.rubyonrails.org/t/ruby-array-inside-hash-is-nil/50205/5 "2010-03-18T19:57:37Z")

</div>

Take out the single quotes.
