[MacRuby] #122: error in objects initialized with an options hash and KVO (maybe a caching issue in dispatcher)
#122: error in objects initialized with an options hash and KVO (maybe a caching issue in dispatcher) --------------------------------+------------------------------------------- Reporter: rich@infoether.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: --------------------------------+------------------------------------------- The following code should work: {{{ framework 'cocoa' class Foo attr_accessor :subject, :key, :another_key def initialize(subject, options={}) @subject = subject @key = options[:key] @another_key = options[:another_key] end end def objects [Foo.new("test", :key => 'key', :another_key => 'another_key'), Foo.new("test2", :key => 'key2', :another_key => 'another_key2')] end controller = NSArrayController.alloc.init controller.addObjects(objects) controller.setAvoidsEmptySelection(true) controller.setPreservesSelection(false) controller.setSelectsInsertedObjects(false) controller.setAutomaticallyRearrangesObjects(true) controller.setSortDescriptors([NSSortDescriptor.alloc.initWithKey("subject", ascending: true)]) }}} If instead you place a single item it works: {{{ def objects [Foo.new("test", :key => 'key', :another_key => 'another_key')] end }}} Or if you make the second item have a different set of keys... {{{ def objects [Foo.new("test", :key => 'key', :another_key => 'another_key'), Foo.new("test2", :another_key => 'another_key')] end }}} This it works again... -- Ticket URL: <http://www.macruby.org/trac/ticket/122> MacRuby <http://macruby.org/>
#122: error in objects initialized with an options hash and KVO (maybe a caching issue in dispatcher) --------------------------------+------------------------------------------- Reporter: rich@infoether.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.3 Component: MacRuby | Resolution: Keywords: | --------------------------------+------------------------------------------- Changes (by lsansonetti@apple.com): * milestone: => MacRuby 0.3 -- Ticket URL: <http://www.macruby.org/trac/ticket/122#comment:1> MacRuby <http://macruby.org/>
#122: error in objects initialized with an options hash and KVO (maybe a caching issue in dispatcher) --------------------------------+------------------------------------------- Reporter: rich@infoether.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.3 Component: MacRuby | Resolution: Keywords: | --------------------------------+------------------------------------------- Comment(by lsansonetti@apple.com): It's because objects()[0] is not an instance of Foo, but Foo itself (the class). {{{ $ cat /tmp/t.rb class Foo def initialize(subject, options={}) end end p [Foo.new(1, :x => 42, :y => 43), Foo.new(2, :x => 42, :y => 43)] $ ./miniruby /tmp/t.rb [Foo, #<Foo:0x1077480>] $ }}} Looks definitely like a bad bug in the core :-) -- Ticket URL: <http://www.macruby.org/trac/ticket/122#comment:2> MacRuby <http://macruby.org/>
#122: error in objects initialized with an options hash and KVO (maybe a caching issue in dispatcher) --------------------------------+------------------------------------------- Reporter: rich@infoether.com | Owner: lsansonetti@apple.com Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.3 Component: MacRuby | Resolution: fixed Keywords: | --------------------------------+------------------------------------------- Changes (by lsansonetti@apple.com): * status: new => closed * resolution: => fixed Comment: Fixed in r551/trunk. -- Ticket URL: <http://www.macruby.org/trac/ticket/122#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby