ruby eval('\1') of gsub possible?
- by Horace Ho
I try to replace a sub-str by the content of a valiable where its name matches the sub-str by:
>> str = "Hello **name**"
=> "Hello **name**"
>> name = "John"
=> "John"
str.gsub(/\*\*(.*)\*\*/, eval('\1')) # => error!
the last line in the code above is a syntax error. and:
>> str.gsub(/\*\*(.*)\*\*/, '\1')
=>…