Skip to content

Instantly share code, notes, and snippets.

@rodolfobandeira
Created April 7, 2019 13:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodolfobandeira/e3e908e64dc62db0db86b115e45b059f to your computer and use it in GitHub Desktop.
Save rodolfobandeira/e3e908e64dc62db0db86b115e45b059f to your computer and use it in GitHub Desktop.
Convert string to boolean in Ruby
  def to_bool(string)
    if string == true || string == 1 || string =~ (/(true|1)$/i)
      true
    else
      false
    end
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment