Skip to content

Instantly share code, notes, and snippets.

@alexggordon
Last active August 29, 2015 14:13
Show Gist options
  • Save alexggordon/f8359b160559358fb12b to your computer and use it in GitHub Desktop.
Save alexggordon/f8359b160559358fb12b to your computer and use it in GitHub Desktop.
# I need to turn
[ {:class_fk => 1234, :criteria => "citizenship", :grade => "A"},
{:class_fk => 1234, :criteria => "effort", :grade => "B"} ]
# into
{ 1234 => {"citizenship" => "A", "effort" => "B"} }
# I have this
@citizenship_effort = @citizenship_effort.map {|v| {class_pk: v[:class_pk], v[:criteria] => v[:grade]}}.group_by {|x| x[:class_pk]}
# but it results in
{1234=>[{:class_pk=>1234, "citizenship"=>"A"}, {:class_pk=>1234, "Effort"=>"B"}] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment