Skip to content

Instantly share code, notes, and snippets.

@orend
Last active December 26, 2015 03:09
Show Gist options
  • Select an option

  • Save orend/7084314 to your computer and use it in GitHub Desktop.

Select an option

Save orend/7084314 to your computer and use it in GitHub Desktop.
before:
<%= if profile.has_experience? && profile.experience_public? %>
<p><strong>Experience:</strong> <%= user_profile.experience %></p>
<% end %>
//after
<h2><%= user_profile.full_name %></h2>
<%= user_profile.bio_html %>
<% user_profile.with_experience do %>
<p><strong>Experience:</strong> <%= user_profile.experience %></p>
<% end %>
<% user_profile.with_hobbies do %>
<p><strong>Hobbies:<strong> <%= user_profile.hobbies %></p>
<% end %>
class ProfilePresenter < ::Presenter
def with_experience(&block)
if profile.has_experience? && profile.experience_public?
block.call(view)
end
end
end
from http://www.saturnflyer.com/blog/jim/2013/10/21/how-to-make-your-code-imply-responsibilities/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment