Module: YiffSpace::Extensions::Object::TruthyFalsy

Included in:
Object
Defined in:
lib/yiffspace/extensions/object/truthy_falsy.rb

Instance Method Summary collapse

Instance Method Details

#falsy?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/yiffspace/extensions/object/truthy_falsy.rb', line 20

def falsy?
  case self
  when ::String
    match?(/\A(false|f|no|n|off|0)\z/i)
  when ::TrueClass
    false
  when ::FalseClass
    true
  else
    to_s.falsy?
  end
end

#truthy?Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/yiffspace/extensions/object/truthy_falsy.rb', line 7

def truthy?
  case self
  when ::String
    match?(/\A(true|t|yes|y|on|1)\z/i)
  when ::TrueClass
    true
  when ::FalseClass
    false
  else
    to_s.truthy?
  end
end