Module: GLib::ArrayMethods

Included in:
Array, PtrArray
Defined in:
lib/ffi-glib/array_methods.rb

Overview

Common methods for GLib::Array and GLib::PtrArray

Instance Method Summary collapse

Instance Method Details

#index(idx) ⇒ Object

Re-implementation of the g_array_index and g_ptr_array_index macros



7
8
9
10
11
12
13
14
# File 'lib/ffi-glib/array_methods.rb', line 7

def index(idx)
  unless (0...length).cover? idx
    raise IndexError, "Index #{idx} outside of bounds 0..#{length - 1}"
  end

  ptr = GirFFI::InOutPointer.new element_type, data_ptr + idx * element_size
  ptr.to_ruby_value
end