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, #typecast_on_write?, typecaster_for

Instance Method Details

#typeObject



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

def type; 'boolean' end

#typecast(value) ⇒ Object



67
68
69
# File 'lib/type_casters.rb', line 67

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