MACRUBY: WHAT'S THE BIG DEAL?
Last year, Apple released MacRuby, an open source Ruby implementation
written on top of the Objective-C runtime. Writing native MacOSX
applications in Ruby without having to pay the cost of using a bridge
is now a reality. This is an important milestone for Ruby, Apple and
the Ruby community.
Matt Aimonetti explains the implementation, show how to build
desktop applications with MacRuby & HotCocoa, and discuss why Ruby
developers should add this new tool to their utility belt. Matt also talks about the future of MacRuby.
38. # Loading the Cocoa framework. If you need to load more
frameworks, you can
# do that here too.
framework 'Cocoa'
# Loading all the Ruby project files.
dir_path =
NSBundle.mainBundle.resourcePath.fileSystemRepresentation
Dir.entries(dir_path).each do |path|
if path != File.basename(__FILE__) and path[-3..-1] == '.rb'
require(path)
end
end
# Starting the Cocoa main loop.
NSApplicationMain(0, nil)
Friday, February 6, 2009
44. class Controller
attr_writer :friendsTableView
def awakeFromNib
end
def numberOfRowsInTableView(view)
end
def tableView(view, objectValueForTableColumn:column,
row:index)
end
def tableView(view, setObjectValue:object,
forTableColumn:column, row:index)
end
def addFriend(sender)
end
end
Friday, February 6, 2009
45. class Controller
attr_writer :friendsTableView
end
ivar = outlet
Friday, February 6, 2009
46. class Controller
def awakeFromNib
end
end
called when instantiated by nib
Friday, February 6, 2009
47. class Controller
def awakeFromNib
@friends = []
@friendsTableView.dataSource = self
end
end
set the NSTableView data source
Friday, February 6, 2009
48. class Controller
def addFriend(sender)
end
end
button action
Friday, February 6, 2009
49. bind the UI with the Controller
Friday, February 6, 2009
65. def start
application :name => quot;Sdrubyquot; do |app|
app.delegate = self
window(:frame => [100, 100, 500, 500],
:title => quot;SDRubyquot;) do |win|
win << label(:text => quot;Hello from HotCocoaquot;,
:layout => {:start => false})
win.will_close { exit }
end
end
end
RUBY HELPERS
Friday, February 6, 2009
66. application :name => quot;Sdrubyquot; do |app|
end
NSApplication
Friday, February 6, 2009
67. application :name => quot;Sdrubyquot; do |app|
app.delegate = self
end
set the delegation
Friday, February 6, 2009
68. # file/open
def on_open(menu)
end
# file/new
def on_new(menu)
end
# help menu item
def on_help(menu)
end
# window/zoom
def on_zoom(menu)
end
# window/bring_all_to_front
def on_bring_all_to_front(menu)
end
set the delegation
Friday, February 6, 2009
69. window(:frame => [100, 100, 500, 500], :title => quot;SDRubyquot;) do |win|
end
NSWindow helper
Friday, February 6, 2009
70. label(:text => quot;Hello from HotCocoaquot;, :layout => {:start => false})
NSTextField helper
Friday, February 6, 2009
71. win << label(:text => quot;Hello from HotCocoaquot;)
contentView.addSubview helper
Friday, February 6, 2009