In some code I’m trying to learn from, the Maze string below is turned into an array (code not shown for that) and saved in the instance variable @maze. The starting point of the Maze is represented by the letter ‘A’ in that Maze, which can be accessed at @maze[1][13]—row 1, column 13. However, the code I’m looking at uses @maze[1][13,1] to get the A, which you can see returns the same result in my console. If I do @maze[1][13,2], it returns the letter “A ” with two blank spaces next to it, and so on. [13,3] returns “A ” with three blank spaces.
Does the 2 in [13,2] mean, “return two values starting at [1][13]? If so, why? Is this some feature of arrays or two dimensional arrays that I don’t get?
[20] pry(#<Maze>):1> @maze[1][13]
=> "A"
[17] pry(#<Maze>):1> @maze[1][13,1]
=> "A"
[18] pry(#<Maze>):1> @maze[1][13,2]
=> "A "
[19] pry(#<Maze>):1> @maze[1][13,3]
=> "A "
Maze String
MAZE1 = %{#####################################
# # # #A # # #
# # # # # # ####### # ### # ####### #
# # # # # # # # #
# ##### # ################# # #######
# # # # # # # # #
##### ##### ### ### # ### # # # # # #
# # # # # # B# # # # # #
# # ##### ##### # # ### # # ####### #
# # # # # # # # # # # #
# ### ### # # # # ##### # # # ##### #
# # # # # # #
#####################################}
From what you show, it seems that
@mazeis not a two-dimentional array, but is an array of strings.@maze[1]is a string. The second[]is applied to a string. And the second argument ofString#[]method describes the length of characters to take. You can consider that it is defaulted to1when you do not specify it. By the way, your question is wrong. You describebut what your example shows is