Created
December 24, 2008 20:29
-
-
Save wuputah/39763 to your computer and use it in GitHub Desktop.
This file contains 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
# All the places I used !! in a very sizable project | |
# (4 cases in 7600 LOC, about 40% of which is specs) | |
# ActiveRecord callback - writing to a DB: | |
def update_has_emailable_accounts! | |
# !! replaces "condition ? true : false" | |
self.update_attribute(:has_emailable_accounts, !!accounts.detect { |account| account.emailable? }) | |
end | |
# AR validation helper predicate: | |
def valid_url?(url) | |
!! (url =~ %r[^https?://.]i) | |
end | |
# application.rb - user? predicate: | |
def user? | |
!! current_user | |
end | |
helper_method :user? | |
# In a custom validation I wrote - returns true/false instead of... true/nil. | |
# I'd only justify this because its a predicate, but this is certainly | |
# my least solid usage. | |
def has_uniqueness_errors? | |
!! @has_uniqueness_errors | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment