require 'OSX/cocoa' class CloseDelegate < OSX::NSObject def windowWillClose( sender ) OSX::NSApp.terminate_ sender end end # Instantiate the shared App OSX::NSApplication.sharedApplication window = OSX::NSWindow.alloc window.initWithContentRect_styleMask_backing_defer_( OSX::NSMakeRect(50,50,200,400), OSX::NSTitledWindowMask + OSX::NSClosableWindowMask, OSX::NSBackingStoreBuffered, true) window.setDelegate CloseDelegate.alloc.init window.makeKeyAndOrderFront nil # run the main loop OSX::NSApplication.sharedApplication.run