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 "./expression"
|
||||||
require "./label"
|
require "./label"
|
||||||
require "./lazy"
|
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
# Represents a block from a test.
|
# Represents a block from a test.
|
||||||
|
@ -9,9 +8,6 @@ module Spectator
|
||||||
# The label should be a string recognizable by the user,
|
# The label should be a string recognizable by the user,
|
||||||
# or nil if one isn't available.
|
# or nil if one isn't available.
|
||||||
class Block(T) < Expression(T)
|
class Block(T) < Expression(T)
|
||||||
# Cached value returned from the block.
|
|
||||||
@value = Lazy(T).new
|
|
||||||
|
|
||||||
# Creates the block expression from a proc.
|
# Creates the block expression from a proc.
|
||||||
# The *proc* will be called to evaluate the value of the expression.
|
# The *proc* will be called to evaluate the value of the expression.
|
||||||
# The *label* is usually the Crystal code for the *proc*.
|
# The *label* is usually the Crystal code for the *proc*.
|
||||||
|
@ -28,18 +24,10 @@ module Spectator
|
||||||
super(label)
|
super(label)
|
||||||
end
|
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.
|
# Evaluates the block and returns the value from it.
|
||||||
# This method _does not_ cache the resulting value like `#value` does.
|
# This method _does not_ cache the resulting value like `#value` does.
|
||||||
# Successive calls to this method may return different values.
|
# Successive calls to this method may return different values.
|
||||||
def call : T
|
def value : T
|
||||||
@block.call
|
@block.call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue