class Quartz::State

Overview

A base class that wraps the state of a model. Automatically extended by models through use of the state macro.

See Stateful#state.

Direct Known Subclasses

Defined in:

quartz/state.cr

Constructors

Instance Method Summary

Macro Summary

Instance methods inherited from class Reference

==(other : Quartz::Any) ==

Instance methods inherited from class Object

===(other : Quartz::Any) ===

Constructor Detail

def self.new(**kwargs) #

[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


[View source]
def ==(other) #
Description copied from class Reference

Returns false (other can only be a Value here).


[View source]
def clone #

[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


[View source]
def inspect(io) #

[View source]
def to_hash #

[View source]
def to_named_tuple #

[View source]

Macro Detail

macro parameter(name, &block) #

The parameter macro defines a state parameter for the State of a model.

It is intended to be used within a block provided with the Stateful#state macro.

Unlike state variables, parameters are read-only variables that can be set with the initial state of a model. As an example, they can be used to define the constants of an equation.

See also #var to declare state variables. See also Stateful#state.

Usage

parameter must receive a type declaration which will be used to declare an instance variable and a getter.

Default values must be declared using the type declaration notation or through a block (lazy initialization) :

state do
  parameter c = 0.013
end

[View source]
macro var(name, &block) #

The var macro defines a state variable for the State of a model. Its primary goal is to generate convenient getters and setters for the model among other purposes.

It is intended to be used within a block provided with the Stateful#state macro.

Unlike state parameters, state variables are updated during the simulation by its model behaviour.

See also #parameter See also Stateful#state.

Usage

var must receive a type declaration which will be used to declare an instance variable, a getter and a setter.

Default values must be declared using the type declaration notation or through a block (lazy initialization) :

state do
  var foo : Int32 = 42
  var bar : Int32 { (rand * 100 + 1).to_i32 }
  var quz : Int32 { foo * 42 }
end

Note from previous example that the initialization block of quz is allowed to reference the value of another state variable.


[View source]