Sha256: 62727eb0041573705f7821bbec5e9ef316f6cdd4d25df0047b77f4ed78924bbb
Contents?: true
Size: 649 Bytes
Versions: 3
Compression:
Stored size: 649 Bytes
Contents
# frozen_string_literal: true module Attribool ## # An abstraction of any class that can convert itself to a boolean. class Value ## # Construct the value with an optional +Proc+ condition. # # @param [Object] value # # @param [Proc] condition (default: nil) def initialize(value, condition = nil) ValidatorService.call(:condition, condition) @value = value @condition = condition end ## # Convert the value or the condition to a boolean based off truthiness. # # @return [Boolean] def to_boolean !!(@condition ? @condition.call(@value) : @value) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
attribool-2.0.5 | lib/attribool/value.rb |
attribool-2.0.4 | lib/attribool/value.rb |
attribool-2.0.3 | lib/attribool/value.rb |