How can I render a string like erb files render.
for example I want this string:
"Hello <%= 'World'%>"
To be:
"Hello World"
How can I do this?
If I properly understand you, this would be helpful:
require 'erb'
str = "Hello <%= 'World'%>"
result = ERB.new(str).result # => "Hello World"
UPDATE
If you want to use variables:
require 'erb'
w = "World"
str = "Hello <%= w %>"
result = ERB.new(str).result(binding) # => "Hello World"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With