Skip to content

Instantly share code, notes, and snippets.

/hash.rb Secret

Created March 17, 2017 07:09
Show Gist options
  • Save anonymous/480bf9f18e98fd12020a196ff4dad7ca to your computer and use it in GitHub Desktop.
Save anonymous/480bf9f18e98fd12020a196ff4dad7ca to your computer and use it in GitHub Desktop.
filter a nested hash
user = {"id"=>97, "username"=>"bobbyl1000", "scores"=>[{"group_id"=>nil, "percentile_score"=>"0.3669724771"}, {"group_id"=>nil, "percentile_score"=>"0.3333333333"}, {"group_id"=>1, "percentile_score"=>"1.0"}, {"group_id"=>1, "percentile_score"=>"1.0"}], "avatar"=>{"url"=>"https://s3.amazonaws.com/gamepredict/assets/logo-.png", "profile"=>{"url"=>"https://s3.amazonaws.com/gamepredict/assets/logo-profile.png"}, "small"=>{"url"=>"https://s3.amazonaws.com/gamepredict/assets/logo-small.png"}}}
# I want to filter user so that it returns the exact hash, except the scores array should return only the hash that has "group_id" == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment