Class: RLTK::CG::User::OperandCollection
- Includes:
- Enumerable
- Defined in:
- lib/rltk/cg/value.rb
Overview
This class is used to access a User’s operands.
Instance Method Summary collapse
-
#[](index) ⇒ Value?
Access the operand at the given index.
-
#[]=(index, value) ⇒ void
Set the operand at the given index.
-
#each {|val| ... } ⇒ Enumerator
An iterator for each operand inside this collection.
-
#initialize(user) ⇒ OperandCollection
constructor
A new instance of OperandCollection.
-
#size ⇒ Integer
Number of operands.
Constructor Details
#initialize(user) ⇒ OperandCollection
Returns a new instance of OperandCollection.
242 243 244 |
# File 'lib/rltk/cg/value.rb', line 242 def initialize(user) @user = user end |
Instance Method Details
#[](index) ⇒ Value?
Access the operand at the given index.
251 252 253 |
# File 'lib/rltk/cg/value.rb', line 251 def [](index) if (ptr = Bindings.get_operand(@user, index)).null? then nil else Value.new(ptr) end end |
#[]=(index, value) ⇒ void
This method returns an undefined value.
Set the operand at the given index.
261 262 263 |
# File 'lib/rltk/cg/value.rb', line 261 def []=(index, value) Bindings.set_operand(@user, index, check_type(value, Value, 'value')) end |
#each {|val| ... } ⇒ Enumerator
An iterator for each operand inside this collection.
270 271 272 273 274 275 276 |
# File 'lib/rltk/cg/value.rb', line 270 def each return to_enum(:each) unless block_given? self.size.times { |i| yield self[i] } self end |
#size ⇒ Integer
Returns Number of operands.
279 280 281 |
# File 'lib/rltk/cg/value.rb', line 279 def size Bindings.get_num_operands(@user) end |