/ Published in: Ruby
injects .to_bool instance method into NilClass, TrueClass, FalseClass, Numeric & String
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
module ToBoolean def to_bool return true if self == true || self.to_s.strip =~ /^(true|t|yes|y|1)$/i return false end end class NilClass; include ToBoolean; end class TrueClass; include ToBoolean; end class FalseClass; include ToBoolean; end class Numeric; include ToBoolean; end class String; include ToBoolean; end