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: ClassMethods

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.



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

def element_type
  @element_type
end

Class Method Details

.included(base) ⇒ Object



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

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

  base.extend ContainerClassMethods
  base.extend ClassMethods
end

.replace_method(base, old, new) ⇒ Object



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

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



57
58
59
# File 'lib/ffi-glib/list_methods.rb', line 57

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

#eachObject



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

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

#headObject



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

def head
  return nil if struct.null?

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

#initialize(type) ⇒ Object



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

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

#reset_typespec(typespec) ⇒ Object



52
53
54
55
# File 'lib/ffi-glib/list_methods.rb', line 52

def reset_typespec(typespec)
  @element_type = typespec
  self
end

#tailObject



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

def tail
  return nil if struct.null?

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