Skip to content

Instantly share code, notes, and snippets.

View alistairholt's full-sized avatar

Alistair Holt alistairholt

View GitHub Profile
@alistairholt
alistairholt / boolean_value.rb
Created November 7, 2018 11:32 — forked from attenzione/boolean_value.rb
Ruby: casting to boolean value
class BooleanValue
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/column.rb#L8
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF']
def self.from_string(value)
Rails.present? ? with_rails(value) : without_rails(value)
end
private