struct Spectator::Wrapper


Typeless wrapper for a value. Stores any value or reference type. However, the type must be known when retrieving the value.

This type is expected to be used like so:

wrapper ="wrapped")
value = wrapper.get(String)

Defined in:



Instance Method Summary

Instance methods inherited from class Object

should(matcher, message = nil) should, should_eventually(matcher, message = nil) should_eventually, should_never(matcher, message = nil) should_never, should_not(matcher, message = nil) should_not

Constructor Detail

def #

Creates a wrapper for the specified value.

[View source]

Instance Method Detail

def get(type : T.class) : T forall T #

Retrieves the previously wrapped value. The type of the wrapped value must match otherwise an error will be raised.

[View source]
def get(& : -> T) : T forall T #

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.

wrapper =
# type = wrapper.get(Int32.class) # Does not work!
type = wrapper.get { Int32 } # Returns Int32

[View source]