Skip to content

Instantly share code, notes, and snippets.

@VasylShevchenko
Created February 16, 2020 09:54
Show Gist options
  • Save VasylShevchenko/2f8f7a739d1b0272f596f33c1b13c597 to your computer and use it in GitHub Desktop.
Save VasylShevchenko/2f8f7a739d1b0272f596f33c1b13c597 to your computer and use it in GitHub Desktop.
class String
def to_boolean
ActiveRecord::Type::Boolean.new.cast(self)
end
end
class NilClass
def to_boolean
false
end
end
class TrueClass
def to_boolean
true
end
def to_i
1
end
end
class FalseClass
def to_boolean
false
end
def to_i
0
end
end
class Integer
def to_boolean
to_s.to_boolean
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment