Skip to content

Instantly share code, notes, and snippets.

@gmgent
Created April 29, 2012 19:53
Show Gist options
  • Save gmgent/2552946 to your computer and use it in GitHub Desktop.
Save gmgent/2552946 to your computer and use it in GitHub Desktop.
def to_boolean(value, nil_value = false)
compare_value = value.class == String ? value.downcase : value
case compare_value
when "no","false",false, "0", 0
false
when "yes","true",true, "1", 1
true
when nil
nil_value
else
!!compare_value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment