ferrous26 / broken.c secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

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

View broken.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
View broken.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
View broken.c
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.