Module: GLib::ListMethods

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

Overview

Common methods for List and SList.

Defined Under Namespace

Modules: ListClassMethods

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.



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

def element_type
  @element_type
end

Class Method Details

.included(base) ⇒ Object



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

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

  class << base; self end.send :remove_method, :new
  base.extend ListClassMethods

  base.extend ContainerClassMethods
end

.replace_method(base, old, new) ⇒ Object



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

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



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

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

#eachObject



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

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

#headObject



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

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

#reset_typespec(typespec) ⇒ Object



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

def reset_typespec typespec
  @element_type = typespec
  self
end

#tailObject



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

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