[MacRuby-devel] Invoking a block in MacRuby, instantiated in Objective-C

3 views
Skip to first unread message

Christian Niles

unread,
May 15, 2011, 4:42:35 PM5/15/11
to MacRuby development discussions.
Hey All,

There's plenty of documentation showing how one can use Proc objects to invoke Objective-C methods that accept block parameters, but I can't find any way to invoke an Objective-C block from within a Ruby method.

Without thinking I had assumed they'd be mapped to a Proc-like object, which I could invoke with #call:

def performOperation(operation, success:success_callback, error:error_callback)
# ...
result = "..."
success_callback.call(result)
end

But I get an error: undefined method `call' for #<__NSAutoBlock__:0x2006b6560>

christian.
_______________________________________________
MacRuby-devel mailing list
MacRub...@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Laurent Sansonetti

unread,
May 15, 2011, 6:35:49 PM5/15/11
to MacRuby development discussions.
Hi Christian,

I think I only implemented Ruby -> ObjC blocks support, not the other way around :) I didn't know Cocoa was exposing APIs returning ObjC blocks yet. Could you file a ticket? I will try to get that fixed in the upcoming release.

Thanks,
Laurent

Christian Niles

unread,
May 15, 2011, 7:04:50 PM5/15/11
to MacRuby development discussions.
Here's the ticket:

https://www.macruby.org/trac/ticket/1280

As I mentioned there, my use case isn't for a Cocoa API -- it's my own API. I'm using MacRuby to test my framework and have written a couple mock implementations in MacRuby to simplify testing.

christian.

Reply all
Reply to author
Forward
0 new messages