Skip to the content.

read_file_direct.rb(erb)

This Ruby code snippet utilizes the Embedded Ruby (ERB) library to process and evaluate the content of an ERB template file (‘file.html.erb’). It reads the file, interprets embedded Ruby code within it, and produces the final result by applying the specified binding.

Execution:

require 'erb'
#=> true

ERB.new(File.read('file.html.erb')).result(binding)
#=> "<h1>header</h1>\n\n<p></p>\n"

Executed with Ruby 3.3.6