Class: RCGTK::User::OperandCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rcgtk/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.



230
231
232
# File 'lib/rcgtk/value.rb', line 230

def initialize(user)
	@user = user
end

Instance Method Details

#[](index) ⇒ Value?

Access the operand at the given index.

Parameters:

  • index (Integer)

Returns:

  • (Value, nil)

    Value object representing the operand at index if one exists.



239
240
241
# File 'lib/rcgtk/value.rb', line 239

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.



249
250
251
# File 'lib/rcgtk/value.rb', line 249

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.



258
259
260
261
262
263
264
# File 'lib/rcgtk/value.rb', line 258

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.



267
268
269
# File 'lib/rcgtk/value.rb', line 267

def size
	Bindings.get_num_operands(@user)
end