ruby on rails - push new element into array within hash -


i have hash which, have keys uniquely identify each element within hash. , within each element, have array. question is, how put element inside array within hash.

{"apple"=>[1, 5.99], "banana"=>[5, 9.99]} 

i'm looping through result set, , i'm little bit lost how add element array...

any appreciated

cheers

if hash called, example, hsh, "apple" array can accessed hsh["apple"]. can use variable, add value array hsh["apple"] << some_value. so:

irb> hsh = { "apple" => [1, 5.99], "banana" => [5, 9.99] } irb> hsh["apple"] << 9999 => { "apple" => [1, 5.99, 9999], "banana" => [5, 9.99] } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -