500 template = ERB.new("The value of x is: <%= x %>") puts template.result(binding) The resulting text looks like this: The value of x is: 500 Execution tags <% %> : Code enclosed in such tags is called as a scriptlet. The code in such a tag gets executed and its result gets replaced in place of the scriptlet. Such tags must have a matching <% end %> tag to denote the end of a functional block. For example: <ul> <% 4.times do %> <li>list item</li> <% end %> </ul> In the above example, the text list item gets printed four times. The scriptlet produces no text on its own, it only makes the enclosed statement to run multiple times. The output of above code: list item list item list item list item Comments tags <%# %> : Contents of comment tags don't get rendered in the output. Such tags start with an open tag delimiter followed by a hash symbol and end with an end tag delimiter. Example of a comment tag is shown below: <%# ruby code %> This is the same as a comment in Ruby. All Ruby code after the # is ignored and generates nothing. Other tags Other things common in eRuby are simply common in Ruby, such as string substitution with #{string_name}, which is similar in languages such as Perl or PHP. Newlines in eRuby can be suppressed by adding a hyphen at the beginning of the end tag delimiter. For example: <%2.times do -%> <%= @name %> <% end -%>In the output of the above code, the value of name gets printed twice in the same line. Implementations There are several implementations of eRuby, namely: ERB erubis ember erb erb is an implementation of eRuby written purely in the Ruby programming language and included in the Ruby standard library. A template can be generated by running a piece of code written using the ERB object. A simple example is as shown below: require 'erb' x = 400 simple_template = "Value of x is: is <%= x %>." renderer = ERB.new(simple_template) puts output = renderer.result(binding) The result looks as follows: Value of x is: 400 The same could be achieved using the below code which does not make use of an ERB object:x = 400 string = "The value of x is: #{x}" puts stringBoth of the above code snippets generate the same output. But