Przerabianie obiektu ar na tablicę

Witajcie
planuję przerobić obiekt AR na tablicę,w której indeksem będzie pole typu DateTime. robię to w następujący sposób:

@absences.map! {|x| {x.updated_at=> {x.hours,x.comment} } }

problem w tym, że teraz mam tablicę w postaci
@absences[0][‘Moja-Data’][0], zamiast porządanej przeze mnie
@absences[‘Moja-Data’][0]
czy istnieje jakiś sposób, żeby załatwić mój problem?

Jeśli tablica ma nienumeryczny indeks to nazywa się Hash.

@absences.group_by {|x| x.updated_at}

lub

@absences.map {|x| {:updated_at => x.updated_at, :hours => x.hours, :comment => x.comment}}.group_by {|x| x[:updated_at]}

@absences = Absence.absend(@children.id).map {|x| {:updated_at => x.updated_at, :hours => x.hours, :comment => x.comment}}.group_by {|x| x[:updated_at]}

debug @absences wywala mi cos takiego:

[code=ruby]— !map:ActiveSupport::OrderedHash
&id001 !timestamp ?
at: “2009-06-06 18:25:22 Z”
@marshal_with_utc_coercion”: true
:

  • :comment:
    :updated_at: *id001
    :hours: 5[/code]
    a ogólnie usiłuję wywalczyć, aby
<%== debug @absences.include?('2009-06-06 18:25:22') %>

było true :wink:

@absences.key?(‘2009-06-06 18:25:22’)

Tyle ze updated_at to obiekt Time a nie string. Musisz jeszcze powalczyć :slight_smile: