Class: GLib::Array
- Inherits:
-
Object
- Object
- GLib::Array
- Extended by:
- ContainerClassMethods
- Includes:
- Enumerable, ArrayMethods
- Defined in:
- lib/ffi-glib/array.rb
Overview
Overrides for GArray, GLib’s automatically growing array. It should not be necessary to create objects of this class from Ruby directly.
Instance Attribute Summary collapse
-
#element_type ⇒ Object
readonly
Returns the value of attribute element_type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #append_vals(ary) ⇒ Object
- #data_ptr ⇒ Object
- #each ⇒ Object
- #get_element_size ⇒ Object (also: #element_size)
- #length ⇒ Object
- #reset_typespec(typespec) ⇒ Object
Methods included from ContainerClassMethods
Methods included from ArrayMethods
Instance Attribute Details
#element_type ⇒ Object (readonly)
Returns the value of attribute element_type.
14 15 16 |
# File 'lib/ffi-glib/array.rb', line 14 def element_type @element_type end |
Class Method Details
.from_enumerable(elmtype, it) ⇒ Object
60 61 62 |
# File 'lib/ffi-glib/array.rb', line 60 def self.from_enumerable elmtype, it self.new(elmtype).tap {|arr| arr.append_vals it } end |
.new(type) ⇒ Object
18 19 20 21 |
# File 'lib/ffi-glib/array.rb', line 18 def new type ptr = Lib.g_array_new(0, 0, calculated_element_size(type)) wrap type, ptr end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 |
# File 'lib/ffi-glib/array.rb', line 50 def ==(other) self.to_a == other.to_a end |
#append_vals(ary) ⇒ Object
24 25 26 27 28 |
# File 'lib/ffi-glib/array.rb', line 24 def append_vals ary bytes = GirFFI::InPointer.from_array element_type, ary Lib.g_array_append_vals(self, bytes, ary.length) self end |
#data_ptr ⇒ Object
40 41 42 |
# File 'lib/ffi-glib/array.rb', line 40 def data_ptr @struct[:data] end |
#each ⇒ Object
30 31 32 33 34 |
# File 'lib/ffi-glib/array.rb', line 30 def each length.times do |idx| yield index(idx) end end |
#get_element_size ⇒ Object Also known as: element_size
44 45 46 |
# File 'lib/ffi-glib/array.rb', line 44 def get_element_size Lib.g_array_get_element_size self end |
#length ⇒ Object
36 37 38 |
# File 'lib/ffi-glib/array.rb', line 36 def length @struct[:len] end |
#reset_typespec(typespec) ⇒ Object
54 55 56 57 58 |
# File 'lib/ffi-glib/array.rb', line 54 def reset_typespec typespec @element_type = typespec check_element_size_match self end |