Module: MethodChain
- Included in:
- Object
- Defined in:
- lib/methodchain/not-included.rb
Overview
:main: README
Instance Method Summary collapse
-
#and(*guards, &block) ⇒ Object
with no guards, is equivalent to self && yield_or_eval(&block) && self same as:
self.then(*guards, &block) && self
. -
#chain(*messages, &guard) ⇒ Object
method chaining with a guard.
-
#else(*guards, &block) ⇒ Object
return self if self or a guard evaluates to true otherwise return the evaluation of the block.
-
#or(*guards, &block) ⇒ Object
with no guards, is equivalent to
self || (yield_or_eval(&block) && self)
same as:self.else(*guards, &block) && self
. -
#tap(*messages, &block) ⇒ Object
send messages, evaluate blocks, but always return self.
-
#then(*guards, &block) ⇒ Object
return self if self or a guard evaluates to false, otherwise return the evaluation of the block.
Instance Method Details
#and(*guards, &block) ⇒ Object
with no guards, is equivalent to self && yield_or_eval(&block) && self same as: self.then(*guards, &block) && self
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/methodchain/not-included.rb', line 81 def and *guards, &block if guards.empty? return self if not self else guards.each do |cond| return self if not send_as_function(cond) end end block_given? ? (yield_or_eval(&block) && self) : self end |
#chain(*messages, &guard) ⇒ Object
method chaining with a guard. If no guard block is given then guard against nil and false
44 45 46 47 48 49 |
# File 'lib/methodchain/not-included.rb', line 44 def chain *, &guard return self if .empty? or not( (block_given? ? (yield_or_eval(&guard)) : self)) (send_as_function (.shift)).chain(*, &guard) end |
#else(*guards, &block) ⇒ Object
return self if self or a guard evaluates to true otherwise return the evaluation of the block
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/methodchain/not-included.rb', line 67 def else *guards, &block if guards.empty? return self if self else guards.each do |cond| return self if send_as_function(cond) end end block_given? ? yield_or_eval(&block) : self end |
#or(*guards, &block) ⇒ Object
with no guards, is equivalent to self || (yield_or_eval(&block) && self)
same as: self.else(*guards, &block) && self
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/methodchain/not-included.rb', line 95 def or *guards, &block if guards.empty? return self if self else guards.each do |cond| return self if send_as_function(cond) end end block_given? ? yield_or_eval(&block) : self end |
#tap(*messages, &block) ⇒ Object
send messages, evaluate blocks, but always return self
36 37 38 39 40 |
# File 'lib/methodchain/not-included.rb', line 36 def tap *, &block send_as_functions * unless .empty? yield_or_eval(&block) if block_given? self end |
#then(*guards, &block) ⇒ Object
return self if self or a guard evaluates to false, otherwise return the evaluation of the block
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/methodchain/not-included.rb', line 53 def then *guards, &block if guards.empty? return self if not self else guards.each do |cond| return self if not send_as_function(cond) end end block_given? ? yield_or_eval(&block) : self end |