Skip to content

Instantly share code, notes, and snippets.

@tobiashm
Created October 24, 2016 20:21
Show Gist options
  • Save tobiashm/40c09485e76ce0a9f416fbaaa5dbee2b to your computer and use it in GitHub Desktop.
Save tobiashm/40c09485e76ce0a9f416fbaaa5dbee2b to your computer and use it in GitHub Desktop.
Boolean conversion method in Ruby
module Kernel
def Boolean(input)
case input
when true, /^(true|y|yes|1)$/i, 1
true
when false, /^(false|n|no|0)$/i, 0, "", nil
false
else
fail TypeError, "can't convert #{input.inspect} into boolean"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment