 Video equipment rental costs paid for by peep code screencasts So I gave a lightning talk at the Mountain West Ruby Conference on this topic And I did a lot of hand waving and I was trying to get it done in five minutes I think I got it done in nine or ten so I failed at that but That lightning talk I wasn't planning on doing it. I got there you know noticed a lot of max and just wanted to go over Ruby Coco and developing desktop applications on OS 10 with Ruby And we'll go ahead and this is the schedule So I'll talk about why me. What have I done that? Let's me stand up here What Cocoa is what Ruby Cocoa is go over some examples of applications you may have used that are actually Ruby Cocoa applications? Do a quick demo so it'll be like the lightning talk, but I'll Take more time and walk through it some more And we'll talk about the future of where Ruby Cocoa is going and some other stuff So the who am I I'm from Boise, Idaho. I Spent most of my Paid software development career working for Equalogic This was the best image I could find because they were purchased by Dell in January and I quit And I'm now an independent contractor under the name of Rubisoft and I also developed some apps Ruvid Both of these apps actually were done while I was at Equalogic Let's you just drop videos on and it saves profile so it'll resize your video and whatnot and Roo switch Let's you Create profiles for any application any Cocoa application so you can have two copies of your address book for work And home whatnot That received a design award from Apple and some other people like it When I started getting to Ruby and rails I started the side project simply in voices it generates invoices So I contract for McCallum media doing Rails stuff Catalog choice org is coming up on its millionth millionth user MLK comm is a German Band promotion site for concerts and we're currently working on this Writing our future where students are writing to the next president and it's going to be published on a map and whatnot I'm a father of these two They get along So what is Cocoa Cocoa is not this Chocolatey drink in this case that was Cocoa, but it's apples Name for all their Objective-C Frameworks so covers things like quick time address book Bonjour Quartz all the display stuff core graphics core animation core sound or core audio rather and It comes from next so when Apple purchased next they OS 10 used to be the next operating system and So all the classes that existed at the time are prefixed with ns for next step And They just never change that never need to When I was working at Equalogic, I got my first Mac off eBay and I realized I needed to learn you know, I wanted to learn how to program on it and how to develop native applications for this platform that I'm falling in love with and I noticed that Compared to the embedded systems type work. I was doing Cocoa and Objective-C and just executed the whole platform really did actually make it quick and efficient And the same sort of thing happened when I got into Ruby and Rails, you know, it was like wow This is way better than PHP which I had played with So Cocoa is built with Objective-C and it's not as bad as it sounds It's actually fairly nice ones you get used to the brackets. So it looks like this here It's just allocating an array and initializing it with two strings So there's some similarities between Objective-C and Ruby they both pull some stuff from small talk But so messages are sent objects. You don't call functions. You send messages to your objects. It's not strongly typed although it is C and There are definitely types You can everything falls back down to pointers are passed around and it's works out well Classes are kind of open. You can use what they call categories to add methods to classes, but you can't add properties or Really do it all that you can with Ruby, but You can add to it with leopard Apple Shipped Objective-C2 and that does not have blocks that has the garbage collection and stuff in snow leopard They're shipping Objective-C 2.1. It's going to add blocks and some other cool stuff So it's on the way with Objective-C. I found when I was sort of digging up all this stuff Wikipedia has a really good entry on Objective-C to just go over the highlights and how it's different from C and C plus plus and covers that stuff So when you're developing a Cocoa application Ruby Cocoa Pi Opsi or whatever it may be you're going to use Xcode and interface builder There you probably haven't installed they come on the OS 10 disc. They're free You can register at developer.apple.com if you want the latest or if you don't have it So Xcode is where you spend most of your time. It has this new organized feature It's new in leopard and it sort of just lets you build you drag your project in there if you want to see a Listing of your projects and you know easier to open them. I guess It's new in leopard. I haven't really gotten into it. I'm not sure of anyone who does you can see the the devices That's where phones show up if you're doing that sort of stuff It edits if you want This is what it looks like. It's a pretty good Objective-C editor. It's a pretty bad Ruby editor a good example of this is if you select some code and you hit the shortcut the keyboard command to comment out That block of code it uses C slashes to comment it out So there's some and I'm sure they're working on that You know it was first an Objective-C editor and they've sort of just put in the Ruby stuff and Python stuff as they've gone along So it's coming But you can tell Xcode when you double click on a dot rv file open up your favorite text editor and it'll do that So it builds it manages The whole build environment so you can give it tasks you can create new tasks if you want to work with Something in your build stage. So a typical example is if you want in your about box You want it to say 0.1 and then in parentheses the get revision or SVN revision you create a Build task that just pulls that you know queers that shell script that queries that puts it into What they call your info dot plist which describes your application and then it shows up there It's a really good again really good objective CD bugger It's using sitting on top of GDB and the compiler sitting GCC compiler. So it's standard stuff with a pretty front-end But it's not so good with her. I haven't figured out how to make it so good with Ruby. So I've fallen back. This is the Console where you'll see your log statements and stuff. So when I've been doing Ruby Cocoa stuff I've actually fallen back to doing sort of more printf style debugging, which is unfortunate, but it's not as Often that I go there that then before and it teaches the documentation. This is within the app within Xcode and Their Apple's documentation is actually really good They've got both. This is an example of a Reference for a class really good pointers to other places and they also have these Companion guides and those are really good as well. They sort of just walk you through You know, this is how you do this blah blah blah blah. It's pretty good And I think you know, they sort of feel obligated to that Cocoa is not open source. So they sort of have to give us decent documentation and It's rarely just flat out wrong. Sometimes there's some steps missing or whatnot, but it's usually pretty good Interface builder is where you'll spend your time when you're laying out your UI This is what it looks like and it lets you just drag controls on standard controls. You set their sizes All that sort of thing and we'll see that in the demo It's also where you if you want is where you sort of glue your code to your interface And we'll also see that and we'll talk about that So KVC KVO and bindings KVC is key value coding and at the base of every Cocoa class is an NS object and it defines a set value for key and a value for key function and What those do is it lets the caller pass in the string of the attribute that it wants to set and if a if the receiver defines a set phyto the set phyto method is going to be called if it has the attribute phyto, it's going to get set and value for key same sort of thing if there's a Method to return phyto, it's going to call that otherwise it's going to use the default implementation so here we're just setting number five and We get it back and the key value coding works with Always works with objects. So we have we can't just pass in five We have to say NS number and the reason for all this is working with bindings in interface builder You can so this is interface builder if we were wiring up this slider to our app controller and Over there. We can see we're wiring it wiring up to the phyto key path they call it and that's going to call that set value for key path phyto And that's going to set our value and when they need to know what the value of the slider is it's going to call the get value for key or value for key rather and Key value observing is also what bindings and What bindings use and that's because before in The NS object set value for key before it actually sets the value It sends these this will change value for key letting the observers know Hey, something's going to change in case they need to know and then it's also when it's done it's going to call Did change value for key and this is just letting the interface now So if you go behind the scenes and you change phyto to Phyto plus one in this case it needs to know that the slider needs to get bumped up and this is how it does it It's observing it. It sees it So if you did have this increment phyto method you would have to do this will change value for key and then did Change value for key if you were using bindings and you needed to Have the UI change So that was all just Cocoa specific. What is Ruby Cocoa? It's a bridge. So it lets us right talk to the Cocoa frameworks in Ruby and You know as it goes between Ruby and objective C Ruby arrays become NS arrays their Cocoa equivalent Strings become NS strings and back and forth they go if there's no equivalent you'll get the The Ruby version of that Cocoa class so an example is actually an NS number which could be a double float It's just their generic number class. You'll get that back and You'll have to say to I or whatever it is you want to do to it This is what Ruby Cocoa looks like Well, that's what objective C looks like. This is what it looks like in Ruby Cocoa It's just Ruby in this case because we're using an array. I cheated on this slide. So We're just using brackets instantiating the array. It's a lot nicer than It's objective C version less words Cocoa is somewhat verbose and You know sometimes that's nice. Sometimes it's not one problem when they Sort of bridged this was that in objective C the way you Why the way methods are defined is the parameters are actually named and broken up like this So if you wanted to call path for resource You have to type out, you know, whoever you're sending it to space path for resource colon that Parameter you want as the string there and then use space of type and then The other parameter that you want so in Ruby Cocoa. We can't really do that because it doesn't fly So what they do is they translate it to this path for resource under of type so anytime you see a colon you can just change it to a underscore and You can also have a trailing underscore because you'll see of type has a trailing colon They made that optional because it's kind of ugly if it You always have that trailing so some examples GitNub is useful for It's sort of like GitK if you've ever used it with a Ruby Cocoa UI on front of it so it shows you your Git log and you can easily go back and forth between branches and Pull out the version numbers and whatnot or just look at the diffs and Well, I was preparing this talk. I moved a couple rails applications over to the Thoughtbot guys Hoptode app and it just lets you push exceptions up to this web app instead of having them, you know at the time I was receiving them by email So now they get pushed up to this app, but you know, that's good and they're all in a central place and You can click on them and see more details and say okay, this one's resolved and that's kind of nice But I wanted something more immediate to know when an exception happened and it was a great they have an API It was a great Chance to use Ruby Cocoa So I created this croak app. It's Open source on GitHub. It doesn't look so great yet But it's just you know, it steals the UI from Twitterific and It's a Cocoa app. It's and it's but it's Ruby the active resource is behind the API that pulls in the errors So that was fun to do and then if you actually go to GitHub and search for Ruby Cocoa a good number of 25 or so projects come back some of them larger than others Some of them better code than others, but you know if you wanted to just poke around and see what people are doing and Get some ideas and what's possible and whatnot. They're there So now we'll dig into the demo now that we've sort of got the Cocoa and what is Ruby Cocoa and it's going to be a really simple demo. It's going to use the faker gem to Just generate some random names for us and then we're going to use Cocoa to slap them into address book So we'll go ahead and do that So we switch to Xcode I'm actually going to launch something since I restarted. It's not all quite set up how I want Okay Say new project. There's a bunch of options What if you go into the applications? Under Mac OS 10 you have the option for Cocoa Ruby. It's Of course Ruby Cocoa ignore what they'll try and tell you so we're going to call this friend faker and right out of the box it sort of creates a Somewhat a framework of an app build-and-go just compiles the what objective see there is and copies over the Ruby files So this is what it looks like and it resizes and it's got some menus and quit that and The first thing we're going to do is lay out the user interface and the interface builder works with the nibs and now Zibs in XIBs in leopard and That's basically in the case of a zip. It's an XML file that defines where your controls are and all this stuff A nib is actually a bundle that defines it in a more complex way, but we'll leave it as a nib for now Double-click that and we go to interface builder and This library over here is the all the controls we can pick from Some of them make more sense like the buttons are obviously buttons, but some of these other things are abstractions So what we're going to do is? It has this little search box down here We're going to create a label drop it in there It's going to tell us how many friends we want We're going to fill that in in a text field We need a button And that's going to make friends these little blue lines are just guides that Are so many pixels apart from the different controls and the number of pixels is defined in the human interface guidelines which You know you may or may not want to Go with so we're also going to come in and pull a multi-line text field So we're going to enter in How many friends we want we're going to push the button and it's going to go and make the friends and then this Multi-line text field it's just going to be for logging. It's going to show us what friend names were created So that's all well and good interface builder lets us simulate the interface So instead of having to go back to Xcode and build and go and see how it works when the user resizes or they tab That sort of thing we can just do this simulate And we'll see you know nothing resizes right now, and if we make we can make it, you know completely invisible and That's not good, but so we want to make the multi-line text field expandable. So if we Want to see more names or whatnot we can do that If you type in text you don't have it Multi-line text field You're on leopard That's a good question. Yeah, I think yeah Maybe they added it in 3.1. I'm somewhat surprised, but you can just make that You can make that a text view Yeah, and that should work fine and that'll actually work even better, but So We want this Multi-line text field and if you have questions feel free to to jump in But we'll make this multi-line question multi-line text field We want it to grow with and height and we want it to be bound to where it currently is On the both the right and bottom edges as well. It was currently only bound to the left and top this Is referred to as springs and struts and it's really cool in that you can just you know drop it in there and say You know make this resize grow And you can do some fairly complex things with just that so now if we go back and we say Simulate it should now resize correctly and But when we shrink it all the way down we can see at the top there it didn't quite do what we wanted and really we don't Want The application ever to shrink that small anyway, so if we go to the window we can say In the inspector we can say that it has a minimum size and that minimum size should be the current minimum size And there's just a bunch of attributes for each of the controls that you can change so We simulate that we should be able to grow it but not shrink it and that's good so another thing Cocoa provides is Some formatters so we can actually We go to the library and Is that better or is that not enough? We can search for formatter and there's this number formatter So there's how many we don't want to accept just anything because we'll have to deal with that in our code but we can tell Cocoa that we only want it to be numbers And we wanted to have a minimum of one and there's all sorts of you know these different attributes you can set and these constraints and now When we simulate we should Did I say print? If we type in five, it's not going to let us tab away and It's just going to keep focus there and that's because it wants a number and now we can tab away So it's kind of a nice thing you don't have to worry about When you read that attribute you don't you don't have to worry about being a string or how big it was and it also The default settings is it's an integer. So it's going to round for us And that's exactly exactly what we want. So we're going to go with that Now that we've sort of laid out our beautiful interface here we have it functioning the resize is working and whatnot we're going to go ahead and Wire up the make friends button. So to do that. We need an application controller that's going to take receive the action and then do something with it and Before I do that. I'm going to go into this RB main and this is really where all of the Startup stuff happens. You'll see it pulling in all the Ruby files in the bundle and whatnot, but this is where we're going to go and We're going to require Ruby gems and we're going to Baker and while we're here There's I also like to include the OS 10 module. Otherwise as you can sort of see down here, you have to prefix all your References to Cocoa classes with OS 10 colon colon and it gets old And I'm also going to Pull in the address book framework And you do that saying require framework address book And now we'll have once this compiles will have access to All the address book stuff. So although if we were to look in our frameworks We'll see that we're linking with Coco, but they don't for Reasons of you know trying to having to link against a giant library they break it out. So although Cocoa Does cover address book and quick time and all this other stuff when you actually start writing an application that you want to Use those They're actually in a sub framework of Cocoa and in this case. It's address book Quick times in Qt kit and some other stuff So we're going to do that save that and now We need to create our class that our controller class So you can put it anywhere, but they've got it broken out. You could create a controller subfolder Do it however however you want Say a new file and Again, you know it lists everything you can create it defaults to What you last did so in the case of this? That's Ruby Cocoa and the NS object subclass and That's what we need We're just going to create an application controller. We don't need all that stuff since It's taking for taking care of us taking care of for us by RB main And we need an action to be called so now that we have our controller We need to define what gets called when they push the make friends button So to do that Ruby Cocoa has a I be action function and We're going to name it. You just say I be action make friends and it takes a block It takes an optional argument All the actions in Cocoa Take an argument and that argument is whoever whoever sent you that Action it passes themself as the sender But we in this case we don't need it sometimes It's really handy if you were for whatever reason to have a button that called this as well as like when the user double-clicked on Something in a table view you might want to know did they click on the button or did they? Click on the table view So all we're going to do in this case is just Log a message So now that we've done that it's actually done nothing it's going to be included in our program But it's no one's ever going to call it We have to go back to interface builder and wire up the make friends button But in order to do that The make friends button needs some way to know who the application controller is so in this case What we need to do is create an instance of the class and We define this take this NS object and we're going to say that that this instance is actually an instance of our application controller And we tell it what it is in the inspector The class And you'll see it auto completes for us, which is really nice Xcode and interface builder know about each other, you know, they're monitoring the files and it parsed that if I had a parse error in my Application controller dot rb it actually wouldn't have auto completed because it needs to know that it's a inherits from NS object and that sort of things but in this case it was good and Found it for us So now yeah When you go to interface builder it should if you're in Xcode if you double-click on In resources if you double-click on main menu nib should bring up interface builder and That's the main window controlling the nib so that that defines what's in the nib so that should definitely be there. Oh It might be you might see it like this see the The bigger icons oh right there the I prefer the Outline view because you can actually drill down and see you know inside the window as a content view So that's handy So we've defined this now when this nib loads which in the case of main menu dot nib is immediately or during application start When this nib loads, it's going to create an instance of our application controller And it will send it some some messages that we may or not respond to and we'll talk about that in a second but We can now talk this button can now talk to this nib and one of the cooler things in interface builders how you assign The actions so in this case You help you can help you can either double-click it and you can go down to Or I think in the case, I'm sorry not double-click, but right-click it And we have to do it you have to do it backwards in that case Sorry, I'm not prepared for that But you can say make friends and drag it to Who is going to be sending that and in that case it would be the make friends button? But I don't want to do that. I Prefer to drag from the action to the receiver So in the case of you hold down control click on the button or whatever it is that's sending the message and Drag it over to the controller. It's going to pop up all the Methods that are defined with or all the blocks that are defined as I be actions and in this case we just have the one make friends. It's now wired up you can see all the Connections that are made in this button connections in the inspector. So we've successfully wired that up so now When we start a program, we'll have an instance of our application controller and the button should send us this message and We're going to have to go back to Xcode to see the log and it logged it and Every time we push it it logs it So that's a step in the right direction now we need to wire up the the how many and we're going to do that with Bindings one thing we could do is in our code we could say We could set up an outlet and that says Make friends text field and we could wire up the text field to the controller and then the controller could query the text field But that whole KVC KVO stuff and the bindings that I talked about Makes it such that in a such a simple case like this the text field can control the value of your Property so some people like it some people really hate it Because they want to you know have written out explicitly everything they want going on in there between their controllers and their view But in this case we're going to use it So to do that we go back to Xcode and since it's going to be a property of our application controller We just come in here and we use another ruby-coco Nicity KVC accessor Number of friends and Now when we go back to interface builder We can click on that text field We can go to the bindings portion of the inspector and it gives you a handful of different Bindings to to make and in this case we want to bind the value so anytime the user needs to see the value and anytime The user changes the value it's going to go to our application controller and either set or get whatever we tell it And in this case we're telling it number number of friends There's some attributes you can do some Validation and whatnot and this transformer stuff so if it was a boolean you could say You know negate it before I ever see it that sort of thing That's useful for checkbox, you know, whether something's enabled or checkboxes Things like that so now Our text field is or our text field is wired up to our number of friends. We can come in here and we now have a Number of friends method we can call and I briefly touched on this before when I was talking about the bridging between Ruby and Objective-C the number of friends since we set the Number formatter on it. It's going to come to us as an NS number It's not going to come to us as it normally it would come to us as a string But since we told it to validate it as a number it's going to help us out and send us An NS number which could be in the case of NS number. It could be a double afloat what not we know It's going to be an integer It's already been rounded for us, but in order to call dot times on it. We have to make it Ruby integer so we call two I times do And we'll just log our message for now Right, and if we I've been using the keyboard shortcut, but the little tool the build and go is what I've been using It just compiles everything and then runs the application. So now if we say we want five friends Go back to the console and printed the log message five times pretty much what we wanted. So now we want to Let's actually use the faker gem and say that f name equals faker name First name l name equals faker last name So now we should have a generated first and last name From faker and we'll just log that now We've already required it before in the RB main because we knew we were going to be using faker and whatnot The text field in the case where it's using bindings it's not actually going to call the the set method on our attribute Until I tab away from the field then it knows that I've ended editing you can do some things to say That it should you know constantly update that field and that's useful in the case Or usually more useful in the case of sliders where you want the slider to immediately affect like the contrast or something But in that case I hadn't tabbed away so it the value was still nil and we did it no times and now we've got five Generated names so we're again moving in the right direction And at this point we're done with Or no, I'm sorry now. Let's log those messages to the interface So we're going to just put instead of logging into the console and having to look back and see what they were We're just going to plop them in this multi-line text field and To do that. We're also going to use bindings And we're just going to call it log Go back to interface builder We've already got the bindings inspector up And we just say that we want to bind it to our application controller And it's just listing everything that the nib knows about here if we had other controllers that could be bound to they'd show up here As like the file's owner application will not do So we just called it log So in the case of how many we were the user was sending us the value and in this case We're pushing the value and bindings just work both ways So now instead of NS log we can do Self.log equals put a carriage return at the end and then the rest of the log and Since we're Adding the string value of the the log here We need to initialize it before we can add it otherwise it'll crash saying that self.log returned nil And in order to do that we're going to use this awake from nib method and I've talked about before when we when Our controllers were in an object is instantiated from the nib. So because the nib is loading itself It's going to send some messages one of those messages is that This awake from nib it means, you know, everything's wired up bindings are good to go If there's a view the user is about to see it That sort of thing so this is a perfect place for us just to say self.log equals nothing or empty string rather and If all went well Say we want five friends and they show up here now and it's just going to keep adding them So now we want to that's we'll be cocoa interacting with the UI and stuff but Really, it would be nice to or to really the point of this application is to use the address book framework in cocoa to push them to Push the names into the address book and you could actually see a use for this if you were building an application that used the You know a pure cocoa application that used the address book framework You'd want to test it with you know 2000 records or some thousands of records So this would be a great little tool for that and It would be easy to generate with ruby cocos we're doing here So I'm going to cheat for a second and I'm going to pull in this text clipping That just has the code written out for me to save some time and more importantly save some typos So but we'll go through it line by line We allocate this a b person address book has a set of classes one of them is a b person you can also create groups in address book But here we're creating a person We're going to call through the API the set value for property for a first name last name. We're passing our ruby strings Even though these this set value for property wants an NS string and In the case here the second parameter is the property and it's a constant defined in the address book framework and The way we're going to reference that is with the OS 10 colon colon and then capital K a b first name property If you look in the documentation They did the address book frameworks to find it as lowercase k. We have to make it uppercase For ruby so we go they go ahead and take care of that for us. So we set first name last name we add the record and then we Save the address book off and this address book dot shared address book Returns the system copy of the address book so When we run this we're going to be Adding these names to my address book and we'll see that when we're done And then we're going to save it and this save really wants to be outside of the loop here Because we just want to save when we're done So I think Again if all went well We're done with the UI we're going to create some names create 10 friends goes ahead and creates them and This is a smart group that just says show me all the people with no emails and no phone numbers. So that matches our gene after hire should Show up here. So we're creating them and that's ruby coco a little example of How to create a potentially useful application? So I'm going to spend a little bit of time talking about why you would use ruby coco and Also, I'll talk about why not It's ruby. It's you know a language if we're here. We clearly enjoy working with it You have access to all the gems You saw the require ruby gems you can require whatever gem you want and in the case of git nub it uses I think the open for gem if I'm right and they actually ship that with the application So you don't need to worry about if it's on the system and you just put it in the bundle and you require it from out of your application bundle so Just to make that more clear and in application in OS 10 is just really a special folder And you can have whatever you want within that folder if you right click on an app and say show package contents You can drill down and see what's in there You can actually with IRB you can Talk to this stuff. I was I Went over the the friend faker thing on my flight into Austin and I used IRB. You just require OS 10 slash coco You say that OS 10 that require framework and you can just start working away with those classes Assuming you're not doing anything with windows and whatnot. It's it's great And so if you want to play around with ns array and see how it acts and or whatever class You can do that and as we saw it's great for fast prototyping. You know if this was a Application we wanted to you know just see how it how it worked out We could use Ruby Cocoa for that and It's pretty good for that and it's Cocoa It looks correct. It feels correct and it's fun. I've got a sort of strong opinion that You know WX widgets and even now Adobe Air They they definitely have a place and there's application. You can make great great applications with them But really if you're creating you want that standard look and feel you really have to use the the packet or the what's available on whichever OS you're on And in the case of OS 10 that's definitely Cocoa and the reason just you know the different operating systems act different Tab orders are different. You know some things are probable and you just really want Cocoa to make sure you get that Otherwise, you know if you're trying to do a cross-platform app What is correct on Windows isn't correct on OS 10 and you know, it doesn't always work out well So why not Ruby Cocoa? That jumped a little bit Performance if you're doing something performance critical You can certainly call into Cocoa and let that rip array rip away at it But you're always going to have the cost of Crossing between the two worlds. So you're every time you go to from Ruby to Cocoa You know, it has to say are you an array? Okay. Now you're an NS array And on the way back. So there's some there's some cost to that and Unless you do anything about it Your dot RB files just ship in that bundle that I talked about so you can say to get enough you can say or any Ruby Cocoa app you can say show package contents and you can see the dot RB file and all their code You may or may not care if it's an open-source app like Ruby Cocoa Get now you definitely don't care But if you're trying to make a commercial app, you could have to jump through some hoops to make sure You know, it's not super easy for them to steal it But you know some some packages just put it out there and say please pay for it and do very little The debugging was you know, just not so great compared to Working with an objective see Cocoa app and I'm not so sure What's going on if they're working on that or if I'm just missing something completely? So what next if you want to do this? I actually recommend learning objective see you really want to learn How objective see works how the the Cocoa frameworks are actually talking to each other and whatnot and to do that This gentleman wrote a really good book that Myself and a lot of people recommend Cocoa programming for Mac OS 10 It's covers objective C or it's all in objective C And it goes through a lot and it's really well-written It's in its third edition third one just came out covers the new leopard stuff There's also a new book from the pragmatic programmers that I have not checked out, but it's in a beta PDF I think specifically about Ruby Cocoa I Imagine that'll be good as well So the future Ruby Cocoa actually has Some competition in Mac Ruby, and I think that was mentioned this morning Mac Ruby is Ruby implemented in the objective C runtime sort of I my understanding is that That's very much like J Ruby in that it's got its own gem repository and whatnot and it's a in that case it bypasses the The bridge and it's talking directly to Cocoa classes and whatnot and it looks pretty promising It's being developed by Apple open source But they are going to fully support it they do claim to build still support Ruby Cocoa they had Adopted Ruby Cocoa and out in leopard, and I don't think they're going to just drop that and for the most part the stuff you learn Mac Ruby right now isn't quite ready for Even like I don't At least with the version that's published we couldn't do that The friend faker because we couldn't actually talk to gems With Mac Ruby yet There's I think in October is in is their next release and it's supposed to have gem support and some other really good stuff So the obvious question is is Mac Ruby going to be in snow leopard and nobody knows they don't you can be talking to Apple And they're really nice people At one time I was at WWDC talking to them about some Cocoa stuff And you can there's just you know humans and you're talking to them And all of a sudden you ask them well, will this be fixed or whatever in the next release and they just turn into these robots Like we did not talk about future products So who knows But Mac Ruby You can see the first two lines is the first one's objective C then Ruby Cocoa and I talked about a little bit You know you have to do this jump through these underscore hoops Mac Ruby takes care of that with a new little extension to Ruby that just said lets them say Instead of having to do the underscore game. You can pass the name of the parameter and it's just nicer. There's no real benefit I Had a this at the last minute, but Tim Berks Spent a lot of time. He wrote a lot of the articles on Ruby Cocoa comm and He did a lot of Ruby Cocoa work and he got frustrated with it with the how the bridge worked So he started and in January of I think 07 he Published Ruby obj see Which it would have been which would be an alternative to Ruby Cocoa and some months after that He got frustrated with that and dropped that and he came up with new new is Lisp with like a Ruby to spin to it and it talks to Cocoa and it does it much like I'm actually not sure how the bridge works or if there is no bridge like in the case of Mac Ruby, but I'm pretty sure that's the scenario where there's where there's no bridge. It's implemented in the VM So thank you. Here's some links That were covered The I'll put my slides and that demo application. I'll check in to github at bright cook slash LSR see Ruby Coco And if we have time I'll take questions Yeah, you can it's You can program all the NS window stuff and you can work with the Layout manager directly No, it'll be it'll be yeah, yeah, because you're gonna have to do a lot of drawing yourself and positioning Yeah, sorry Yeah, so the program you wrote if you write something else that you discovered it was very good You want to take it? Making more the performance use all the Visual stuff and just swap out the Ruby for a bit of scene So the question was could we take that Ruby Cocoa app and Turn it into an Objective-C app with just leaving the views there and you definitely can You'll need to rewire everything up. So an interface builder where I wired up The make friends button in that class you're just gonna have to redo that stuff So but as far as the visual layout goes you can definitely keep that that's Cocoa specific and And the where he's there Think we'll go here and then For like testing and stuff I haven't there are some Some blog articles about doing TDD and BDD with Ruby Cocoa, but I have no experience there No, oh, I'm sorry you definitely can Yeah, I was supposed to talk about that but in the case of that croak app that I showed you There's a session. I or not a session ID, but a API token that haptode app gives you and I store that in the key chain and there's no Cocoa Framework for working with the key chain. So somebody published an Objective-C wrapper around The what they call carbon, which is just their straight-C interface they wrapped it in Cocoa and I included that in the project You just have to tell Ruby that it exists and then once you do that and once it's in your project and compiled You can call it and so you can you can include it straight Objective-C files Or you can actually have if somebody published a third-party framework a good case of this is like Sparkle Is the auto-updater framework and get enough uses that they talk to the framework? It's written Sparkle's written in Cocoa a lot of Cocoa Objective-C apps use it, but Ruby Cocoa can talk to it. No problem and you can yeah define your own whatnot Any other questions Sure, I mean it's Ruby so You can do whatever you want when you're in your when your Ruby codes being executed Whatever you want limited to Well, this is more of a limit limitation when you're talking to Cocoa, but you can't use any of the Threading stuff that Cocoa provides. So there's some pretty cool distributed object stuff that it does All that's out, but that's coming with Mac Ruby that'll all be available So but as far as pure Ruby stuff when you're in Ruby, it's it's Ruby It runs the system library one that that it comes with so if you hand-built and put it in like the user local bin or something It should stay away from that one You could probably tell it to you know relink whatever and if you wanted a different version of Ruby But Any other questions, okay. Thank you. Oh, sorry If you're trying to ship an application that runs on The question was between differences between tiger and leopard Ruby Coco was only adopted For leopard as far as apples concerned So if you're running tiger the only way you're gonna have to manually install Ruby Coco So at that point you get whatever version of Ruby Cocoa you have at the time so Hey, I think we're done. Thank you. That was fun video equipment rental costs paid for by peep code screencasts