Prefer endless methods
This commit is contained in:
parent
686264f1b0
commit
6472aca1a6
@ -19,9 +19,7 @@ class Object
|
|||||||
|
|
||||||
# An object is present if it's not blank.
|
# An object is present if it's not blank.
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def present?
|
def present? = !blank?
|
||||||
!blank?
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the receiver if it's present otherwise returns +nil+.
|
# Returns the receiver if it's present otherwise returns +nil+.
|
||||||
# <tt>object.presence</tt> is equivalent to
|
# <tt>object.presence</tt> is equivalent to
|
||||||
@ -48,14 +46,10 @@ class NilClass
|
|||||||
#
|
#
|
||||||
# nil.blank? # => true
|
# nil.blank? # => true
|
||||||
sig { returns(TrueClass) }
|
sig { returns(TrueClass) }
|
||||||
def blank?
|
def blank? = true
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { returns(FalseClass) }
|
sig { returns(FalseClass) }
|
||||||
def present? # :nodoc:
|
def present? = false # :nodoc:
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class FalseClass
|
class FalseClass
|
||||||
@ -63,14 +57,10 @@ class FalseClass
|
|||||||
#
|
#
|
||||||
# false.blank? # => true
|
# false.blank? # => true
|
||||||
sig { returns(TrueClass) }
|
sig { returns(TrueClass) }
|
||||||
def blank?
|
def blank? = true
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { returns(FalseClass) }
|
sig { returns(FalseClass) }
|
||||||
def present? # :nodoc:
|
def present? = false # :nodoc:
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class TrueClass
|
class TrueClass
|
||||||
@ -78,14 +68,10 @@ class TrueClass
|
|||||||
#
|
#
|
||||||
# true.blank? # => false
|
# true.blank? # => false
|
||||||
sig { returns(FalseClass) }
|
sig { returns(FalseClass) }
|
||||||
def blank?
|
def blank? = false
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { returns(TrueClass) }
|
sig { returns(TrueClass) }
|
||||||
def present? # :nodoc:
|
def present? = true # :nodoc:
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Array
|
class Array
|
||||||
@ -98,9 +84,7 @@ class Array
|
|||||||
alias blank? empty?
|
alias blank? empty?
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def present? # :nodoc:
|
def present? = !empty? # :nodoc:
|
||||||
!empty?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Hash
|
class Hash
|
||||||
@ -113,9 +97,7 @@ class Hash
|
|||||||
alias blank? empty?
|
alias blank? empty?
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def present? # :nodoc:
|
def present? = !empty? # :nodoc:
|
||||||
!empty?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Symbol
|
class Symbol
|
||||||
@ -126,9 +108,7 @@ class Symbol
|
|||||||
alias blank? empty?
|
alias blank? empty?
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def present? # :nodoc:
|
def present? = !empty? # :nodoc:
|
||||||
!empty?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class String
|
class String
|
||||||
@ -164,9 +144,7 @@ class String
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def present? # :nodoc:
|
def present? = !blank? # :nodoc:
|
||||||
!blank?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Numeric # :nodoc:
|
class Numeric # :nodoc:
|
||||||
@ -175,14 +153,10 @@ class Numeric # :nodoc:
|
|||||||
# 1.blank? # => false
|
# 1.blank? # => false
|
||||||
# 0.blank? # => false
|
# 0.blank? # => false
|
||||||
sig { returns(FalseClass) }
|
sig { returns(FalseClass) }
|
||||||
def blank?
|
def blank? = false
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { returns(TrueClass) }
|
sig { returns(TrueClass) }
|
||||||
def present?
|
def present? = true
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Time # :nodoc:
|
class Time # :nodoc:
|
||||||
@ -190,12 +164,8 @@ class Time # :nodoc:
|
|||||||
#
|
#
|
||||||
# Time.now.blank? # => false
|
# Time.now.blank? # => false
|
||||||
sig { returns(FalseClass) }
|
sig { returns(FalseClass) }
|
||||||
def blank?
|
def blank? = false
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { returns(TrueClass) }
|
sig { returns(TrueClass) }
|
||||||
def present?
|
def present? = true
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user