Then I write an article about using TimeMachine over a wireless connection. Just days after the magazine hits the stand, Steve Jobs announces Time Capsule.
Now, I've just finished a pair of articles on RubyCocoa. They haven't even been published yet, but Apple's already at it again.
Today, I just learned about a new, open source project backed by Apple, called MacRuby.
MacRuby is a Ruby 1.9 port that runs on top of Objective-C. It's not ready for prime time yet, but it looks promising. First off, it is Ruby 1.9--which I think is a great thing. Among other things, this means it will be much, much faster than RubyCocoa, which uses Ruby 1.8.
From there, things get really interesting--and just a bit odd. All MacRuby objects are subclasses of NSObject. Because of this, they inherit all the base object methods from both Objective-C and Ruby. They've also added an expanded syntax for keyed attributes in method calls.
So,
[person setFirstName:first lastName:last];
becomes
person.setFirstName(first, lastName:last)
or
person.setFirstName first, :lastName => last
You can even write your own classes in Ruby that use keyed attributes:
def setFirstName(first, lastName:last)
@name = "#{first} #{last}"
end
Of course, you can do all the cool RubyCocoa tricks. Make calls back and forth between the Objective-C and Ruby portions of your code. Import Cocoa frameworks. Etc. But, in MacRuby, it all looks just a little bit tighter.
For example, MacRuby's String, Array and Hash classes are simply subclasses of Objective-C's NSString, NSArray and NSDictionary. This lets you transparently pass objects between Ruby and Objective-C.
I look forward to playing around with this project as it develops.
-Rich-
1 comment:
Hi Rich - this isn't directly related to this post, but I figured it's close enough. I sat down this morning to run through your first RubyCocoa article in the April MacTech, but got stuck right here:
"First, download the source code from ftp://ftp.mactech.com/src/."
So, I don't know if the code was ever there, but I certainly can't find it now. Any chance you could send the missing file(s) my way? I don't suppose you can do much with the tutorial without this...
Thanks,
Patrick
Post a Comment