" To b...">

How to render a string as an erb file?

How to edit a line as erb file rendering.

For example, I want this line:

"Hello <%= 'World'%>" 

To be:

 "Hello World" 

How can i do this?

+6
source share
1 answer

If I understand you correctly, this will be useful:

 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" 
+18
source

Source: https://habr.com/ru/post/900522/


All Articles