18
| My first OS X application Eric from blog.8thlight.com helps me to run my first OS X application in Ruby Cocoa. Sweet |
So, starting to look around how to make my way trough the OS X development I decided to look into Ruby - and more precisely RubyCocoa. I looked into XCode and Interface Builder. Huh ? What's that ... darn ... At first sight these 2 really look awkward, drawing lines around and stuff ... Creating classes without actually creating them ... I'm confused.
I decided to look into something easy to start up. I googled around and I found a great article. It was just posted (well ok a day ago) and had lots of screenshots and lots of explanations. Just the thing I needed.
http://blog.8thlight.com/articles/2007/08/13/rubycocoa-tutorial
For everyone looking for a something small and simple in RubyCocoa I recommend it.
However let's see what happen onwards. I built my interface as explained. I found XCode set of interface controls a little bit poor. Ok ... adding a button is a blast, but searching for something more advanced is ... a bummer. After I added the text fields and text as described in the tutorial

I decided to also add couple of other stuff (hehe ... programmer never goes exactly after the tutorial) well ... adding an image was a weird procedure, you have to first select an image to import to images pool, then add an image and enter the name of the image in a text box ...
I maybe think way ahead ... but, in any other similar software you browse for an image and it's added to the resource pool and selected for the image object you're adding to the interface ...

However besides several of these issues I built my interface and happily continued to the Ruby writing part.
Now I should say the code is lovable (as expected) ... let's see :
class CurrencyConv <OSX::NSObject
ib_outlets :origAmm, :rate, :data, :newAmm
def convert
origAmm = @origAmm.floatValue
rate = @rate.floatValue
newAmm = @data.convert origAmm, rate
@newAmm.setFloatValue newAmm
@origAmm.selectText @origAmm
end
end
Pretty easy ... few gotchas however, no initialization in Cocoa .. (uhm), using methods and properties on the Cocoa objects is cool and intuitive but still you may need to look in the the API (uh ! apple documentation ... ) but in brief it's cool
That's pretty much it ... few lines of Ruby, Interface builder, Xcode to compile and run ... seems like pretty fast track for building nice Cocoa applications.
I liked it. Gonna do some more :)
Marin

Hi Marin
I followed the link from Eric blog.
Here is some comments you may find interresing:
If you don’t like xcode, have you tried the newcocoa gem:
http://metaatem.net/2007/05/27/your-first-few-days-on-rubycocoa
It has a structure very similar to rails projets.
You can even write a little ruby script to open your app in Textmate (http://macromates.com/):
#!/usr/local/bin/ruby
# newapp
if ARGV != []
puts %x{ newcocoa #{ARGV[0]} }
%x{ mate #{ARGV[0]} }
else
puts ‘Usage: newapp [appname]’
end
I put it in `/usr/local/bin` and `chmod +x newapp`, it’s very handy and keep you away from xcode. Double clicking on nib directory in mate project drawer open the file in interface builder. By using the `rake` methods of the link above, you can even build your application inside textmate.
Have a look also on http://rubyobjc.com, it’s the same person that maintain http://rubycocoa.com.