I know this code doesn't look good at all , but i just want to explain my requirement. I want to know is there any good or alternative approach to it.
Actually, i want to create a new stack and whenever one stack has reached its capacity. I want to keep track of number of stacks created like @stack_1, @stack_2 ...by incrementing @number += 1 like @stack_@number. And for every stack, i want to maintain a @current_position pointer which is specific to every stack like @stack_2 has @current_position_2. So i want to create dynamic instance variables.
Example:
def initialize
@number = 1
@stack+"#{@number}" = Array.new(10)
@current_position_"#{@number}" = 0
end
Output should be something like @stack1 = Array.new(10).
Lets say if i increment value of @number += 1, it should look like @stack2 = Array.new(10)