Class: String

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

Instance Method Summary collapse

Instance Method Details

#to_b(when_not_recognized = :raise) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/truther.rb', line 15

def to_b(when_not_recognized=:raise)
	sanitized_string = self.downcase.strip
	return true if Truther::TRUTHY_STRINGS.include? sanitized_string
	return false if Truther::FALSY_STRINGS.include? sanitized_string
	
	if when_not_recognized == :raise
		raise Truther::NeitherTrueNorFalseError.new sanitized_string
	else
		when_not_recognized
	end
end