Last active
December 16, 2021 16:34
Revisions
-
equivalent revised this gist
Dec 16, 2021 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ This gist was writen in 2012 and it was solving specific problem in Rails & SimpleForm. Some fellow developers were pointing out this may be out dated concept. That's why I advise everyone to read comment section bellow to have a full grasp of alternative solutions other sources that may be helpful to understand why this may not be best idea: * [Why Ruby doesn’t have a Boolean class](https://www.rubytapas.com/2019/01/08/boolean/) -
equivalent renamed this gist
Feb 19, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
equivalent revised this gist
Feb 19, 2013 . 1 changed file with 29 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ # However there is also better practice to do it by using ActiveRecord::ConnectionAdapters::Column.value_to_boolean( something ) 2.0.0dev :019 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean('1') => true 2.0.0dev :020 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean('0') => false 2.0.0dev :021 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean('true') => true 2.0.0dev :022 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean('false') => false 2.0.0dev :023 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean('nil') => false 2.0.0dev :024 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean('t') => true 2.0.0dev :025 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean('cat') => false 2.0.0dev :026 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean(true) => true 2.0.0dev :027 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean(false) 2.0.0dev :035 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean(1) => true 2.0.0dev :036 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean(2) => false 2.0.0dev :037 > ActiveRecord::ConnectionAdapters::Column.value_to_boolean(0) => false -
equivalent revised this gist
Feb 19, 2013 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,8 +7,9 @@ def to_bool end class String; include StringToBoolean; end module BooleanToBoolean def to_bool;return self; end end class TrueClass; include BooleanToBoolean; end class FalseClass; include BooleanToBoolean; end -
equivalent revised this gist
Oct 3, 2012 . No changes.There are no files selected for viewing
-
equivalent revised this gist
Oct 3, 2012 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,14 @@ module StringToBoolean def to_bool return true if self == true || self =~ (/^(true|t|yes|y|1)$/i) return false if self == false || self.blank? || self =~ (/^(false|f|no|n|0)$/i) raise ArgumentError.new("invalid value for Boolean: \"#{self}\"") end end class String; include StringToBoolean; end module Boolean def to_bool;return self; end end class TrueClass; include Boolean; end class FalseClass; include Boolean; end -
equivalent revised this gist
Oct 3, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ class String def to_bool return true if self == true || self =~ (/^(true|t|yes|y|1)$/i) return false if self == false || self.blank? || self =~ (/^(false|f|no|n|0)$/i) raise ArgumentError.new("invalid value for Boolean: \"#{self}\"") end end -
equivalent created this gist
Oct 3, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ class String def to_bool return true if self == true || self =~ (/^(true|t|yes|y|1)$/i) return false if self == false || self.blank? || self =~ (^/(false|f|no|n|0)$/i) raise ArgumentError.new("invalid value for Boolean: \"#{self}\"") end end