?

Log in

No account? Create an account
latest entries related journals calendar about the author My life in pictures older entries older entries more recent entries more recent entries
Today I've been taking a quick spin with MacRuby, which is a port of… - My Thoughts Today
An ill-used association of words and pictures
feyeleanor
feyeleanor
Today I've been taking a quick spin with MacRuby, which is a port of Ruby to Objective-C with the Cocoa frameworks. Not being a Mac programmer (which is shameful considering that I've been coding on a Mac for about five years now) I blagged some example Cocoa code written in Objective-C and nu from the Hackety Hack blog and came up with this little dittie:



	framework 'Cocoa'

	NSApplication.sharedApplication

	class Window
		attr_accessor   :frame, :text_frame, :window, :text_field

		def initialize
			@frame = NSRect.new(NSPoint.new(0, 0), NSSize.new(450, 140))
			@window = NSWindow.alloc.initWithContentRect @frame,
						styleMask:(NSTitledWindowMask + NSClosableWindowMask + NSMiniaturizableWindowMask),
						backing:NSBackingStoreBuffered,
						defer:false

			@text_frame = NSRect.new(NSPoint.new(40, 90), NSSize.new(400, 18))
			@text_field = NSTextField.alloc.initWithFrame @text_frame
			@text_field.setBezeled false
			@text_field.setStringValue "Yay for MacRuby!!!"
			@text_field.setBackgroundColor NSColor.windowBackgroundColor
			@text_field.setEditable false
			@text_field.setSelectable false

			@window.contentView.addSubview @text_field
			@window.center
			@window.setLevel NSFloatingWindowLevel
			@window.makeKeyAndOrderFront nil
		end

		def setDelegate delegate
			@window.setDelegate delegate
		end
	end

	class WindowDelegate < Object
		def app
			NSApplication.sharedApplication
		end
		def windowWillClose id
			app.terminate 0
		end
	end

	window = Window.new
	window.setDelegate WindowDelegate.alloc.init




This looks simple enough that I'll have to make time to play further - perhaps during my pre-RailsConf coding bash in August.

the music in my head: Nonstop To Nowhere-Faster Pussycat-Whipped!

participate