Heads up: This description was created by AI and might not be 100% accurate.
read_file_direct.rb
This Ruby code snippet demonstrates the use of the ERB
(Embedded Ruby) template engine. It first requires the erb
library. Then, it reads the contents of an ERB file (file.html.erb
), creates an ERB
object from it, and evaluates the template using the current binding
. The result is a string containing the rendered HTML, in this case a header and an empty paragraph.
Ruby code snippet
require 'erb'
#=> true
ERB.new(File.read('input/erb/file.html.erb')).result(binding)
#=> "<h1>header</h1>\n\n<p></p>\n"
Executed with Ruby 3.4.5
.