Last active
December 17, 2015 08:49
-
-
Save nicolasblanco/5582734 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Virtus.coercer do |config| | |
| config.string.boolean_map = { 'true' => true, 'false' => false } | |
| end | |
| class BookingWizard | |
| include Virtus | |
| extend ActiveModel::Naming | |
| include ActiveModel::Conversion | |
| include ActiveModel::Validations | |
| attribute :know_doctor, Boolean, default: false | |
| end | |
| 1.9.3 (main):0 > b = BookingWizard.new | |
| => #<BookingWizard:0x007fea748bf338 | |
| @know_doctor=false> | |
| 1.9.3 (main):0 > b.know_doctor = "true" | |
| => "true" | |
| 1.9.3 (main):0 > b.know_doctor | |
| => "true" | |
| 1.9.3 (main):0 > b.know_doctor.class | |
| => String | |
| 1.9.3 (main):0 > Virtus.coercer[String].to_boolean("true") | |
| => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment