class RLTK::CG::Module::GlobalCollection
This class is used to access a module’s global variables.
Public Class Methods
@param [Module] mod Module
for which this is a proxy.
# File lib/rltk/cg/module.rb, line 367 def initialize(mod) @module = mod end
Public Instance Methods
Retreive a GlobalVariable
object.
@param [String, Symbol, Integer] key Global variable identifier. Either the name of the variable or its index.
@return [GlobalVariable]
# File lib/rltk/cg/module.rb, line 376 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
Remove a global variable from the module.
@param [GlobalVariable] global Global variable to remove.
@return [void]
# File lib/rltk/cg/module.rb, line 399 def delete(global) Bindings.delete_global(global) end
An iterator for each global variable inside this collection.
@yieldparam fun [GlobalVariable]
@return [Enumerator] Returns an Enumerator if no block is given.
# File lib/rltk/cg/module.rb, line 408 def each return to_enum(:each) unless block_given? global = self.first while global yield global global = self.next(global) end end
@return [GlobalVariable, nil] The module’s first global variable if one has been added.
# File lib/rltk/cg/module.rb, line 420 def first if (ptr = Bindings.get_first_global(@module)).null? then nil else GlobalValue.new(ptr) end end
@return [GlobalVariable, nil] The module’s last global variable if one has been added.
# File lib/rltk/cg/module.rb, line 425 def last if (ptr = Bindings.get_last_global(@module)).null? then nil else GlobalValue.new(ptr) end end
@param [String, Symbol] name Name of the desired global variable.
@return [GlobalVariable, nil] The global variable with the given name.
# File lib/rltk/cg/module.rb, line 432 def named(name) if (ptr = Bindings.get_named_global(@module, name)).null? then nil else GlobalValue.new(ptr) end end
@param [GlobalVariable] global Global variable you want the successor for.
@return [GlobalVariable, nil] global Next global variable in the collection.
# File lib/rltk/cg/module.rb, line 439 def next(global) if (ptr = Bindings.get_next_global(global)).null? then nil else GlobalValue.new(ptr) end end
@param [GlobalVariable] global Global variable you want the predecessor for.
@return [GlobalVariable, nil] Previous global variable in the collection.
# File lib/rltk/cg/module.rb, line 446 def previous(global) if (ptr = Bindings.get_previous_global(global)).null? then nil else GlobalValue.new(ptr) end end