[MacRuby-devel] Array and NSMutableArray mutability

Henry Maddocks henry.maddocks at gmail.com
Sun Jan 30 22:14:21 PST 2011


On 31/01/2011, at 6:37 PM, Caio Chassot wrote:

> On 2011-01-30, at 23:55 , Mark Rada wrote:
>> 
>> Should both types of arrays work the same way? An instance of NSMutableArray says its class is Array, so I thought that they would.
> 
> There's something weird going on in there, I don't really know the details of it, but:
> 
> A while back I had issues calling #count(foo) on a NSMutableArray, even though it #is_a?Array, because it tried to call ObjC's count, which doesn't take an optional argument.
> 
> Whenever I need ruby semantics on an array returned from a Cocoa framework, I use Array.new(my_ns_array).
> 
> Anyway, I can see this Array/NSArray incomplete equivalence being a source of endless confusion. I'm curious what tradeoffs are at play here.

This behaviour is the same with most (all?) Ruby/Cocoa objects, eg. an NSString object will claim to be a Ruby String but doesn't respond to the same methods. See this ticket...

https://www.macruby.org/trac/ticket/726

And yes, this can be very confusing.

Henry





More information about the MacRuby-devel mailing list