ruby - select row from array of arrays -


I am trying to print the fourth row of the array of the following array using a certain method, maybe someone in class. Array_of_arrays = [["1", "2", "3", "4"], ["g", "h", "y", "t"], [ I tried a lot, "p", "v", "b", "q"], ["z", "z", "z", "z"] ] But this will not work because I need to call a specific line in the method Although I am familiar with the Chenning method like (.slice), I need to define a method within a class that will generate the expected line I have tried to experiment with hash and blocks, but for my solution Do not work. I'm really reaching out for options thanks!

  hsh = {} array_of_arrays.each {| X | Hsh [x [0]] = x [1]} p array_of_arrays.map {| Row | Line [2]} p array_of_arrays {| Row | Row.values} hsh_boggled = {} array_of_arrays.each do | X | Key = x [0] val = x [1] hsh_boggled [key] = val end   

Therefore, I would like to define a method which can call a line; Therefore, with a method array_of_arrays must call line 4 ["z", "z", "z", "z"]. Thanks!

If you really want a method, use it.

  Array_of_arrays.slice (3) # = & gt; Commenting on Carrie Swavland, alternative syntax and more common way to do the same thing: , "z", "z", "z",   

  array_of_arrays [3] # = & gt; ["Z", "z", "z", "z"]    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -