In the context of creating the local variable itself, it is true that there are some difficulties to overcome, however, the dynamic task assignment still does not present a problem.
>> my_lv = 0 => 0 >> instance_eval("#{'my_lv'} = 42") => 42 >> my_lv => 42
So, just create from the collected input (from gets , chomped or stripped as needed, it will just naturally end as a string) and call to_sym on it and add a new character to local_variables and evade ...
>> local_variables << :my_created_lv => [:my_lv, :__, :_, :_dir_, :_file_, :_ex_, :_pry_, :_out_, :_in_, :my_created_lv] >>
Then you take the assembled string that you converted to a character and assigned in the code shown above and evaluate it to get the value.
>> eval :my_lv.to_s >> 24
As noted in another answer, I cannot easily reproduce this outside of Pry or IRB.
This has changed in future versions of Ruby, and Matz has removed and is working hard to make this no longer possible.
vgoff
source share