htmlruby-on-railsrubyhamleruby

Under what cirumstances would I need eruby if I'm just doing Ruby programming


As I understand it, eruby is like erb - it lets you stick ruby code into HTML. If someone is using Rails, more than likely they would use erb or Haml.

But if I'm not using Rails, under what cirumstances would I need eruby if I'm just doing Ruby programming?

I guess I don't understand why someone would need to be outputting HTML if they're just using Ruby for writing scripts.


Solution

  • eRuby isn't just for HTML - it allows you to embed ruby into any arbitrary text. I've seen it used in scripts that generate Apache configuration files, for instance - it's generally useful if you have any sort of text-based output that needs some dynamic content, as an eRuby template can often be easier to read than a bunch of string concatenation or interpolation.