Hema, to be honest, I'm not really sure what exactly you want to
achieve, but maybe you can try this:

result = Array.new

for k in 1..4 do
  result << {"first" => k , "second"=> k + 1}
end


The result is:

[{"second"=>2, "first"=>1}, {"second"=>3, "first"=>2}, {"second"=>4,
"first"=>3}, {"second"=>5, "first"=>4}]



As far as I know there is no easy way to sort the elements of the
inner hashes, but that shouldn't raise any problem.

Let me know it this works for you.

On Nov 24, 9:49 pm, Hema <[EMAIL PROTECTED]> wrote:
> Hi All,
>             I need to add the hashes is there any way to add
>
> actually my data is in the given format
> data = [ {"first" => 1 ,"second" =>  2},
>             {"first" => 2 ,"second" =>  3},
>             {"first" => 3 ,"second" =>  4} ]
>
> I want to acheive it through the loop So, I took 2 hashes as
>
> result = Hash.new
> data = Hash.new
>
> for k in 1..4 do
>   data = {"first"=>k , "second"=>k+1}
>   result = result,data
> end
>
> in the above the result variable
>
>  result = [[[[{}, [{"first"=>1, "second"=>2}]], [{"first"=>2,
> "second"=>3}]], [{"first"=>3, "second"=>4}]], [{"first"=>4,
> "second"=>5}]]
>
> But my Output should be as
> result =  [{"first"=>1, "second"=>2}, {"first"=>2, "second"=>3},
> {"first"=>3, "second"=>4}, {"first"=>4, "second"=>5}]
>
> I tried with the merge,update but those are updating or the changing
> the existing the feilds.. the not appending
>
> How can I achieve the output if any help you can save my day...
> Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to