File: blank.rb

package info (click to toggle)
ruby-sequel 5.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,408 kB
  • sloc: ruby: 113,747; makefile: 3
file content (57 lines) | stat: -rw-r--r-- 923 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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