I want to populate an array that has an integer and a hash, something like:
my_a=[Integer,{}]
then for example I am trying to have:
my_a[5,{:direction=>'up'}]
my_a[5,{:speed=>'fast'}]
my_a[3,{:direction=>'up'}]
my_a[3,{:speed=>'slow'}]
but I get
ArgumentError: wrong number of arguments(2 for 1)
How do I set my_a to have an entry for 5 with :direction => 'up'?
Maybe the whole thing should be a hash?
Trying to find someway to store this:
[0,{:top => ' ―― '},{:top_mid => '|__|'},{:bot_mid => '| |'},{:bot => '――'}]
[1,{:top => ' ―― '},{:top_mid => '|__|'},{:bot_mid => '| |'},{:bot => '――'}]
[2,{:top => ' ―― '},{:top_mid => '|__|'},{:bot_mid => '| |'},{:bot => '――'}]
{:direction=>'up'}
if you ask for the value indexed by number5
? Because that is just a regular arraymy_a[5] = {:direction=>'up'}
. . . what is different about your requirement?my_a[...]
is an array access.Array#[int, hash]
is indeed not defined. That doesn't prevent you from using[int, hash]
as an array literal:my_a = [5, {:direction => :up}]
direction
andspeed
, while your edit hastop
andtop_mid
. When someone asks you "What are you trying to do?" you should not describe the data structures you think you need. You should describe your actual goal, the coding problem you are trying to solve. Step back two abstraction layers higher and tell us something like, "I'm writing an ASCII table and as I iterate through the rows I need to pick out the right pieces to show." Or whatever you are really doing.