class YPetri::Agent::HashKeyPointer

Represents a pointer to a key of a specific hash associated with the pointer instance. Used to implement pointers of the Agent class.

Attributes

key[R]

Key at which the pointer points.

what_is_hash_value[R]

Short text explaining what does a value of the associated hash represent.

Public Class Methods

new( hash: nil, hash_value_is: '', default_key: nil ) click to toggle source

Upon initalization, hash key pointer requires a hash, with which the instance will be associated, a textual description explaining what does a value of the associated hash represent, and the default hash key.

# File lib/y_petri/agent/hash_key_pointer.rb, line 17
def initialize( hash: nil, hash_value_is: '', default_key: nil )
  @hash = hash
  @what_is_hash_value = hash_value_is
  @default_key = default_key
end

Public Instance Methods

get() click to toggle source

Gets the value paired in the hash associated with the current key to which this pointer points.

# File lib/y_petri/agent/hash_key_pointer.rb, line 34
def get
  return @hash[@default_key] if @key.nil?
  @hash[@key] or raise "No #{what_is_hash_value} identified by #{arg}!"
end
reset() click to toggle source

Resets the key to the default key.

# File lib/y_petri/agent/hash_key_pointer.rb, line 25
def reset; @key = @default_key end
set(arg;) click to toggle source

Sets the pointer key to the one given in the argument.

# File lib/y_petri/agent/hash_key_pointer.rb, line 29
def set arg; @key = arg end