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.



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
# 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

  base.extend ContainerClassMethods
end

.replace_method(base, old, new) ⇒ Object



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

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



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

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

#eachObject



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

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

#headObject



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

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

#initialize(type) ⇒ Object



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

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

#reset_typespec(typespec) ⇒ Object



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

def reset_typespec(typespec)
  @element_type = typespec
  self
end

#tailObject



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

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