struct Spectator::LazyWrapper


Lazily stores a value of any type. Combines Lazy and Wrapper.

Contains no value until the first call to #get is made. Any type can be stored in this wrapper. However, the type must always be known when retrieving it via #get. The type is inferred from the block, and all blocks must return the same type. Because of this, it is recommended to only have #get called in one location.

This type is expected to be used like so:

@wrapper : LazyWrapper

# ...

def lazy_load
  @wrapper.get { some_expensive_operation }

Defined in:



Instance Method Summary

Instance methods inherited from class Object

should(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
should(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
, should_eventually(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_eventually, should_never(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_never, should_not(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
should_not(matcher : Spectator::Matchers::NilMatcher, message = nil, *, _file = __FILE__, _line = __LINE__)
should_not(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)

Constructor Detail

def #

[View source]

Instance Method Detail

def get(& : -> T) : T forall T #

Retrieves the value, if it was previously fetched. On the first invocation of this method, it will yield. The block should return the value to store. Subsequent calls will return the same value and not yield.

[View source]
def initialize #

[View source]