Created
May 24, 2011 16:09
-
-
Save joemsak/989013 to your computer and use it in GitHub Desktop.
instance has?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% if @instance.has? :city, :state, :zipcode -%> | |
<p class="address"> | |
<%= @instance.city %><% if @instance.has? :city -%>, <% end -%><%= @instance.state %> <%= @instance.zipcode %> | |
</p> | |
<% end -%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment