class RustyKey::Conditional
Attributes
found[RW]
otherwise[RW]
result[RW]
Public Class Methods
if(action, condition)
click to toggle source
# File lib/rusty_key/boolean.rb, line 81 def if(action, condition) new(action, false, condition) end
new(action, negate, condition)
click to toggle source
# File lib/rusty_key/boolean.rb, line 73 def initialize(action, negate, condition) self.found = negate ? !check(condition) : check(condition) self.result = found ? action : -> {} end
unless(action, condition)
click to toggle source
# File lib/rusty_key/boolean.rb, line 84 def unless(action, condition) new(action, true, condition) end
Public Instance Methods
call()
click to toggle source
# File lib/rusty_key/boolean.rb, line 98 def call if found result&.call else otherwise&.call end end
else(&action)
click to toggle source
# File lib/rusty_key/boolean.rb, line 106 def else(&action) self.otherwise = action self end
else!(&action)
click to toggle source
# File lib/rusty_key/boolean.rb, line 111 def else!(&action) self.else(&action) self.call end
elsif(condition, &action)
click to toggle source
# 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
Also aliased as: else_if
to_proc()
click to toggle source
# File lib/rusty_key/boolean.rb, line 116 def to_proc -> { self.call } end
Private Instance Methods
check(condition)
click to toggle source
# File lib/rusty_key/boolean.rb, line 63 def check(condition) if condition.respond_to?(:call) !!condition.call else !!condition end end