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
module to evaluate an ERB template file. It reads the content of ‘input/erb/file.html.erb’ using File.read
, creates an ERB
object, and then evaluates the template, producing the HTML string “<h1>header</h1>\n\n<p></p>\n” as its result, with the binding
providing access to the current scope.
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
.