Skip to content

Instantly share code, notes, and snippets.

@dscataglini
Created August 26, 2013 19:56
Show Gist options
  • Select an option

  • Save dscataglini/6345908 to your computer and use it in GitHub Desktop.

Select an option

Save dscataglini/6345908 to your computer and use it in GitHub Desktop.
Erb question
# How would you write an erb file that produces exactly the following output
<articles>
<article>Title</article>
<article>Title</article>
<article class=”high”>Title</article>
<article>Title</article>
<article>Title</article>
<article class=”high”>Title</article>
<article>Title</article>
<article>Title</article>
<article class=”high”>Title</article>
<article>Title</article>
<article>Title</article>
<article class=”high”>Title</article>
</articles>
@hedgeye-bnovak

Copy link
Copy Markdown
require 'action_view'
include ActionView::Helpers::TextHelper
erb_input = <<-ERB

ERB

puts ERB.new(erb_input).result

@hedgeye-bnovak

hedgeye-bnovak commented Apr 20, 2021 •

Copy link
Copy Markdown
require 'erb'
require 'action_view'
include ActionView::Helpers::TextHelper
erb_input = <<-ERB_DAT
<articles>
  <% 12.times do |i| %>
    <article class="<%= cycle('', '', "high") %>">Title</article>
  <% end %>
</articles>
ERB_DAT

puts ERB.new(erb_input).result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment