From: Robert Klemme Date: 2012-10-06T01:53:36+09:00 Subject: Re: Calculation of heights On Thu, Oct 4, 2012 at 7:26 PM, Joao Silva wrote: > The question I have is how to load a hash where the key is not numeric > or does not follow a cycle. I'm doing an exercise where I have to go > asking people's names and their corresponding heights, these the income The term "income" has a meaning not applicable here: http://www.merriam-webster.com/dictionary/income > each in a different array, and then deposit them into a hash and get > over 2 meters, 1.60 meters minors, etc. The problem is how to charge the > hash data arrays. Here is the code: The program does not do any calculations. What are you trying to achieve? Do you want to ouput all names of people who are less than 1.6m and over 2m? That would be a selection of the data which I cannot see in your program. Example irb(main):006:0> heights = {"foo"=>1.0, "bar"=>1.8, "baz" => 2.1} => {"foo"=>1.0, "bar"=>1.8, "baz"=>2.1} irb(main):007:0> puts heights.select {|n,h| h < 1.6}.map {|n, h| n} foo => nil irb(main):008:0> puts heights.select {|n,h| h < 2}.map {|n, h| n} foo bar => nil irb(main):009:0> puts heights.select {|n,h| h >= 2}.map {|n, h| n} baz => nil > is not applicable in Ruby using for loops, but not the only language I > use then I get a little tricky to get used. > > not if you understand the problem. You lost me here completely. What are you trying to say? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/