<p>What's the difference between eruby and erb?  What considerations would drive me to choose one or the other?</p>

<p>My application is generating config files for network devices (routers, load balancers, firewalls, etc.).  My plan is to template the config files, using embedded ruby (via either eruby or erb) within the source files to do things like iteratively generate all the interface config blocks for a router (these blocks are all very similar, differing only in a label and an IP address).  For example, I might have a config template file like this:</p>

<pre><code>hostname sample-router
&lt;%=
r = String.new;
[
    ["GigabitEthernet1/1", "10.5.16.1"],
    ["GigabitEthernet1/2", "10.5.17.1"],
    ["GigabitEthernet1/3", "10.5.18.1"]
].each { |tuple|
    r &lt;&lt; "interface #{tuple[0]}\n"
    r &lt;&lt; "    ip address #{tuple[1]} netmask 255.255.255.0\n"
}
r.chomp
%&gt;
logging 10.5.16.26
</code></pre>

<p>which, when run through an embedded ruby interpreter (either erb or eruby), produces the following output:</p>

<pre><code>hostname sample-router
interface GigabitEthernet1/1
    ip address 10.5.16.1 netmask 255.255.255.0
interface GigabitEthernet1/2
    ip address 10.5.17.1 netmask 255.255.255.0
interface GigabitEthernet1/3
    ip address 10.5.18.1 netmask 255.255.255.0
logging 10.5.16.26
</code></pre>

[{'answer_id': 74807, 'author': 'Jordi Bunster', 'author_id': 4272, 'author_profile': 'https://Stackoverflow.com/users/4272', 'pm_score': 3, 'selected': False, 'text': "<p>Doesn't really matter, they're both the same. erb is pure ruby, eruby is written in C so it's a bit faster.</p>\n\n<p>erubis (a third one) is pure ruby, and faster than both the ones listed above. But I doubt the speed of that is the bottleneck for you, so just use erb. It's part of Ruby Standard Library.</p>\n"}, {'answer_id': 74823, 'author': 'Daniel Spiewak', 'author_id': 9815, 'author_profile': 'https://Stackoverflow.com/users/9815', 'pm_score': 2, 'selected': False, 'text': "<p>Eruby is an external executable, while erb is a library within Ruby.  You would use the former if you wanted independent processing of your template files (e.g. quick-and-dirty PHP replacement), and the latter if you needed to process them within the context of some other Ruby script.  It is more common to use ERB simply because it is more flexible, but I'll admit that I have been guilty of dabbling in eruby to execute <code>.rhtml</code> files for quick little utility websites.</p>\n"}, {'answer_id': 81574, 'author': 'Jon Wood', 'author_id': 25258, 'author_profile': 'https://Stackoverflow.com/users/25258', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m doing something similar using erb, and the performance is fine for me.</p>\n\n<p>As Jordi said though, it depends what context you want to run this in - if you\'re literally going to use templates like the one you listed, eruby would probably work better, but I\'d guess you\'re actually going to be passing variables to the template, in which case you want erb.</p>\n\n<p>Just for reference, when using erb you\'ll need to pass it the binding for the object you want to take variables from, something like this:</p>\n\n<pre><code>device = Device.new\ndevice.add_interface("GigabitEthernet1/1", "10.5.16.1")\ndevice.add_interface("GigabitEthernet1/2", "10.5.17.1")\n\ntemplate = File.read("/path/to/your/template.erb")\nconfig = ERB.new(template).result(device.binding)\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/74782', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13157/']