Created
March 31, 2015 21:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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