Skip to content

Files

Latest commit

 

History

History
46 lines (31 loc) · 585 Bytes

Rails-Presence.md

File metadata and controls

46 lines (31 loc) · 585 Bytes

Pattern: Missing use of Object#presence

Issue: -

Description

This rule checks code that can be written more easily using Object#presence defined by Active Support.

Examples

# bad
a.present? ? a : nil

# bad
!a.present? ? nil : a

# bad
a.blank? ? nil : a

# bad
!a.blank? ? a : nil

# good
a.presence
# bad
a.present? ? a : b

# bad
!a.present? ? b : a

# bad
a.blank? ? b : a

# bad
!a.blank? ? a : b

# good
a.presence || b

Further Reading