Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
Add Comment
Please, Sign In to add comment