How to do “late” string interpolation in Ruby

前端 未结 6 955
再見小時候
再見小時候 2021-01-01 10:55
>> string = \'#{var}\'
=> \"\\#{var}\"

>> proc = Proc.new { |var| string }
=> #

>> proc.call(123)
=> \"\\         


        
6条回答
  •  春和景丽
    2021-01-01 11:38

    Do you have to define the interpolation-bearing string outside of your Proc?

    proc = Proc.new { |var| "#{var}" }
    proc.call(123) # "123"
    

    This would be the cleanest way I think.

提交回复
热议问题