You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Usually, it's [Array, nil] or [Model, nil], and usage of present?/blank? is superfluous.
Array/Hash/NilClass/TrueClass/FalseClass/String and an arbitrary Object define those methods, disguising the exact object type. blank? and present? in the Rails Guides
I'd suggest:
using .nil? or an implicit check when it's only important if it's nil or not:
returnifuser.nil?# orreturnunlessuser
using any?/empty?/none? when distinguishing between an empty and non-empty Array/Hash
The only one I really have a strong support for 4. The others can certainly result in clunky code, but I think restricting them may be overly-prescriptive.
If puzzles me what the type of the object is when I read something like:
or
Usually, it's
[Array, nil]
or[Model, nil]
, and usage ofpresent?
/blank?
is superfluous.Array/Hash/NilClass/TrueClass/FalseClass/String and an arbitrary Object define those methods, disguising the exact object type.
blank?
andpresent?
in the Rails GuidesI'd suggest:
.nil?
or an implicit check when it's only important if it'snil
or not:using
any?
/empty?
/none?
when distinguishing between an empty and non-empty Array/Hashfor
ActiveRecord::Relation
, see Faster Rails: Useexists
instead ofpresent?
to check if a Record Exists #232 (comment)3.1 using
any?
overpresent?
3.2 using
empty?
/none?
overblank?
stop using
blank?
/present?
for booleansString
'sblank?
/present?
are a special case, a string with whitespace only isblank?
but notempty?
.cc @marcandre
The text was updated successfully, but these errors were encountered: