Class: Attribool::Value
- Inherits:
-
Object
- Object
- Attribool::Value
- Defined in:
- lib/attribool/value.rb
Overview
An abstraction of any class that can convert itself to a boolean.
Instance Method Summary collapse
-
#initialize(value, condition = nil) ⇒ Value
constructor
Construct the value with an optional
Proc
condition. -
#to_boolean ⇒ Boolean
Convert the value or the condition to a boolean based off truthiness.
Constructor Details
#initialize(value, condition = nil) ⇒ Value
Construct the value with an optional Proc
condition.
13 14 15 16 17 |
# File 'lib/attribool/value.rb', line 13 def initialize(value, condition = nil) ValidatorService.call(:condition, condition) @value = value @condition = condition end |
Instance Method Details
#to_boolean ⇒ Boolean
Convert the value or the condition to a boolean based off truthiness.
23 24 25 |
# File 'lib/attribool/value.rb', line 23 def to_boolean !!(@condition ? @condition.call(@value) : @value) end |