Sha256: 26c3ab696b4be9cdccb8901603c9725285f83be1966625f7c735e554bba30b70

Contents?: true

Size: 923 Bytes

Versions: 66

Compression:

Stored size: 923 Bytes

Contents

# frozen-string-literal: true
#
# The blank extension adds the blank? method to all objects (e.g. Object#blank?).
#
# To load the extension:
#
#   Sequel.extension :blank

[FalseClass, Object, NilClass, Numeric, String, TrueClass].each do |klass|
  # :nocov:
  if klass.method_defined?(:blank?)
    klass.send(:alias_method, :blank?, :blank?)
  end
  # :nocov:
end

class FalseClass
  # false is always blank
  def blank?
    true
  end
end

class Object
  # Objects are blank if they respond true to empty?
  def blank?
    respond_to?(:empty?) && empty?
  end
end

class NilClass
  # nil is always blank
  def blank?
    true
  end
end

class Numeric
  # Numerics are never blank (not even 0)
  def blank?
    false
  end
end

class String
  # Strings are blank if they are empty or include only whitespace
  def blank?
    strip.empty?
  end
end

class TrueClass
  # true is never blank
  def blank?
    false
  end
end

Version data entries

66 entries across 59 versions & 3 rubygems

Version Path
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/sequel-5.53.0/lib/sequel/extensions/blank.rb
sequel-5.53.0 lib/sequel/extensions/blank.rb
sequel-5.52.0 lib/sequel/extensions/blank.rb
sequel-5.51.0 lib/sequel/extensions/blank.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/blank.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/sequel-5.50.0/lib/sequel/extensions/blank.rb
sequel-5.50.0 lib/sequel/extensions/blank.rb
sequel-5.49.0 lib/sequel/extensions/blank.rb
sequel-5.48.0 lib/sequel/extensions/blank.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/blank.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/sequel-5.47.0/lib/sequel/extensions/blank.rb
sequel-5.47.0 lib/sequel/extensions/blank.rb
sequel-5.46.0 lib/sequel/extensions/blank.rb
sequel-5.45.0 lib/sequel/extensions/blank.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/blank.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.41.0/lib/sequel/extensions/blank.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/sequel-5.41.0/lib/sequel/extensions/blank.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/sequel-5.44.0/lib/sequel/extensions/blank.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.43.0/lib/sequel/extensions/blank.rb
only_blank-1.0.0 lib/blank.rb