Heads up: This description was created by AI and might not be 100% accurate.

read_file.rb

This Ruby code snippet demonstrates the use of the ERB library for embedding Ruby code within HTML templates. It reads an ERB file, creates an ERB object, sets a variable @val to “val”, and then uses the result method to render the template, outputting an HTML fragment with the variable’s value.

Ruby code snippet

require 'erb'
#=> true

erb = ERB.new(File.read('input/erb/file.html.erb'))
#=> 
#<ERB:0x00007fdf128c9350

@val = 'val'
#=> "val"

erb.result(binding)
#=> "<h1>header</h1>\n\n<p>val</p>\n"

Executed with Ruby 3.4.5.