I've just finished writing a little snippet of code that made me remember why I love programming in Ruby so much, and how great it is that RubyCocoa lets me do so whilst accessing all the glory that is Cocoa :-) So I thought I'd share :-)
It's an application of open classes in Ruby. Basically I wanted a method that would give me an NSImage of any NSView that I wanted. So here it is:
class NSView < NSResponder
bit_image_rep = self.bitImageRepForCachingDisplayInRect(self.visibleRect)
image = NSImage.alloc.initWithSize(bit_image_rep.size)
And to use it:
frame = NSRect.new(0, 0, 100, 100)
some_view = NSButton.alloc.initWithFrame(frame)
image = some_view.captureImage
Although why you'd want to capture the image of a button is beyond me...
Actually, being a bit of a Cocoa newbie, is there a simpler way of doing this?