Embedded Ruby : Embedded Ruby « Development « Ruby






Embedded Ruby


# Embedded Ruby (ERB or eRuby) embeds arbitrary Ruby code in text files. 
# The code is executed when the file is processed. 
# ERB comes with the Ruby distribution. 
# It's very common to embed code in HTML or XHTML.

#!/usr/bin/env ruby

require 'erb'

person = "myValue!"

temp = ERB.new( "Hello, <%= person %>" )

puts temp.result( binding ) # => Hello, myValue!

 








Related examples in the same category

1.Embedded in the string are a pair of template tags, <%= and %>.
2.ERB template tags
3.ERB tags in a string
4.Nested ERB block