That's great it worked fine
But I have another problem,
please check the code
Fields = Array.new
Fields [0] = "sno"
Fields [1] = "username"
Fields [2] = "designation"
Fields [3] = "salary"
Fields [4] = "dob"
Fields [5] = "email"
Fields [6] = "doj"
These are the fields of the object 'Employee'
The Employees array contains of the set of employee objects...
I need to have the array of hashes as [{employee_record1},
{employee_record2}...... n records]
For this i tried as the...
result = []
for employee in Employees
res = {}
for field in fields
res << { field => employee.send(field)}
end
result << res
end
But it is not working... Please Help me Thank You
On Nov 25, 3:07 pm, Xie Hanjian <[EMAIL PROTECTED]> wrote:
> * Hema <[EMAIL PROTECTED]> [2008-11-24 21:49:34 -0800]:
>
>
>
>
>
> > 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}]
>
> (1..4).inject([]){|result,i| result << {"first" => i, "second" => i+1}}
>
>
>
> > 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
> > >
> --
> jan=callcc{|jan|jan};jan.call(jan)
>
> application_pgp-signature_part
> < 1KViewDownload
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---