Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created May 14, 2010 07:23
Show Gist options
  • Save mattetti/400917 to your computer and use it in GitHub Desktop.
Save mattetti/400917 to your computer and use it in GitHub Desktop.
MacRuby Hello World
framework 'AppKit'
class AppDelegate
def applicationDidFinishLaunching(notification)
voice_type = "com.apple.speech.synthesis.voice.GoodNews"
@voice = NSSpeechSynthesizer.alloc.initWithVoice(voice_type)
end
def windowWillClose(notification)
puts "Bye!"
exit
end
def say_hello(sender)
@voice.startSpeakingString("Hello World!")
puts "Hello World!"
end
end
app = NSApplication.sharedApplication
app.delegate = AppDelegate.new
window = NSWindow.alloc.initWithContentRect([200, 300, 300, 100],
styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask,
backing:NSBackingStoreBuffered,
defer:false)
window.title = 'MacRuby: The Definitive Guide'
window.level = 3
window.delegate = app.delegate
button = NSButton.alloc.initWithFrame([80, 10, 120, 80])
button.bezelStyle = 4
button.title = 'Hello World!'
button.target = app.delegate
button.action = 'say_hello:'
window.contentView.addSubview(button)
window.display
window.orderFrontRegardless
app.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment