Class: Contracts::Stringy::Bool

Inherits:
Object
  • Object
show all
Defined in:
lib/contracts/stringy.rb

Overview

A string that is equal to either ‘true’, ‘false’, ‘0’, or ‘1’.

Class Method Summary collapse

Class Method Details

.generate(*args) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/contracts/stringy.rb', line 53

def self.generate(*args)
  if Contracts::Builtin::Bool.generate
    Contracts::Builtin::Bool.generate(*args) ? 'true' : '1'
  else
    Contracts::Builtin::Bool.generate(*args) ? 'false' : '0'
  end
end

.valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/contracts/stringy.rb', line 49

def self.valid?(value)
  value.is_a? String and value == 'true' or value == 'false' or value == "0" or value == "1"
end