Class: Global
Constant Summary collapse
- @@globals =
{}
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#wtype ⇒ Object
readonly
Returns the value of attribute wtype.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(key, value, wtype = Type::DEFAULT_TYPE, mutable: true) ⇒ Global
constructor
A new instance of Global.
- #mutable? ⇒ Boolean
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
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/simul/classes/global.rb', line 7 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/simul/classes/global.rb', line 7 def value @value end |
#wtype ⇒ Object (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
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
27 28 29 |
# File 'lib/simul/classes/global.rb', line 27 def mutable? @mutable end |