Looks like a bug with the way the Cocoa object is boxed. Can you file it at
https://www.macruby.org/trac/newticket ?

Cheers,

Josh

On Wed, Feb 2, 2011 at 8:51 PM, Mark Rada <mr...@marketcircle.com> wrote:

> Hi,
>
> I was trying to setup an async callback using a proc instead of a method to
> register for app launching notifications. For some reason, when I use the
> proc method, I get the wrong object passed to the proc
> when it gets called.
>
> The version using a method callback:
>
>        framework 'Cocoa'
>
>        def callback notif
>          puts notif.class
>          puts notif.inspect
>          puts notif.userInfo.inspect
>        end
>
>        def launch_mail
>          workspace = NSWorkspace.sharedWorkspace
>
>          workspace.notificationCenter.addObserver self,
>                                          selector:'callback:',
>
>  name:NSWorkspaceDidLaunchApplicationNotification,
>                                            object:nil
>
>          workspace.launchAppWithBundleIdentifier 'com.apple.mail',
>                                          options:NSWorkspaceLaunchAsync,
>                   additionalEventParamDescriptor:nil,
>                                 launchIdentifier:nil
>        end
>
>        launch_mail
>        NSRunLoop.currentRunLoop.runUntilDate( Time.now + 5 )
>
>
> That code will work the way that I expected it to, but if I try to use a
> proc:
>
>
>        framework 'Cocoa'
>
>        callback = Proc.new { |notif|
>          puts notif.class
>          puts notif.inspect
>          puts notif.userInfo.inspect
>        }
>
>        workspace = NSWorkspace.sharedWorkspace
>
>        workspace.notificationCenter.addObserver callback,
>                                        selector:'call:',
>
>  name:NSWorkspaceDidLaunchApplicationNotification,
>                                          object:nil
>
>        workspace.launchAppWithBundleIdentifier 'com.apple.mail',
>                                        options:NSWorkspaceLaunchAsync,
>                 additionalEventParamDescriptor:nil,
>                               launchIdentifier:nil
>
>        NSRunLoop.currentRunLoop.runUntilDate( Time.now + 5 )
>
>
> It will crash because for some reason I am not getting the notification
> back as I should, instead I am getting a reference to the NSDictionary
> class.
>
> I don't think this is the intended behaviour in MacRuby, but I'm not sure
> if what I am trying to do is supported.
>
> Is the ability to use a proc as a callback a supported feature? It has
> worked for me in other cases.
>
>
> Mark Rada
> mr...@marketcircle.com
>
>
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel@lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to