Class: RLTK::CG::Function::ParameterCollection
- Includes:
- Enumerable
- Defined in:
- lib/rltk/cg/function.rb
Overview
This class is used to access a function’s parameters.
Instance Method Summary collapse
-
#[](index) ⇒ Value
Access the parameter at the given index.
-
#each {|val| ... } ⇒ Enumerator
An iterator for each parameter inside this collection.
-
#initialize(fun) ⇒ ParameterCollection
constructor
A new instance of ParameterCollection.
-
#size ⇒ Integer
Number of function parameters.
-
#to_a ⇒ Array<Value>
Array of Value objects representing the function parameters.
Constructor Details
#initialize(fun) ⇒ ParameterCollection
Returns a new instance of ParameterCollection.
186 187 188 |
# File 'lib/rltk/cg/function.rb', line 186 def initialize(fun) @fun = fun end |
Instance Method Details
#[](index) ⇒ Value
Access the parameter at the given index.
195 196 197 198 199 200 201 |
# File 'lib/rltk/cg/function.rb', line 195 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.
208 209 210 211 212 213 214 |
# File 'lib/rltk/cg/function.rb', line 208 def each return to_enum :each unless block_given? self.size.times { |index| yield self[index] } self end |
#size ⇒ Integer
Returns Number of function parameters.
217 218 219 |
# File 'lib/rltk/cg/function.rb', line 217 def size Bindings.count_params(@fun) end |
#to_a ⇒ Array<Value>
Returns Array of Value objects representing the function parameters.
222 223 224 |
# File 'lib/rltk/cg/function.rb', line 222 def to_a self.size.times.to_a.inject([]) { |params, index| params << self[index] } end |