mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Workaround for case where wrapper might store a type
This commit is contained in:
parent
e275711f2b
commit
a20b7cad80
2 changed files with 11 additions and 1 deletions
|
@ -13,7 +13,7 @@ module Spectator
|
|||
# Subsequent calls will return the same value and not yield.
|
||||
def get(&block : -> T) : T forall T
|
||||
wrapper = @lazy.get { Wrapper.new(yield) }
|
||||
wrapper.get(T)
|
||||
wrapper.get { yield }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,6 +17,16 @@ module Spectator
|
|||
value.get
|
||||
end
|
||||
|
||||
# Retrieves the previously wrapped value.
|
||||
# Alternate form of `#get` that accepts a block.
|
||||
# The block must return the same type as the wrapped value, otherwise an error will be raised.
|
||||
# This method gets around the issue where the value might be a type (i.e. `Int32.class`).
|
||||
# The block will never be executed, it is only used for type information.
|
||||
def get(& : -> T) : T forall T
|
||||
value = @value.as(Value(T))
|
||||
value.get
|
||||
end
|
||||
|
||||
# Base type that generic types inherit from.
|
||||
# This provides a common base type,
|
||||
# since Crystal doesn't support storing an `Object` (yet).
|
||||
|
|
Loading…
Reference in a new issue