class Quartz::State
- Quartz::State
- Reference
- Object
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/json.crquartz/state.cr
Constructors
Instance Method Summary
-
#==(other : self)
Returns
true
if this reference is the same as other. -
#==(other)
Returns
false
(other can only be aValue
here). - #clone
-
#hash(hasher)
See
Object#hash(hasher)
- #inspect(io)
- #to_hash
- #to_json(json : JSON::Builder)
- #to_named_tuple
Macro Summary
Instance methods inherited from class Reference
==(other : Quartz::Any)
==
Instance methods inherited from class Object
===(other : Quartz::Any)
===
Constructor Detail
Instance Method Detail
Returns true
if this reference is the same as other. Invokes same?
.
Returns false
(other can only be a Value
here).
Macro Detail
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
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.