[MacRuby] #112: NSNumber should behave consistently regardless of how it is accessed
#112: NSNumber should behave consistently regardless of how it is accessed -------------------------------------+-------------------------------------- Reporter: jordan.breeding@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Currently if an NSNumber is stored in something (like an NSDictionary) it behaves differently depending on how you access it. Accessing it through Cocoa methods gets you a raw NSCFNumber which doesn't work with ruby methods, accessing it through [] gets you a ruby object that works. {{{ 6 jordan@thetourist ~/Desktop/Scripts > macirb
framework("Cocoa") => true myDict = NSMutableDictionary.dictionary => {} NSNumber.numberWithInt(100) => #<NSCFNumber:0x1020fc0> myDict.setObject(100, forKey: "testNum1") => nil myDict.setObject(NSNumber.numberWithInt(100), forKey: "testNum2") => nil myDict.objectForKey("testNum1") => 100 myDict.objectForKey("testNum2") => #<NSCFNumber:0x10aaca0> myDict.objectForKey("testNum1").to_f => 100.0 myDict.objectForKey("testNum2").to_f NoMethodError: undefined method `to_f' for #<NSCFNumber:0x10aaca0> from (irb):9 from /usr/local/bin/macirb:12:in `<main>' myDict.objectForKey("testNum1") / 50 => 2 myDict.objectForKey("testNum2") / 50 NoMethodError: undefined method `/' for #<NSCFNumber:0x10aaca0> from (irb):11 from /usr/local/bin/macirb:12:in `<main>' myDict["testNum1"].to_f => 100.0 myDict["testNum2"].to_f => 100.0 myDict["testNum1"] / 50 => 2 myDict["testNum2"] / 50 => 2
}}}
-- Ticket URL: <http://www.macruby.org/trac/ticket/112> MacRuby <http://macruby.org/>
#112: NSNumber should behave consistently regardless of how it is accessed -------------------------------------+-------------------------------------- Reporter: jordan.breeding@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.4 Component: MacRuby | Resolution: Keywords: | -------------------------------------+-------------------------------------- Changes (by lsansonetti@apple.com): * milestone: => MacRuby 0.4 Comment: The problem here is that NSNumber does not implement the Numeric interface yet, because it's defined on Numeric itself. {{{ $ macirb
1.class.ancestors => [Fixnum, Precision, Integer, Precision, Numeric, Comparable, NSNumber, NSValue, NSObject, Kernel] NSNumber.numberWithInt(42).class.ancestors => [NSCFNumber, NSNumber, NSValue, NSObject, Kernel] NSNumber.numberWithInt(42) + 1 NoMethodError: undefined method `+' for #<NSCFNumber:0x13a49b0> from (irb):3 from /usr/local/bin/macirb:12:in `<main>' }}}
Ideally we should reimplement Numeric on top of NSNumber as we did for String/Array/Hash and change MacRuby to always emit NSNumbers (or subclasses) for fixnums instead of special constants. -- Ticket URL: <http://www.macruby.org/trac/ticket/112#comment:1> MacRuby <http://macruby.org/>
#112: NSNumber should behave consistently regardless of how it is accessed -------------------------------------+-------------------------------------- Reporter: jordan.breeding@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.4 Component: MacRuby | Resolution: Keywords: | -------------------------------------+-------------------------------------- Comment(by jordan.breeding@mac.com): Yeah I was kind of thinking that it would be nice for Ruby numbers to be based on NSNumber like Strings and Hashes as well. -- Ticket URL: <http://www.macruby.org/trac/ticket/112#comment:2> MacRuby <http://macruby.org/>
#112: NSNumber should behave consistently regardless of how it is accessed -------------------------------------+-------------------------------------- Reporter: jordan.breeding@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.4 Component: MacRuby | Resolution: duplicate Keywords: | -------------------------------------+-------------------------------------- Changes (by eloy.de.enige@…): * status: new => closed * resolution: => duplicate Comment: A patch for this is available on #202. -- Ticket URL: <http://www.macruby.org/trac/ticket/112#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby