Skip to content

Instantly share code, notes, and snippets.

@skahack
Created April 5, 2011 06:13
Show Gist options
  • Save skahack/903113 to your computer and use it in GitHub Desktop.
Save skahack/903113 to your computer and use it in GitHub Desktop.
framework 'Cocoa'
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
class MyWindow
def initialize
app = NSApplication.sharedApplication
window = NSWindow.alloc.initWithContentRect([200, 300, 300, 100],
styleMask: NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
backing: NSBackingStoreBuffered,
defer: false)
window.title = 'MacRuby: The Definitive Guide'
window.level = NSNormalWindowLevel
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.orderFrontRegardless
@window = window
end
def window
@window
end
end
app = NSApplication.sharedApplication
app.delegate = AppDelegate.new
w = MyWindow.new
w.window.display
app.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment