Class: Efl::EinaList::REinaList

Inherits:
Object
  • Object
show all
Includes:
ClassHelper, Enumerable
Defined in:
lib/efl/eina_list.rb

Instance Method Summary collapse

Methods included from ClassHelper

#===, #address, included, #method_missing, #null?, #to_ptr, #to_s

Constructor Details

#initialize(o = nil) ⇒ REinaList

Returns a new instance of REinaList



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/efl/eina_list.rb', line 25

def initialize o=nil
    @ptr = (
        case o
        when FFI::Pointer
            o
        when NilClass
            FFI::Pointer::NULL
        when Array
            o.inject(FFI::Pointer::NULL) { |p,e| Native.eina_list_append p, e }
        else
            raise ArgumentError.new "wrong argument #{o.class.name}"
        end
    )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Efl::ClassHelper

Instance Method Details

#append(p) ⇒ Object Also known as: <<

for fun and tests



57
58
59
# File 'lib/efl/eina_list.rb', line 57

def append p
    @ptr = Native.eina_list_append @ptr, p
end

#eachObject



43
44
45
46
47
48
49
50
51
# File 'lib/efl/eina_list.rb', line 43

def each
    return if not block_given?
    p = @ptr
    while p!=::FFI::Pointer::NULL
        l = Native::EinaListStruct.new p
        yield l[:data]
        p = l[:next]
    end
end

#freeObject



39
40
41
42
# File 'lib/efl/eina_list.rb', line 39

def free
    Native.eina_list_free @ptr
    @ptr = nil
end

#prepend(p) ⇒ Object Also known as: unshift



61
62
63
# File 'lib/efl/eina_list.rb', line 61

def prepend p
    @ptr = Native.eina_list_prepend @ptr, p
end

#to_aObject Also known as: to_ary



52
53
54
# File 'lib/efl/eina_list.rb', line 52

def to_a
    inject([]) { |s,e| s<<e }
end