Eleanor McHugh (feyeleanor) wrote,
Eleanor McHugh
feyeleanor

  • Music:
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.
Subscribe

  • Back in the US again in October:)

    In mid-October I'll be speaking at Strange Loop in St. Louis about Google's exciting new systems language Go and my open-source GoLightly project.…

  • Letter to my MP regarding the Digital Economy Bill

    Dear Andrew Love, Thank you very much for your letter dated 22nd March in response to my email enquiry concerning the Digital Economy Bill. I…

  • To Dream of Real-Time Ruby?

    My RubyConf 2009 proposal which alas didn't make the cut. Summary Ruby is a beautiful language, and because of that beauty we tend to ignore the…

  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments