[MacRuby] #671: MacRuby developers can't know if their arrays are mutable or immutable
#671: MacRuby developers can't know if their arrays are mutable or immutable -------------------------------------+-------------------------------------- Reporter: mattaimonetti@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.6 Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- The following code will raise an exception: {{{ [1,2,3].copy << 4 }}} The reason why is because Array implements NSCopy and calling #copy on a mutable array will return an immutable version. So everything is normal, the only problem is that since the 0.6 Array rewrite, one can't figure out if his array is mutable or not: {{{ NSArray.arrayWithObjects('terrans', 'zerg', 'protoss', nil).class => Array NSMutableArray.arrayWithObjects('terrans', 'zerg', 'protoss', nil).class => Array NSMutableArray.arrayWithObjects('terrans', 'zerg', 'protoss', nil).copy.class => Array [1,2,3].class => Array ruby-1.9.1-p243 > [1,2,3].copy.class => Array ruby-1.9.1-p243 > [1,2,3].copy.frozen? => false }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/671> MacRuby <http://macruby.org/>
#671: MacRuby developers can't know if their arrays are mutable or immutable -------------------------------------+-------------------------------------- Reporter: mattaimonetti@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.6 Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by tvmoore@…): This is also true for Strings... I was trying to append to a string from textfiled.stringValue ended up doing x = "" << stringvalue << anotherString. -- Ticket URL: <http://www.macruby.org/trac/ticket/671#comment:1> MacRuby <http://macruby.org/>
#671: MacRuby developers can't know if their arrays are mutable or immutable -------------------------------------+-------------------------------------- Reporter: mattaimonetti@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: Component: MacRuby | Resolution: wontfix Keywords: | -------------------------------------+-------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => wontfix * milestone: MacRuby 0.6 => Comment: This is by design. In 0.6, #frozen? will no longer return true for immutable Foundation collections. Check out Bill Bumgarner's response here: http://stackoverflow.com/questions/1788690/objectiv-c-how-to-check-if- variable-is-nsarray-or-nsmutablearray -- Ticket URL: <http://www.macruby.org/trac/ticket/671#comment:2> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby