On Mar 13, 2008, at 4:49 PM, Ernest Prabhakar wrote:
Hi Laurent,
On Mar 13, 2008, at 4:17 PM, Laurent Sansonetti wrote:
As we’ve discussed offline, I’d still love to take a crack at this one. I do wonder what we’ll do with NSStrings, though, since they’re not actually mutable. So many issues.
We could check for mutability and accordingly raise exceptions in ! methods. Every string created by Ruby would be mutable anyway, we are only talking about non-mutable NSStrings received from ObjC, which I don't think are a big deal. But if we want to be truly compatible on the other side too... we will have to find a solution.
Could we add a category on NSString that auto-converts it to an NSMutableString when necessary?
Well there is already [-mutableCopy] which when called on an NSString returns an NSMutableString. But you have to call it, the process is not done automatically for you. Say that you receive a non-mutable string from Objective-C, and want to call the #upcase! method on it. AFAIK, MacRuby could 1) raise an exception 2) auto-convert the receiver as mutable (but a new object will likely have to be created). Laurent