Saturday 7 September 2013

retrieve only unique records from an ruby array

retrieve only unique records from an ruby array

I have an array of students(students). I need to remove duplicate records
from it and get only unique student details. In my console I am getting
like
students = [
[#<Student id: 2, admission_no: "2", gender: "m", blood_group: "A">,
Wed, 11 Sep 2013, "Student"],
[#<Student id: 17, admission_no: "17",gender: "m", blood_group: "AB">,
Sat, 14 Sep 2013, "Student"],
[#<Student id: 17, admission_no: "17",gender: "m", blood_group: "AB">,
Tue, 17 Sep 2013, "Student"],
[#<Student id: 2, admission_no: "2",gender: "m">, Tue, 17 Sep 2013,
"Student"],
[#<Student id: 17, admission_no: "17",gender: "m", blood_group: "AB">,
Thu, 12 Sep 2013, "Student"]
]
I tried using students = students.uniq. But it is getting nil values..
Because I am also inserting two more attributes(date and type i.e last two
ones..) retrieved from another table .But I need to display unique
students records as well as its type.. How do I do it? Please help.

No comments:

Post a Comment