samedi 7 mars 2015

Ruby: Hash {Key => [value1, value2]} - need to check value2 only for each key


Given that i have a dump memory object filled already and i want only to extract and work with the second value



x = Marshal.load(File.binread('in_memory'))

x.each {|key , value | puts " #{key} => #{value}"}

# My Result

1 => [[1, 200]]
2 => [[2, 450]]
6 => [[2, 1000]]
7 => [[4, 1003]]


The Marshal binary dump in to an hash has a key and an array of two values;


in the each loop how can i check for example if value2 is = or > than 1000... if i have some than i only need to display



6 => [[2, 1000]]
7 => [[4, 1003]]


and the count of records found



count =2


is it possible with Marshal dumps and Hashes?





Aucun commentaire:

Enregistrer un commentaire