# Number in hash key

**URL:** <https://www.ruby-forum.com/t/number-in-hash-key/91416>\
**Category:** Rails\
**Created:** [April 8, 2007, 8:09pm UTC](https://www.ruby-forum.com/t/number-in-hash-key/91416 "2007-04-08T20:09:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bitterbal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bitterbal](https://www.ruby-forum.com/u/bitterbal)\
**Post date:** [April 8, 2007, 8:09pm UTC](https://www.ruby-forum.com/t/number-in-hash-key/91416/1 "2007-04-08T20:09:03Z")

</div>

How do I retrieve the valye if my hash key is a number.

example: record from activerecord query

#\<Mutation:0x33cefbc @attributes={“2003”=\>“0.00”, “2004”=\>“7281.62”,  
“week”=\>“01”, “2005”=\>“11847.90”, “2006”=\>“17813.10”,  
“2007”=\>“27772.45”}\>

This is storied in variable “p”.

What I want to do is to get the value for p.2007 but ofcourse this  
does not work. I tried p.‘2007’ but that also does not work.

am I trying to do something impossible ?

---

<div class="post-metadata">

**Author:** ![bitterbal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bitterbal](https://www.ruby-forum.com/u/bitterbal)\
**Post date:** [April 8, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/number-in-hash-key/91416/2 "2007-04-08T20:53:07Z")

</div>

The problem is that 2007 and ‘2007’ are not valid method names.

Try p.attributes[“2007”] or p[“2007”].

Chris
