Class: RLTK::CG::Module::GlobalCollection
- Includes:
- Enumerable
- Defined in:
- lib/rltk/cg/module.rb
Overview
This class is used to access a module’s global variables.
Instance Method Summary collapse
-
#[](key) ⇒ GlobalVariable
Retreive a GlobalVariable object.
-
#add(type, name) ⇒ Object
Add a global variable to a module.
-
#delete(global) ⇒ void
Remove a global variable from the module.
-
#each {|fun| ... } ⇒ Enumerator
An iterator for each global variable inside this collection.
-
#first ⇒ GlobalVariable?
The module’s first global variable if one has been added.
-
#initialize(mod) ⇒ GlobalCollection
constructor
A new instance of GlobalCollection.
-
#last ⇒ GlobalVariable?
The module’s last global variable if one has been added.
-
#named(name) ⇒ GlobalVariable?
The global variable with the given name.
-
#next(global) ⇒ GlobalVariable?
Global Next global variable in the collection.
-
#previous(global) ⇒ GlobalVariable?
Previous global variable in the collection.
Constructor Details
#initialize(mod) ⇒ GlobalCollection
Returns a new instance of GlobalCollection.
322 323 324 |
# File 'lib/rltk/cg/module.rb', line 322 def initialize(mod) @module = mod end |
Instance Method Details
#[](key) ⇒ GlobalVariable
Retreive a GlobalVariable object.
331 332 333 334 335 336 337 338 339 |
# File 'lib/rltk/cg/module.rb', line 331 def [](key) case key when String, Symbol self.named(key) when Integer (1...key).inject(self.first) { |global| if global then self.next(global) else break end } end end |
#add(type, name) ⇒ Object
Add a global variable to a module.
345 346 347 |
# File 'lib/rltk/cg/module.rb', line 345 def add(type, name) GlobalVariable.new(Bindings.add_global(@module, type, name)) end |
#delete(global) ⇒ void
This method returns an undefined value.
Remove a global variable from the module.
354 355 356 |
# File 'lib/rltk/cg/module.rb', line 354 def delete(global) Bindings.delete_global(global) end |
#each {|fun| ... } ⇒ Enumerator
An iterator for each global variable inside this collection.
363 364 365 366 367 368 369 370 371 372 |
# File 'lib/rltk/cg/module.rb', line 363 def each return to_enum(:each) unless block_given? global = self.first while global yield global global = self.next(global) end end |
#first ⇒ GlobalVariable?
Returns The module’s first global variable if one has been added.
375 376 377 |
# File 'lib/rltk/cg/module.rb', line 375 def first if (ptr = Bindings.get_first_global(@module)).null? then nil else GlobalValue.new(ptr) end end |
#last ⇒ GlobalVariable?
Returns The module’s last global variable if one has been added.
380 381 382 |
# File 'lib/rltk/cg/module.rb', line 380 def last if (ptr = Bindings.get_last_global(@module)).null? then nil else GlobalValue.new(ptr) end end |
#named(name) ⇒ GlobalVariable?
Returns The global variable with the given name.
387 388 389 |
# File 'lib/rltk/cg/module.rb', line 387 def named(name) if (ptr = Bindings.get_named_global(@module, name)).null? then nil else GlobalValue.new(ptr) end end |
#next(global) ⇒ GlobalVariable?
Returns global Next global variable in the collection.
394 395 396 |
# File 'lib/rltk/cg/module.rb', line 394 def next(global) if (ptr = Bindings.get_next_global(global)).null? then nil else GlobalValue.new(ptr) end end |
#previous(global) ⇒ GlobalVariable?
Returns Previous global variable in the collection.
401 402 403 |
# File 'lib/rltk/cg/module.rb', line 401 def previous(global) if (ptr = Bindings.get_previous_global(global)).null? then nil else GlobalValue.new(ptr) end end |