Created
May 14, 2010 07:23
-
-
Save mattetti/400917 to your computer and use it in GitHub Desktop.
MacRuby Hello World
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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