Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean values #2

Open
hmcfletch opened this issue Jul 28, 2021 · 0 comments
Open

Boolean values #2

hmcfletch opened this issue Jul 28, 2021 · 0 comments

Comments

@hmcfletch
Copy link
Collaborator

Use the following for true and false values:

FALSE_BASE = [false, 0, 'off', 'f'].freeze
TRUE_BASE = [true, 1, 'on', 't'].freeze

def boolean_variants(base)
  base.map { |f| s = f.to_s; [f, s.downcase, s.downcase.to_sym, s.upcase, s.upcase.to_sym] }.flatten.uniq
end

TRUE_VALUES = boolean_variants(TRUE_BASE).to_set.freeze
# #<Set: {true, "true", :true, "TRUE", :TRUE, 1, "1", :"1", "on", :on, "ON", :ON, "t", :t, "T", :T}>

FALSE_VALUES = boolean_variants(FALSE_BASE).to_set.freeze
# #<Set: {false, "false", :false, "FALSE", :FALSE, 0, "0", :"0", "off", :off, "OFF", :OFF, "f", :f, "F", :F}>

See ActiveRecord::Type::Boolean for the inspiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant