Forum: Ruby on Rails number in hash key

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
86a01abd9d77ebfc577b2890623c6170?d=identicon&s=25 bitterbal (Guest)
on 2007-04-08 20:09
(Received via mailing list)
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",

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 ?
3a0f2ec009ceffdd65f056540a409a23?d=identicon&s=25 Chris Mear (Guest)
on 2007-04-08 20:53
(Received via mailing list)
The problem is that 2007 and '2007' are not valid method names.

Try p.attributes["2007"] or p["2007"].

This topic is locked and can not be replied to.