lib/cocoa/sugarcube-foundation/nsindexpath.rb in sugarcube-2.12.0 vs lib/cocoa/sugarcube-foundation/nsindexpath.rb in sugarcube-2.12.1

- old
+ new

@@ -1,13 +1,24 @@ class NSIndexPath + # support multiple assignment + # + # example: + # a, b = NSIndexPath.indexPathWithIndex(1).indexPathByAddingIndex(3) + # a # => 1 + # b # => 3 + def to_ary + to_a + end + + # convert to an array of integers + # + # example: + # path = NSIndexPath.indexPathWithIndex(1).indexPathByAddingIndex(3) + # path.to_a # => [1, 3] def to_a - indexes_ptr = Pointer.new(:uint, self.length) - self.getIndexes indexes_ptr - a = [] - self.length.times do |i| - a << indexes_ptr[i] + self.length.times.reduce([]) do |a, i| + a << self.indexAtPosition(i) end - a end end