views:

123

answers:

3

Hi

I would like to iterate

@some_value outputs the following result

{"Meta"=>{"Query"=>"java", "ResultOffset"=>"1", "NumResults"=>"1", "TotalResults"=>"21931"}}

i need to retrieve the Value of each individual value for example

java 1 1 21931

+4  A: 

There's the each method.

@some_value['Meta'].each do |k, v|
    puts v
end

Which will loop through every of your entry and execute the code inside the do/end for every of them.
Here it'll display the value of the element.

Damien MATHIEU
i need to display based on key for example @something of Query should return java . The above statement just display the values
Big Bang Theory
got it through the doc :)
Big Bang Theory
This isn't a very good example, since this would be much better accomplished by a simple `puts @some_value['Meta'].values`
Jörg W Mittag
Yeah. But he wants to iterate and do something else than just display the content of the hash.
Damien MATHIEU
The `k` and `v` are short for key and value in case anyone's wondering. Block parameter names tend to be shorter than normal variable names.
Andrew Grimm
+5  A: 
@some_value["Meta"].values

output is array

["java", "1", "1", "21931"]
+4  A: 

Hash#each_value

@some_value['Meta'].each_value { |v| p v }
Firas Assaad