|
From: Tim B. <tim...@gm...> - 2006-02-22 23:56:26
|
On Feb 22, 2006, at 12:41 PM, Jonathan Paisley wrote:
> On 22 Feb 2006, at 18:16, Tim Burks wrote:
>
>> * Something needs to be done to resolve the different calling
>> conventions used by Ruby attribute setters ("object =") and Cocoa
>> KVC setters ("setObject").
>
> Have you any ideas for how best to resolve this?
I used the hack below to replace "attr_accessor" with "cocoa_accessor".
cocoa_accessor creates a "setObject" method instead of "object=".
I'd prefer to have the bridge automatically convert "object=" into
"setObject" calls, perhaps as an option.
Tim
module CocoaAccessor
module ClassMethods
def cocoa_accessor(value_id)
iv_name = "@#{value_id}".to_sym
define_method(value_id) { self.instance_variable_get
(iv_name ) }
define_method("set#{value_id.to_s.capitalize}".to_sym) {|
x| self.instance_variable_set(iv_name, x) }
end
end
def self.append_features(klass)
super
klass.extend(ClassMethods)
end
end
class RubySprite
include CocoaAccessor
cocoa_accessor :position
cocoa_accessor :direction
cocoa_accessor :velocity
cocoa_accessor :radius
cocoa_accessor :color
|