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.



196
197
198
# File 'lib/rltk/cg/function.rb', line 196

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.



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

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.



218
219
220
221
222
223
224
# File 'lib/rltk/cg/function.rb', line 218

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.



227
228
229
# File 'lib/rltk/cg/function.rb', line 227

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.



232
233
234
# File 'lib/rltk/cg/function.rb', line 232

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