Class: RCGTK::Module::FunctionCollection
- Inherits:
-
Object
- Object
- RCGTK::Module::FunctionCollection
- Includes:
- Enumerable
- Defined in:
- lib/rcgtk/module.rb
Overview
This class is used to access a module’s Functions.
Instance Method Summary collapse
-
#[](key) ⇒ Function
Retreive a Function object.
-
#add(name, *type_info, &block) ⇒ Function
Add a Function to this module.
-
#delete(fun) ⇒ void
Remove a function from the module.
-
#each {|fun| ... } ⇒ Enumerator
An iterator for each function inside this collection.
-
#first ⇒ Function?
The module’s first function if one has been added.
-
#initialize(mod) ⇒ FunctionCollection
constructor
A new instance of FunctionCollection.
-
#last ⇒ Function?
The module’s last function if one has been added.
-
#named(name) ⇒ Function?
The function with the given name.
-
#next(fun) ⇒ Function?
Next function in the collection.
-
#previous(fun) ⇒ Function?
Previous function in the collection.
Constructor Details
#initialize(mod) ⇒ FunctionCollection
Returns a new instance of FunctionCollection.
276 277 278 |
# File 'lib/rcgtk/module.rb', line 276 def initialize(mod) @module = mod end |
Instance Method Details
#[](key) ⇒ Function
Retreive a Function object.
285 286 287 288 289 290 291 292 293 |
# File 'lib/rcgtk/module.rb', line 285 def [](key) case key when String, Symbol self.named(key) when Integer (1...key).inject(self.first) { |fun| if fun then self.next(fun) else break end } end end |
#add(name, *type_info, &block) ⇒ Function
Add a Function to this module.
302 303 304 |
# File 'lib/rcgtk/module.rb', line 302 def add(name, *type_info, &block) Function.new(@module, name, *type_info, &block) end |
#delete(fun) ⇒ void
This method returns an undefined value.
Remove a function from the module.
311 312 313 |
# File 'lib/rcgtk/module.rb', line 311 def delete(fun) Bindings.delete_function(fun) end |
#each {|fun| ... } ⇒ Enumerator
An iterator for each function inside this collection.
320 321 322 323 324 325 326 327 328 329 |
# File 'lib/rcgtk/module.rb', line 320 def each return to_enum(:each) unless block_given? fun = self.first while fun yield fun fun = self.next(fun) end end |
#first ⇒ Function?
Returns The module’s first function if one has been added.
332 333 334 |
# File 'lib/rcgtk/module.rb', line 332 def first if (ptr = Bindings.get_first_function(@module)).null? then nil else Function.new(ptr) end end |
#last ⇒ Function?
Returns The module’s last function if one has been added.
337 338 339 |
# File 'lib/rcgtk/module.rb', line 337 def last if (ptr = Bindings.get_last_function(@module)).null? then nil else Function.new(ptr) end end |
#named(name) ⇒ Function?
Returns The function with the given name.
344 345 346 |
# File 'lib/rcgtk/module.rb', line 344 def named(name) if (ptr = Bindings.get_named_function(@module, name)).null? then nil else Function.new(ptr) end end |
#next(fun) ⇒ Function?
Returns Next function in the collection.
351 352 353 |
# File 'lib/rcgtk/module.rb', line 351 def next(fun) if (ptr = Bindings.get_next_function(fun)).null? then nil else Function.new(ptr) end end |
#previous(fun) ⇒ Function?
Returns Previous function in the collection.
358 359 360 |
# File 'lib/rcgtk/module.rb', line 358 def previous(fun) if (ptr = Bindings.get_previous_function(fun)).null? then nil else Function.new(ptr) end end |