Within this itteration:
a1=[1,2,3,4,5]
a2=[1,2,3,4,5]
a1.each_with_index{|a, i| ... = a + a2[i]}
I want to assign to different local variables b1
, b2
, ..., b5
, each per iteration to get:
b1 # => 2
b2 # => 4
b3 # => 6
b4 # => 8
b5 # => 10
I tried:
a1.each_with_index{|a, i| ('b' + i.to_s) = a + a2[i]}
but this doesn't work. Anyone got any ideas?
Try using instance_variable_set