Module: GLib::ListMethods

Includes:
Enumerable
Included in:
List, SList
Defined in:
lib/ffi-glib/list_methods.rb

Overview

Common methods for List and SList.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#element_typeObject (readonly)

Returns the value of attribute element_type.



8
9
10
# File 'lib/ffi-glib/list_methods.rb', line 8

def element_type
  @element_type
end

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/ffi-glib/list_methods.rb', line 10

def self.included(base)
  # Override default field accessors.
  replace_method base, :next, :tail
  replace_method base, :data, :head

  base.extend ContainerClassMethods
end

.replace_method(base, old, new) ⇒ Object



18
19
20
21
22
23
# File 'lib/ffi-glib/list_methods.rb', line 18

def self.replace_method(base, old, new)
  base.class_eval do
    remove_method old
    alias_method old, new
  end
end

Instance Method Details

#==(other) ⇒ Object



50
51
52
# File 'lib/ffi-glib/list_methods.rb', line 50

def ==(other)
  to_a == other.to_a
end

#eachObject



30
31
32
33
34
35
# File 'lib/ffi-glib/list_methods.rb', line 30

def each
  reset_iterator
  while (elem = next_element)
    yield elem
  end
end

#headObject



41
42
43
# File 'lib/ffi-glib/list_methods.rb', line 41

def head
  GirFFI::ArgHelper.cast_from_pointer(element_type, @struct[:data])
end

#initialize(type) ⇒ Object



25
26
27
28
# File 'lib/ffi-glib/list_methods.rb', line 25

def initialize(type)
  store_pointer(FFI::Pointer.new(0))
  @element_type = type
end

#reset_typespec(typespec) ⇒ Object



45
46
47
48
# File 'lib/ffi-glib/list_methods.rb', line 45

def reset_typespec(typespec)
  @element_type = typespec
  self
end

#tailObject



37
38
39
# File 'lib/ffi-glib/list_methods.rb', line 37

def tail
  self.class.wrap(element_type, @struct[:next])
end