Hi,

Am 14.10.2009 um 11:04 schrieb Laurent Sansonetti:

Hi,

On Oct 14, 2009, at 1:03 AM, B. Ohr wrote:

Hi all!

Using Cocoa in MacRuby is sometimes a hard job, because all documentation, examples and sample code is Obj-C. For example, I found this piece of code '[NSNumber numberWithBool:NO]' and asked myself how to write that in Macruby.

You can simply pass true or false and MacRuby will do the conversion for you.

Oh yes, in my example project , I automatically used true and it worked. But then I began asking myself, how can I be shure that this is the correct way and what would an absolute beginner do and then i opened macirb... ;-)


I opened macirb and typed:

> NSNumber.numberWithBool 0
=> false

First I had to laugh and then I thought: Hey implementors of macruby, you really did a great job!

And NSNumbers are converted to Ruby types as you just experienced :)

In the docs

+ (NSNumber *)numberWithBool:(BOOL)value

gives a NSNumber and not a TrueClass or FalseClass as in Macruby. I only wanted to say how impressed I am!



What do you think about a table on http://www.macruby.org/ which lists all such short (and astonishing) examples. Or even better, why not create a command in the services menu which translates a Obj-C sequence (by regexp).

I think a short tutorial/page on the website would be great, indeed. I don't believe it is easily possible to write an Objective-C -> MacRuby convertor that works most/all the time (because of the C nature of ObjC).


Such a cheat sheet can easily show the beauty of MacRuby and the "noisiness" of Obj-C! ;-)

I agree that a real translator is impossible. What I want is a simple text processing which removes all the [foo: bar baz] and replaces it with foo.bar(baz).


BTW, the second example I tried is:

> NSDictionary.dictionaryWithObjectsAndKeys "a", "b", nil

but instead of {"b"=>"a"} I got a seg fault! (ticket is filed)

I replied to the ticket, it seems you forgot to do `framework 'Foundation'' first.


Oh, my fault! But wouldn't it be better NOT to respond with a segment fault (this irritated me) and instead throw an normal ruby exception? (But perhaps that is impossible.)

Bernd





_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to