Tim Perrett <freestyle_kayaker / hotmail.com> writes:

>> Second, you'll need to pass the *full* name of the selector, not just 
>> the
>> part before the first argument - i.e. 
>> "didEndSheet:returnCode:contextInfo:".
>
> So what your saying in effect is that although im writing in Ruby, 
> because its a bridge I have to pass the whole ObjC method signiture?

Yes, because the code that will be calling your callback is Objective-C.
All it knows is to send the message 'didEndSheet:returnCode:contextInfo:'.
It doesn't know if the receiver will handle the message by calling a
method in Objective-C, Ruby, or some other language.

To put it another way, the selector is the name of the message, and will
be the same regardless of what language you're writing in, or how that
language maps messages to the methods that handle them.

Most of the time, you won't need to worry about the distinction between
selector and method names - the bridge will handle translating ordinary
Ruby method calls to Objective-C messages. But you will need to keep it
in mind when you're passing selectors as arguments.

> so if my method was:
>
> def connectionSheetDidEnd(returnCode, contextInfo)

Don't name your method like that. When you send Cocoa messages, you replace
the :s with _s (all except the last one). When you want Cocoa to call your
Ruby methods, the bridge does the same translation in reverse. So if the
selector you give to Cocoa is 'didEndSheet:returnCode:contextInfo:', then
the Ruby method should be named like this:

    def didEndSheet_returnCode_contextInfo(sheet, code, context)
        ...
    end

So, when the bridge receives the message, it will replace the :s with _s,
and strip off the last _, to determine what Ruby method will handle the
message.

> I would then have to pass in 
> 'connectionSheetDidEnd:returnCode:contextInfo'?

Don't forget that last colon. In Ruby (and Perl, and Python) the trailing
underscore is optional for the method name, but the trailing colon is still
part of the selector.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net