Class: RLTK::CG::Function::ParameterCollection
- Inherits:
-
Object
- Object
- 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.
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.
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.
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 |
#size ⇒ Integer
Returns Number of function parameters.
227 228 229 |
# File 'lib/rltk/cg/function.rb', line 227 def size Bindings.count_params(@fun) end |
#to_a ⇒ Array<Value>
Returns 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 |