Is there a 'variable_get' method? If not, how can I create my own?

前端 未结 2 1867
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 02:39

courtesy of irb:

2.0.0-p0 :006 > @instance_variable = \"from an instance variable\"
 => \"from an instance variable\" 
2.0.0-p0 :007 > variable = \"         


        
2条回答
  •  庸人自扰
    2020-12-04 03:23

    You could use eval:

    irb(main):007:0> variable = "from a variable"
    => "from a variable"
    irb(main):008:0> eval 'variable'
    => "from a variable"
    

提交回复
热议问题