Class: RLTK::CG::Module::FunctionCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rltk/cg/module.rb

Overview

This class is used to access a module’s Functions.

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ FunctionCollection



226
227
228
# File 'lib/rltk/cg/module.rb', line 226

def initialize(mod)
	@module = mod
end

Instance Method Details

#[](key) ⇒ Function

Retreive a Function object.



235
236
237
238
239
240
241
242
243
# File 'lib/rltk/cg/module.rb', line 235

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.



252
253
254
# File 'lib/rltk/cg/module.rb', line 252

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.



261
262
263
# File 'lib/rltk/cg/module.rb', line 261

def delete(fun)
	Bindings.delete_function(fun)
end

#each {|fun| ... } ⇒ Enumerator

An iterator for each function inside this collection.

Yield Parameters:



270
271
272
273
274
275
276
277
278
279
# File 'lib/rltk/cg/module.rb', line 270

def each
	return to_enum(:each) unless block_given?
	
	fun = self.first
	
	while fun
		yield fun
		fun = self.next(fun)
	end
end

#firstFunction?



282
283
284
# File 'lib/rltk/cg/module.rb', line 282

def first
	if (ptr = Bindings.get_first_function(@module)).null? then nil else Function.new(ptr) end
end

#lastFunction?



287
288
289
# File 'lib/rltk/cg/module.rb', line 287

def last
	if (ptr = Bindings.get_last_function(@module)).null? then nil else Function.new(ptr) end
end

#named(name) ⇒ Function?



294
295
296
# File 'lib/rltk/cg/module.rb', line 294

def named(name)
	if (ptr = Bindings.get_named_function(@module, name)).null? then nil else Function.new(ptr) end
end

#next(fun) ⇒ Function?



301
302
303
# File 'lib/rltk/cg/module.rb', line 301

def next(fun)
	if (ptr = Bindings.get_next_function(fun)).null? then nil else Function.new(ptr) end
end

#previous(fun) ⇒ Function?



308
309
310
# File 'lib/rltk/cg/module.rb', line 308

def previous(fun)
	if (ptr = Bindings.get_previous_function(fun)).null? then nil else Function.new(ptr) end
end