Skip to content
ERB-like mruby gem
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.


This is a mruby gem provinding an ERB-like mechanism for converting template files with embedded mruby code.


Simply add the following line to your build_config.rb file in mruby root:

conf.gem :github => "pbosetti/mruby-merb", :branch => "master"

and then recompile mruby with make clean; make.


Due to the fact that mruby lacks the Binding class, values must be passed from toplevel (or calling scope) to the code within the template by using global variables, as in the following example:

merb = "The value of $x is: <%= $x -%>"
$x = 2.3
result =
puts result #=> The value of $x is: 2.3

Of course you can load the template string from an external file:

merb =
result = merb.convert("test.erb")

Supported erb tags

  • <% ... %>: standard ruby code execution (no printout)
  • <%= ... %>: execute and insert the resulting value as a string; adds a newline
  • <%= ... -%>: execute and insert the resulting value as a string; no newline added (note the dash in the closing tag!)

An arbitrary pair of opening and closing tags can be specified instead of the <% and %> default:

merb.tags[:open] = '{-'
merb.tags[:close] = '-}'
You can’t perform that action at this time.