Class: RLTK::CG::Function::ParameterCollection

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

Overview

This class is used to access a function’s parameters.

Instance Method Summary collapse

Constructor Details

#initialize(fun) ⇒ ParameterCollection

Returns a new instance of ParameterCollection.

Parameters:

  • fun (Function)

    Function for which this is a proxy.



183
184
185
# File 'lib/rltk/cg/function.rb', line 183

def initialize(fun)
	@fun = fun
end

Instance Method Details

#[](index) ⇒ Value

Access the parameter at the given index.

Parameters:

  • index (Integer)

    Index of the desired parameter. May be negative.

Returns:

  • (Value)

    Value object representing the parameter.



192
193
194
195
196
197
198
# File 'lib/rltk/cg/function.rb', line 192

def [](index)
	index += self.size if index < 0
	
	if 0 <= index and index < self.size
		Value.new(Bindings.get_param(@fun, index))
	end
end

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

An iterator for each parameter inside this collection.

Yield Parameters:

Returns:

  • (Enumerator)

    Returns an Enumerator if no block is given.



205
206
207
208
209
210
211
# File 'lib/rltk/cg/function.rb', line 205

def each
	return to_enum :each unless block_given?
	
	self.size.times { |index| yield self[index] }
	
	self
end

#sizeInteger

Returns Number of function parameters.

Returns:

  • (Integer)

    Number of function parameters.



214
215
216
# File 'lib/rltk/cg/function.rb', line 214

def size
	Bindings.count_params(@fun)
end

#to_aArray<Value>

Returns Array of Value objects representing the function parameters.

Returns:

  • (Array<Value>)

    Array of Value objects representing the function parameters.



219
220
221
# File 'lib/rltk/cg/function.rb', line 219

def to_a
	self.size.times.to_a.inject([]) { |params, index| params << self[index] }
end