diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-04-27 06:00:58 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-04-27 06:00:58 +0200 |
commit | 7c63402a0087554395b97f6edc6c4cb7f10f6320 (patch) | |
tree | 738685f8a7f3df1c1286c723bad5a962646abf72 /lib/efl | |
parent | 44abb93bd6ad3f44d8b8a139e2b0ac0da7953631 (diff) | |
download | ffi-efl-7c63402a0087554395b97f6edc6c4cb7f10f6320.zip ffi-efl-7c63402a0087554395b97f6edc6c4cb7f10f6320.tar.gz |
ffi Helper: method_missing nicely handles /^(.)=$/ setters
Diffstat (limited to 'lib/efl')
-rw-r--r-- | lib/efl/ffi.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/efl/ffi.rb b/lib/efl/ffi.rb index eaa45e7..4419b38 100644 --- a/lib/efl/ffi.rb +++ b/lib/efl/ffi.rb @@ -51,15 +51,22 @@ module Efl m.class_eval "def self.inherited sub; sub.class_eval 'def self.func_prefixes; superclass.func_prefixes; end'; end" end def method_missing m, *args, &block + if m =~/^(.*)=$/ + m_s = $1+'_set' + args_s = '*args[0]' + else + m_s = m.to_s + args_s = '*args' + end self.class.func_prefixes.each do |p| - sym = p+m.to_s + sym = p+m_s if Efl::API.respond_to? sym - self.class.class_eval "def #{m} *args, █ r=Efl::API.#{sym}(@ptr,*args); yield r if block_given?; r; end" + self.class.class_eval "def #{m} *args, █ r=Efl::API.#{sym}(@ptr,#{args_s}); yield r if block_given?; r; end" return self.send m, *args, &block end end r = Efl::API.send m, @ptr, *args - self.class.class_eval "def #{m} *args, █ r=Efl::API.#{m}(@ptr,*args); yield r if block_given?; r; end" + self.class.class_eval "def #{m} *args, █ r=Efl::API.#{m}(@ptr,#{args_s}); yield r if block_given?; r; end" r end end |