Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
instance has?
class Example < ActiveRecord::Base
#...
# would this be cool to have, or am I daft?
def has? *args
args.any? { |a| send(a.to_sym) }
end
# irc chan said to drop the to_sym but I like having the failsafe
# also thinking about maybe has_any? & has_all? for clarification
#...
end
<% if @instance.has? :city, :state, :zipcode -%>
<p class="address">
<%= @instance.city %><% if @instance.has? :city -%>, <% end -%><%= @instance.state %> <%= @instance.zipcode %>
</p>
<% end -%>
@citrus
Copy link

citrus commented May 24, 2011

I like it :)

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