Class: RustyKey::Conditional
- Inherits:
-
Object
- Object
- RustyKey::Conditional
- Defined in:
- lib/rusty_key/boolean.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #else(&action) ⇒ Object
- #else!(&action) ⇒ Object
- #elsif(condition, &action) ⇒ Object (also: #else_if)
- #to_proc ⇒ Object
Class Method Details
.if(action, condition) ⇒ Object
81 82 83 |
# File 'lib/rusty_key/boolean.rb', line 81 def if(action, condition) new(action, false, condition) end |
.unless(action, condition) ⇒ Object
84 85 86 |
# File 'lib/rusty_key/boolean.rb', line 84 def unless(action, condition) new(action, true, condition) end |
Instance Method Details
#call ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/rusty_key/boolean.rb', line 98 def call if found result&.call else otherwise&.call end end |
#else(&action) ⇒ Object
106 107 108 109 |
# File 'lib/rusty_key/boolean.rb', line 106 def else(&action) self.otherwise = action self end |
#else!(&action) ⇒ Object
111 112 113 114 |
# File 'lib/rusty_key/boolean.rb', line 111 def else!(&action) self.else(&action) self.call end |
#elsif(condition, &action) ⇒ Object Also known as: else_if
89 90 91 92 93 94 95 |
# File 'lib/rusty_key/boolean.rb', line 89 def elsif(condition, &action) if !found && check(condition) self.found = true self.result = action end self end |
#to_proc ⇒ Object
116 117 118 |
# File 'lib/rusty_key/boolean.rb', line 116 def to_proc -> { self.call } end |