Class: Ruff::Standard::MeasureTime::Instance
- Inherits:
-
Object
- Object
- Ruff::Standard::MeasureTime::Instance
- Defined in:
- lib/ruff/standard/measure_time.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.
-
#measure(label) ⇒ ()
is a smart method to invoke the effect operation.
-
#with(&th) ⇒ [A, ...{ label: string, time: float }]!{e}
is a handler to interpret the effect invocation as measuring computation time.
Constructor Details
#initialize ⇒ Instance
makes a new instance.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ruff/standard/measure_time.rb', line 22 def initialize @eff = Ruff.instance @handler = Ruff.handler @handler.on(@eff) do |k, label| t1 = Time.now result = k[] t2 = Time.now result + [{ label: label, time: t2 - t1 }] end @handler.to { |x| [x] } end |
Instance Attribute Details
#eff ⇒ Object (readonly)
You can reimplement the handler using this effect instance.
56 57 58 |
# File 'lib/ruff/standard/measure_time.rb', line 56 def eff @eff end |
Instance Method Details
#measure(label) ⇒ ()
is a smart method to invoke the effect operation.
38 39 40 |
# File 'lib/ruff/standard/measure_time.rb', line 38 def measure(label) @eff.perform(label) end |
#with(&th) ⇒ [A, ...{ label: string, time: float }]!{e}
is a handler to interpret the effect invocation as measuring computation time.
51 52 53 |
# File 'lib/ruff/standard/measure_time.rb', line 51 def with(&th) @handler.run(&th) end |