Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. # All the places I used !! in a very sizable project
  2. # (4 cases in 7600 LOC, about 40% of which is specs)
  3.  
  4. # ActiveRecord callback - writing to a DB:
  5.  
  6. def update_has_emailable_accounts!
  7. # !! replaces "condition ? true : false"
  8. self.update_attribute(:has_emailable_accounts, !!accounts.detect { |account| account.emailable? })
  9. end
  10.  
  11. # AR validation helper predicate:
  12.  
  13. def valid_url?(url)
  14. !! (url =~ %r[^https?://.]i)
  15. end
  16.  
  17. # application.rb - user? predicate:
  18.  
  19. def user?
  20. !! current_user
  21. end
  22. helper_method :user?
  23.  
  24. # In a custom validation I wrote - returns true/false instead of... true/nil.
  25. # I'd only justify this because its a predicate, but this is certainly
  26. # my least solid usage.
  27.  
  28. def has_uniqueness_errors?
  29. !! @has_uniqueness_errors
  30. end
Add Comment
Please, Sign In to add comment