mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Don't cache the block return value
Let the matcher handle this if it needs to.
This commit is contained in:
parent
a74957204b
commit
50d1f69230
1 changed files with 1 additions and 13 deletions
|
@ -1,6 +1,5 @@
|
|||
require "./expression"
|
||||
require "./label"
|
||||
require "./lazy"
|
||||
|
||||
module Spectator
|
||||
# Represents a block from a test.
|
||||
|
@ -9,9 +8,6 @@ module Spectator
|
|||
# The label should be a string recognizable by the user,
|
||||
# or nil if one isn't available.
|
||||
class Block(T) < Expression(T)
|
||||
# Cached value returned from the block.
|
||||
@value = Lazy(T).new
|
||||
|
||||
# Creates the block expression from a proc.
|
||||
# The *proc* will be called to evaluate the value of the expression.
|
||||
# The *label* is usually the Crystal code for the *proc*.
|
||||
|
@ -28,18 +24,10 @@ module Spectator
|
|||
super(label)
|
||||
end
|
||||
|
||||
# Retrieves the value of the block expression.
|
||||
# This will be the return value of the block.
|
||||
# The block is lazily evaluated and the value retrieved only once.
|
||||
# Afterwards, the value is cached and returned by successive calls to this method.
|
||||
def value
|
||||
@value.get { call }
|
||||
end
|
||||
|
||||
# Evaluates the block and returns the value from it.
|
||||
# This method _does not_ cache the resulting value like `#value` does.
|
||||
# Successive calls to this method may return different values.
|
||||
def call : T
|
||||
def value : T
|
||||
@block.call
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue