Class: Ruff::Standard::Defer::Instance
- Inherits:
-
Object
- Object
- Ruff::Standard::Defer::Instance
- Defined in:
- lib/ruff/standard/defer.rb
Instance Attribute Summary collapse
-
#eff ⇒ Object
readonly
You can reimplement the handler using this effect instance.
Instance Method Summary collapse
-
#initialize ⇒ Instance
constructor
makes a new instance.
-
#register(&prc) ⇒ ()
is a smart method to invoke the effect operation.
-
#with(&th) ⇒ A!{e}
is a handler to interpret the effect invocation as registering a procedure.
Constructor Details
Instance Attribute Details
#eff ⇒ Object (readonly)
You can reimplement the handler using this effect instance.
52 53 54 |
# File 'lib/ruff/standard/defer.rb', line 52 def eff @eff end |
Instance Method Details
#register(&prc) ⇒ ()
is a smart method to invoke the effect operation.
19 20 21 |
# File 'lib/ruff/standard/defer.rb', line 19 def register(&prc) @eff.perform prc end |
#with(&th) ⇒ A!{e}
is a handler to interpret the effect invocation as registering a procedure. Registerred procedures are run on the end of computation, by value handler.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruff/standard/defer.rb', line 32 def with(&th) # This is a stack to store deferred procedures. procs = [] # The handler *closes* `procs` variable so it should be created every time. Ruff.handler .on(@eff) do |k, prc| procs << prc k[] end .to do |v| # Like Go's defer functions, it crashes the thunk by reversed order. procs.reverse_each(&:[]) v end .run(&th) end |