Class: Ruff::Standard::CurrentTime::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/ruff/standard/current_time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInstance

makes a new instance.



10
11
12
13
# File 'lib/ruff/standard/current_time.rb', line 10

def initialize
  @eff = Ruff.instance
  @handler = Ruff.handler.on(@eff) { |k| k[Time.now] }
end

Instance Attribute Details

#effObject (readonly)

You can reimplement the handler using this effect instance.



37
38
39
# File 'lib/ruff/standard/current_time.rb', line 37

def eff
  @eff
end

Instance Method Details

#getTime

is a smart method to invoke the effect operation.

Returns:

  • (Time)

    with with , returns Time.now



18
19
20
# File 'lib/ruff/standard/current_time.rb', line 18

def get
  @eff.perform
end

#with(&th) ⇒ A!{e}

is a handler to interpret the effect invokation as requesting the current time. This handler receives the request and returns current time.

Parameters:

  • th (Proc<(), A!{CurrentTime.eff, e}>)

    is a thunk returning A with the possibility to invoke effects, including CurrentTime.eff .

Returns:

  • (A!{e})

    returns A , without modification by value handler. But it still has the possibility to invoke effects(e).



32
33
34
# File 'lib/ruff/standard/current_time.rb', line 32

def with(&th)
  @handler.run(&th)
end