Class: Global

Inherits:
Object show all
Defined in:
lib/simul/classes/global.rb

Constant Summary collapse

@@globals =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, wtype = Type::DEFAULT_TYPE, mutable: true) ⇒ Global

Returns a new instance of Global.



9
10
11
12
13
14
15
16
17
# File 'lib/simul/classes/global.rb', line 9

def initialize(key, value, wtype = Type::DEFAULT_TYPE, mutable: true)
  raise "Can't initialize same Global twice #{key}" \
    if @@globals.has_key? key
  @key = key
  @value = value
  @@globals[key] = self
  @wtype = wtype
  @mutable = mutable
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/simul/classes/global.rb', line 7

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/simul/classes/global.rb', line 7

def value
  @value
end

#wtypeObject (readonly)

Returns the value of attribute wtype.



7
8
9
# File 'lib/simul/classes/global.rb', line 7

def wtype
  @wtype
end

Class Method Details

.find_gvar(key) ⇒ Object



35
36
37
# File 'lib/simul/classes/global.rb', line 35

def self.find_gvar(key)
  @@globals[key]
end

.has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/simul/classes/global.rb', line 31

def self.has_key?(key)
  @@globals.has_key? key
end

Instance Method Details

#[](key) ⇒ Object



23
24
25
# File 'lib/simul/classes/global.rb', line 23

def [] (key)
  @@globals[key].value
end

#[]=(key, value) ⇒ Object



19
20
21
# File 'lib/simul/classes/global.rb', line 19

def []= (key, value)
  raise "Cannot modify unmutable global #{@key}" unless self.mutable?
end

#mutable?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/simul/classes/global.rb', line 27

def mutable?
  @mutable
end