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.
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.
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.
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 |
#size ⇒ Integer
Returns Number of function parameters.
214 215 216 |
# File 'lib/rltk/cg/function.rb', line 214 def size Bindings.count_params(@fun) end |
#to_a ⇒ Array<Value>
Returns 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 |