Article:
  Read iCal Data with Ruby
Subject:   Ruby with Objective-C?
Date:   2003-10-04 16:56:53
From:   anonymous2
Hi,


Can one use RubyCocoa within an Objective-C cocoa app. Also, how about some information on what exactly Ruby is?


Thanks.

Full Threads Newest First

Showing messages 1 through 2 of 2.

  • Ruby with Objective-C?
    2003-10-05 12:30:02  rschmidt [View]

    For more information look at www.rubycentral.com. There you will find a free online version of Programming Ruby: The Pragmatic Programmer's Guide.

    Ruby includes a C API to extend it, so you could certainly use that to invoke Ruby classes from Objective-C.

    There might be another way using the RubyCocoa framework and for that I'm trying to get some answers from the RubyCocoa mailing list.
  • Ruby with Objective-C?
    2003-10-16 12:18:56  schromosan [View]

    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;
    }