[MacRuby-devel] sub classing with hot cocoa

Benjamin Stiglitz ben at tanjero.com
Tue Dec 2 13:37:29 PST 2008


> I am sure there is an easy answer to this question, but I have not  
> figured it out after some experimenting (nor can I find an example  
> in the examples)
>
> What do I do if i want to subclass (say) an NSView ? And yet still  
> employ that subclass with all the rest of the hot cocoa magic? (so  
> without using nib/xibs)
>
> I would do this to overwrite the drawRect callback for NSView for  
> example - perhaps to do some animation.

class MyView < NSView
   def drawRect(r)

   end
end

or, even better in some cases

a = view(:something)
class << a
   def drawRect(r)

   end
end

-Ben


More information about the MacRuby-devel mailing list