Skip to content

Instantly share code, notes, and snippets.

@samuraijane
Created March 31, 2015 21:54
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 samuraijane/88638f708ec3f042727f to your computer and use it in GitHub Desktop.
Save samuraijane/88638f708ec3f042727f to your computer and use it in GitHub Desktop.
When dealing with nested maps that create an array you need to access, where you define the variable that holds the array is important. See the differences here.
#Example 1
$myvariable= imgarray.map do |layouts|
layouts[ 'layouts' ].map do |layout_name|
layout_name[ 'layout_name' ]
end
end
#Placing the variable at the beginning of the loop returns an array within an array:
#[["annie", "billy", "charlie", "danny", "eddy", "fergie", "granny", "henry", "jenny", "kelsey"]]
#Example 2
imgarray.map do |layouts|
$myvariable= layouts[ 'layouts' ].map do |layout_name|
layout_name[ 'layout_name' ]
end
end
#Placing the variable one level down returns just one array:
#["annie", "billy", "charlie", "danny", "eddy", "fergie", "granny", "henry", "jenny", "kelsey"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment