Module: Efl::ClassHelper

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/efl.rb', line 60

def method_missing m, *args, &block
    m_s = m.to_s
    if m_s =~/^(.*)=$/
        m_s = $1+'_set'
        args_s = '*args[0]'
    elsif m_s =~/^(.*)\?$/
        m_s = $1+'_get'
        args_s = '*args'
    else
        args_s = '*args'
    end
    (['']+self.class.search_prefixes).each do |p|
        sym = p+m_s
        meth = (
            if Efl::Native.respond_to? sym
                sym
            elsif Efl::Native.respond_to? m_s
                m_s
            elsif Efl::Native.respond_to? sym+'_get'
                sym+'_get'
            elsif Efl::Native.respond_to? m_s+'_get'
                m_s+'_get'
            else
                nil
            end
        )
        if not meth.nil?
            self.class.class_eval "def #{m} *args, █ r=Efl::Native.#{meth}(@ptr,#{args_s}); yield r if block_given?; r; end"
            return self.send m, *args, &block
        end
    end
    Kernel.raise NameError.new "#{self.class.name} is unable to resolve #{m} within #{self.class.search_prefixes.inspect}"
end

Class Method Details

.included(kls) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/efl.rb', line 47

def self.included kls
    # create class instance @search_prefixes
    kls.class_eval "@search_prefixes ||=[]"
    # access and prepend *args to @search_prefixes
    kls.class_eval "def self.search_prefixes *args; @search_prefixes.unshift *args unless args.empty?; @search_prefixes; end"
    # on inheritance, copy ancestor's @search_prefixes
    kls.class_eval <<-EOF
    def self.inherited sub
        sub.class_eval '@search_prefixes = []'
        sub.search_prefixes *self.search_prefixes
    end
    EOF
end

Instance Method Details

#===(o) ⇒ Object



44
# File 'lib/efl.rb', line 44

def === o; @ptr === o.to_ptr; end

#addressObject



46
# File 'lib/efl.rb', line 46

def address; @ptr.address; end

#null?Boolean

Returns:

  • (Boolean)


45
# File 'lib/efl.rb', line 45

def null?; @ptr.null?; end

#to_aObject



39
# File 'lib/efl.rb', line 39

def to_a; [self] end

#to_aryObject



40
# File 'lib/efl.rb', line 40

def to_ary; [self] end

#to_ptrObject



43
# File 'lib/efl.rb', line 43

def to_ptr; @ptr; end

#to_sObject Also known as: to_str



41
# File 'lib/efl.rb', line 41

def to_s; Object.instance_method(:to_s).bind(self).call+' ['+self.to_ptr.to_s+']' end