Class: BooleanTypecaster

Inherits:
Typecaster show all
Defined in:
lib/type_casters.rb

Overview

Casts a value to a boolean. ‘1’, ‘t’ or ‘true’ (case ignored) will evaluate to true, otherwise the result will be false.

Instance Method Summary collapse

Methods inherited from Typecaster

registered_typecasters, typecaster_for

Instance Method Details

#typeObject



50
# File 'lib/type_casters.rb', line 50

def type; 'boolean' end

#typecast(value) ⇒ Object



52
53
54
# File 'lib/type_casters.rb', line 52

def typecast(value)
  !(/^(1|t|true)$/i =~ value.to_s).nil?
end