Use ERB to replace string : replace « String « Ruby






Use ERB to replace string


require 'erb'

template = ERB.new %q{static string <%= food %>!}
food = "bacon"
template.result(binding)           
food = "peanut butter"
template.result(binding)           

puts template.result

 








Related examples in the same category

1.The replace method replaces a string wholesale.
2.Replace a substring