Revision
789
Author
eloy.de.enige@gmail.com
Date
2009-01-13 07:54:09 -0800 (Tue, 13 Jan 2009)

Log Message

Added workarounds for NSCFNumber to Float conversion on the NSRect setters. This is because Numeric is not yet re-implemented on top of NSCFNumber.

Modified Paths

Diff

Modified: MacRuby/trunk/lib/objc_ext/ns_rect.rb (788 => 789)


--- MacRuby/trunk/lib/objc_ext/ns_rect.rb	2009-01-13 15:34:04 UTC (rev 788)
+++ MacRuby/trunk/lib/objc_ext/ns_rect.rb	2009-01-13 15:54:09 UTC (rev 789)
@@ -8,17 +8,17 @@
       
       # Assigns the `x' coordinate on the rects origin instance.
       def x=(x)
-        origin.x = x
+        origin.x = coerce_float(x)
       end
       
       # Returns the `y' coordinate of the rects origin instance.
-      def x
-        origin.x
+      def y
+        origin.y
       end
       
       # Assigns the `y' coordinate on the rects origin instance.
-      def x=(x)
-        origin.x = x
+      def y=(y)
+        origin.y = coerce_float(y)
       end
       
       # Returns the `height' of the rects size instance.
@@ -28,7 +28,7 @@
       
       # Sets the `height' on the rects size instance.
       def height=(height)
-        size.height = height
+        size.height = coerce_float(height)
       end
       
       # Returns the `width' of the rects size instance.
@@ -38,8 +38,16 @@
       
       # Sets the `width' on the rects size instance.
       def width=(width)
-        size.width = width
+        size.width = coerce_float(width)
       end
+      
+      private
+      
+      # Needed because atm NSCFNumber to Float conversion does not happen yet.
+      # In other words, Numeric should be build upon NSCFNumber.
+      def coerce_float(value)
+        (value.is_a?(NSCFNumber) ? value.floatValue : value)
+      end
     end
   end
 end

Modified: MacRuby/trunk/test-macruby/test_objc_ext.rb (788 => 789)


--- MacRuby/trunk/test-macruby/test_objc_ext.rb	2009-01-13 15:34:04 UTC (rev 788)
+++ MacRuby/trunk/test-macruby/test_objc_ext.rb	2009-01-13 15:54:09 UTC (rev 789)
@@ -1,6 +1,6 @@
 #!/usr/bin/env macruby
 
-$: << File.expand_path('../../lib', __FILE__)
+$:.unshift(File.expand_path('../../lib', __FILE__))
 framework 'Cocoa'
 
 require 'test/unit'
@@ -54,6 +54,9 @@
   it "should assign the height to its size instance with #height=" do
     @rect.height = 300
     assert_equal 300, @rect.height
+    
+    @rect.height = NSNumber.numberWithInt(400)
+    assert_equal 400, @rect.height
   end
   
   it "should return its size instance's width with #width" do
@@ -63,6 +66,9 @@
   it "should assign the width to its size instance with #width=" do
     @rect.width = 300
     assert_equal 300, @rect.width
+    
+    @rect.width = NSNumber.numberWithInt(400)
+    assert_equal 400, @rect.width
   end
   
   it "should return its origin instance's x coord with #x" do
@@ -72,6 +78,9 @@
   it "should assign the x coord to its origin instance with #x=" do
     @rect.x = 200
     assert_equal 200, @rect.x
+    
+    @rect.x = NSNumber.numberWithInt(300)
+    assert_equal 300, @rect.x
   end
   
   it "should return its origin instance's y coord with #y" do
@@ -81,5 +90,8 @@
   it "should assign the y coord to its origin instance with #y=" do
     @rect.y = 200
     assert_equal 200, @rect.y
+    
+    @rect.y = NSNumber.numberWithInt(300)
+    assert_equal 300, @rect.y
   end
 end
\ No newline at end of file