what happens when we interchange lines 2 with line 3 in the first code snippet and line 1 with line 2 in the second code snippet? The first snippet changes to the code shown below: require 'erb' simple_template = "Value of x is: is <%= x %>." x = 400 renderer = ERB.new(simple_template) puts output = renderer.result(binding) This still generates the same output. i.e., Value of x is: 400. The second code snippet changes to the below code:string = "The value of x is: #{x}" x = 400 puts stringThe above code will not get executed. This is because the 1st line does not know the value of x when it gets executed. Thus, the main reason of using an ERB object is to write templates ahead of time, by binding variables and methods which may not exist at the given time. The template gets processed only when result is called on the ERB object. In order to get access to instance methods and instance variable of an object, ERB makes use of a binding object. Access to variables and methods of an object is given by the private binding object which exists in each ruby class. It is easy to get access to methods and variables within the method of a class. But to access variables of a different class, that class will have to expose its binding object via a public method. The example is as shown below: class ERBExample attr_accessor:variable1 # using bind to access class variables def render() renderer.result(binding) end def initialize(variable1) @variable1 = variable1 end # Expose private binding() method. def get_binding binding() end end example = ERBExample.new(variable1) renderer = ERB.new(template) puts output = renderer.result(example.get_binding)As we can see in the above example, we are exposing the binding object of the class ERBExample. Furthermore, we have used the binding object to access the variables and methods of the class within one of its methods. new() method of ERB The new method of the ERB object takes two more parameters. The second parameter specifies a safety level. By giving a number in the second parameter (max value = 4) one can make the template run in a different thread. The value of the number determines the safety level. At the maximum isolation level, unless the binding object is marked as trusted, ERB cannot use it. The third parameter specify optional modifiers. These can be used to control