Skip to content

Instantly share code, notes, and snippets.

@ecnalyr
Last active August 4, 2016 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecnalyr/fd4c6f3916ff93abd39af6131c8f363f to your computer and use it in GitHub Desktop.
Save ecnalyr/fd4c6f3916ff93abd39af6131c8f363f to your computer and use it in GitHub Desktop.
# Fetches the responses and uses the first N elements of the array
# where N is the same number of associated_objects the parent object has.
def responses_and_associated_objects
# response is hard-coded for demonstration purposes
response = {"something":[123,456,789,101112,0,0,0,0,0,0,0,0]}
# this next line is ugly, thoughts?
response['something'][0..associated_objects.count-1]
end
@ecnalyr
Copy link
Author

ecnalyr commented Aug 4, 2016

Maybe this?

associated_objects.map.with_index{|associated_object, index| response['something'][index]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment