secret
Last active

MacRuby issue with nested modules that use the names of objective-c classes with the C API

  • Download Gist
broken.c
C
1 2 3 4
mJSON = rb_define_module("JSON");
rb_define_module_under(mJSON, "NSString");
// TypeError: JSON::NSString:Class is not a module
// This seems to happen because a call to rb_const_defined_at will always resolve NSString
not-broken.c
C
1 2 3 4
mJSON = rb_define_module("JSON");
rb_define_module_under(mJSON, "String");
 
// This will work, and is a reduction of how json is coded right
not-broken.rb
Ruby
1 2 3 4 5 6 7 8 9
module JSON
module NSString
end
end
 
p JSON::NSString.class
p JSON::NSString::NSString.class
 
# this works as expected, and is how json/pure is patched (changed module from String to NSString)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.