Skip to content

Instantly share code, notes, and snippets.

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) }
# irc chan said to drop the to_sym but I like having the failsafe
# also thinking about maybe has_any? & has_all? for clarification
<% if @instance.has? :city, :state, :zipcode -%>
<p class="address">
<%= %><% if @instance.has? :city -%>, <% end -%><%= @instance.state %> <%= @instance.zipcode %>
<% end -%>
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