Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/epb_view_models.rb
Overview
Monkey patching to avoid using ActiveRecord::Type::Boolean.new.cast Source: jeffgardner.org/2011/08/04/rails-string-to-boolean-method/
Instance Method Summary collapse
Instance Method Details
#to_bool ⇒ Object
14 15 16 17 18 19 |
# File 'lib/epb_view_models.rb', line 14 def to_bool return true if self == true || self =~ (/(true|t|yes|y|1)$/i) return false if self == false || blank? || self =~ (/(false|f|no|n|0)$/i) raise ArgumentError, "invalid value for Boolean: \"#{self}\"" end |