Women in Technology

Hear us Roar



Article:
  Read iCal Data with Ruby
Subject:   Ruby with Objective-C?
Date:   2003-10-16 12:18:56
From:   schromosan
Response to: Ruby with Objective-C?

Here's an example of how to use RubyCocoa from Objective-C. For more information inquire on the RubyCocoa mailing list and/or examine the RubyCocoa API.


/* cc -I/usr/lib/ruby/1.6/powerpc-darwin6.0 -framework Cocoa -framework RubyCocoa test.m */
#import <Cocoa/Cocoa.h>
#import <RubyCocoa/RubyCocoa.h>


int main()
{
id pool;
id obj;


RBRubyCocoaInit(); /* initialize Ruby and RubyCocoa */
pool = [[NSAutoreleasePool alloc] init];


obj = [RBObject RBObjectWithRubyScriptCString: "'hello world'" ]; /* eval string */
NSLog(@"%@", obj);


/* Create a Ruby Time instance */
obj = [[RBObject alloc] initWithRubyObject: rb_cTime];
NSLog(@"%@", obj);
obj = [obj now]; /* obj is a RBObject with wrapping a result of obj.now */
NSLog(@"%@", obj);


[pool release];
return 0;
}