Module: Naught::InstanceMethods

Defined in:
lib/naught_check.rb

Instance Method Summary collapse

Instance Method Details

#aught?Boolean

inverts naught?

Returns:

  • (Boolean)


37
# File 'lib/naught_check.rb', line 37

def aught?; !naught?; end

#naught?Boolean

Tests if a value if nil, blank, or zero

nil.naught? => true
"".naught? => true
"    ".naught? => true
[].naught? => true
{}.naught? => true
0.naught? => true
0.00.naught? => true

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/naught_check.rb', line 13

def naught?
  if self == nil
    true
  elsif self.kind_of? Array
    self.size == 0
  elsif self.kind_of? Hash
    self.keys.size == 0
  elsif self.kind_of? Numeric
    self.zero?
  elsif self.kind_of? String
    self == "" || (/^\s*$/.match(self) != nil)
  else
    false
  end
end

#nought?Boolean

aliases .naught?

Returns:

  • (Boolean)


30
# File 'lib/naught_check.rb', line 30

def nought?; naught?; end

#nowt?Boolean

aliases .naught?

Returns:

  • (Boolean)


33
# File 'lib/naught_check.rb', line 33

def nowt?; naught?; end

#ought?Boolean

aliases .aught?

Returns:

  • (Boolean)


40
# File 'lib/naught_check.rb', line 40

def ought?; aught?; end

#owt?Boolean

aliases .aught?

Returns:

  • (Boolean)


43
# File 'lib/naught_check.rb', line 43

def owt?; aught?; end