Module: GLib::ListMethods

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#element_typeObject

Returns the value of attribute element_type.



6
7
8
# File 'lib/ffi-glib/list_methods.rb', line 6

def element_type
  @element_type
end

Class Method Details

.included(base) ⇒ Object



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

def self.included base
  base.extend ContainerClassMethods
  # Override default field accessors.
  replace_method base, :next, :tail
  replace_method base, :data, :head
end

.replace_method(base, old, new) ⇒ Object



15
16
17
18
19
20
# File 'lib/ffi-glib/list_methods.rb', line 15

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

Instance Method Details

#eachObject



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

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

#headObject



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

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

#reset_typespec(typespec) ⇒ Object



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

def reset_typespec typespec
  self.element_type = typespec
  self
end

#tailObject



29
30
31
# File 'lib/ffi-glib/list_methods.rb', line 29

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