[MacRuby-devel] macruby-bundle-example

2009-08-15 Thread Clay Bridges
Hi all,

When I was first figuring out how to call my ObjC classes from MacRuby, I
greatly benefited from Pieter de Bie's excellent minimal, xcode-free example
of this, macruby-bundle-example. I spiffed it up a bit.  Here's the github
link: http://github.com/diffengr/macruby-bundle-example.

It might be helpful to link to this or its like in future tutorials on this
subject.

Cheers,

Clay
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


[MacRuby-devel] forwardingTargetForSelector vs. MacRuby 0.4

2009-08-15 Thread Clay Bridges
Hi all,

I'm using a forwardingTargetForSelector: to create a wrapper class in
ObjC. It seems to work in ObjC, but when I try to use it in MacRuby
0.4, I get an error. As usual, it's likely I'm doing something quite
foolish.

Since it's kind of a complicated setup, rather than trying to describe
code via email, I've created a minimal-ish project in github
containing ObjC and MacRuby code to illustrate the problem. (I say
minimal-ish, since I'm using XCode). It's here:

http://github.com/diffengr/macruby_forwarding_invocation_example

That contains an XCode project and a rakefile. It has the ObjC classes
Candy and CandyWrapper, and they both have the NSString* property
flavor. CandyWrapper declares that property @dynamic, and forwards it
to Candy.

Here's the code that works in ObjC.

  Candy* rootBeerCandy = [[Candy alloc] init];
  rootBeerCandy.flavor = @"Root Beer";

  CandyWrapper* rootBeerWrapper = [[CandyWrapper alloc]
initWithCandy:rootBeerCandy];
  NSLog(@"Candy#flavor \"%...@\", Wrapper#flavor \"%...@\"", 
rootBeerCandy.flavor,
      rootBeerWrapper.flavor);

If you load and run the xcode project in this directory, you'll get this output:

  NSLog[...]  forwarding flavor to 
  NSLog[...] Candy#flavor "Root Beer", Wrapper#flavor "Root Beer"

Here's that (I think) same code instantiated in MacRuby, from candy_test.rb:

  rootBeerCandy = Candy.alloc.init
  rootBeerCandy.flavor = 'Root Beer'

  rootBeerWrapper = CandyWrapper.alloc.initWithCandy rootBeerCandy
  puts "Candy#flavor #{rootBeerCandy.flavor}, Wrapper#flavor
#{rootBeerWrapper.flavor}"

You can run this with "macrake test" in the project directory, and it
will give (among other things):

  candy_test.rb:7:in `': undefined method `flavor' for
# (NoMethodError)
  rake aborted!

So, what am I doing wrong?

Thanks,

Clay Bridges
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel