[MacRuby-devel] When is a String not an NSString?

Henry Maddocks henry.maddocks at gmail.com
Mon Jul 12 17:02:15 PDT 2010


With respect to the following code

     1  require 'test/unit'
     2  
     3  class String
     4      def my_method
     5          "My Method " + self
     6      end
     7  end
     8  
     9  class Test_Tumblr < Test::Unit::TestCase
    10  
    11    def test_strings
    12      cocoa_string = NSString::stringWithString("blah")
    13      ruby_string = "Ruby String"
    14      
    15      assert_equal String, cocoa_string.class
    16      assert_equal String, ruby_string.class
    17      assert_equal cocoa_string.class, ruby_string.class
    18      
    19      assert ruby_string.respond_to?(:my_method), "ruby_string.respond_to?"
    20      assert cocoa_string.respond_to?(:my_method), "cocoa_string.respond_to?"
    21    end
    22    
    23  end


What is the expected result of line 20?

On the one hand cocoa_string is an NSString so the monkey patch shouldn't have any effect, but on the other cocoa_string is claiming to be a ruby String.

Henry


More information about the MacRuby-devel mailing list