Class: RLTK::CG::User::OperandCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rltk/cg/value.rb

Overview

This class is used to access a User’s operands.

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ OperandCollection

Returns a new instance of OperandCollection.

Parameters:

  • user (User)

    User object for which this is a proxy.



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.

Parameters:

Returns:

  • (Value, nil)

    Value object representing the operand at index if one exists.



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.

Parameters:

  • index (Integer)

    Index of operand to set.

  • value (Value)

    Value to set as operand.



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.

Yield Parameters:

Returns:

  • (Enumerator)

    Returns an Enumerator if no block is given.



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

#sizeInteger

Returns Number of operands.

Returns:

  • (Integer)

    Number of operands.



279
280
281
# File 'lib/rltk/cg/value.rb', line 279

def size
	Bindings.get_num_operands(@user)
end