Class: Hollaback::Sequence
- Inherits:
-
Object
- Object
- Hollaback::Sequence
- Defined in:
- lib/hollaback/sequence.rb
Instance Attribute Summary collapse
-
#afters ⇒ Object
readonly
Returns the value of attribute afters.
-
#befores ⇒ Object
readonly
Returns the value of attribute befores.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
Instance Method Summary collapse
- #after(&after) ⇒ Object
-
#around(&around) ⇒ Object
rubocop:disable Performance/RedundantBlockCall.
- #before(&before) ⇒ Object
- #call(target) ⇒ Object
-
#initialize(args = {}, &main) ⇒ Sequence
constructor
A new instance of Sequence.
Constructor Details
#initialize(args = {}, &main) ⇒ Sequence
Returns a new instance of Sequence.
5 6 7 8 9 |
# File 'lib/hollaback/sequence.rb', line 5 def initialize(args = {}, &main) @main = main @befores = args.fetch(:befores, []) @afters = args.fetch(:afters, []) end |
Instance Attribute Details
#afters ⇒ Object (readonly)
Returns the value of attribute afters.
3 4 5 |
# File 'lib/hollaback/sequence.rb', line 3 def afters @afters end |
#befores ⇒ Object (readonly)
Returns the value of attribute befores.
3 4 5 |
# File 'lib/hollaback/sequence.rb', line 3 def befores @befores end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
3 4 5 |
# File 'lib/hollaback/sequence.rb', line 3 def main @main end |
Instance Method Details
#after(&after) ⇒ Object
16 17 18 19 |
# File 'lib/hollaback/sequence.rb', line 16 def after(&after) afters << after self end |
#around(&around) ⇒ Object
rubocop:disable Performance/RedundantBlockCall
22 23 24 25 26 |
# File 'lib/hollaback/sequence.rb', line 22 def around(&around) Sequence.new do |target| around.call(target) { call(target) } end end |
#before(&before) ⇒ Object
11 12 13 14 |
# File 'lib/hollaback/sequence.rb', line 11 def before(&before) befores << before self end |
#call(target) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/hollaback/sequence.rb', line 28 def call(target) befores.each { |before| before.call(target) } value = main.call(target) afters.each { |after| after.call(target) } value end |