Beispiel #1
0
VALUE
rb_define_class_under(VALUE outer, const char *name, VALUE super)
{
    VALUE klass;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined_at(outer, id)) {
	klass = rb_const_get_at(outer, id);
	if (TYPE(klass) != T_CLASS) {
	    rb_raise(rb_eTypeError, "%s is not a class", name);
	}
	if (rb_class_real(RCLASS_SUPER(klass)) != super) {
	    rb_name_error(id, "%s is already defined", name);
	}
	return klass;
    }
    if (!super) {
	rb_warn("no super class for `%s::%s', Object assumed",
		rb_class2name(outer), name);
    }
    klass = rb_define_class_id(id, super);
    rb_set_class_path(klass, outer, name);
    rb_const_set(outer, id, klass);
    rb_class_inherited(super, klass);

    return klass;
}
Beispiel #2
0
VALUE
rb_define_class_under(VALUE outer, const char *name, VALUE super)
{
    VALUE klass;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined_at(outer, id)) {
	klass = rb_const_get_at(outer, id);
	if (TYPE(klass) != T_CLASS) {
	    rb_raise(rb_eTypeError, "%s is not a class", name);
	}
	if (RCLASS_RUBY(klass)) {
	    // Only for pure Ruby classes, as Objective-C classes
	    // might be returned from the dynamic resolver.
	    if (rb_class_real(RCLASS_SUPER(klass), true) != super) {
		rb_name_error(id, "%s is already defined", name);
	    }
	    return klass;
	}
    }
    if (!super) {
	rb_warn("no super class for `%s::%s', Object assumed",
		rb_class2name(outer), name);
    }
    klass = rb_define_class_id(id, super);
    rb_set_class_path(klass, outer, name);
    rb_const_set(outer, id, klass);
    rb_class_inherited(super, klass);

    return klass;
}
Beispiel #3
0
void
Init_Symbol(void)
{
    // rb_cSymbol is defined earlier in Init_PreVM().
    rb_set_class_path(rb_cSymbol, rb_cObject, "Symbol");
    rb_const_set(rb_cObject, rb_intern("Symbol"), rb_cSymbol);

    rb_undef_alloc_func(rb_cSymbol);
    rb_undef_method(*(VALUE *)rb_cSymbol, "new");
    rb_objc_define_method(*(VALUE *)rb_cSymbol, "all_symbols",
	    rsym_all_symbols, 0);

    // Undefine methods defined on NSString.
    rb_undef_method(rb_cSymbol, "to_i");
    rb_undef_method(rb_cSymbol, "to_f");
    rb_undef_method(rb_cSymbol, "to_r");
    rb_undef_method(rb_cSymbol, "to_str");

    rb_objc_define_method(rb_cSymbol, "==", rsym_equal, 1);
    rb_objc_define_method(rb_cSymbol, "<=>", rsym_cmp, 1);
    rb_objc_define_method(rb_cSymbol, "casecmp", rsym_casecmp, 1);
    rb_objc_define_method(rb_cSymbol, "eql?", rsym_equal, 1);
    rb_objc_define_method(rb_cSymbol, "inspect", rsym_inspect, 0);
    rb_objc_define_method(rb_cSymbol, "to_proc", rsym_to_proc, 0);
    rb_objc_define_method(rb_cSymbol, "to_s", rsym_to_s, 0);
    rb_objc_define_method(rb_cSymbol, "id2name", rsym_to_s, 0);
    rb_objc_define_method(rb_cSymbol, "description", rsym_to_s, 0);
    rb_objc_define_method(rb_cSymbol, "intern", rsym_to_sym, 0);
    rb_objc_define_method(rb_cSymbol, "to_sym", rsym_to_sym, 0);
    rb_objc_define_method(rb_cSymbol, "empty?", rsym_empty, 0);
    rb_objc_define_method(rb_cSymbol, "[]", rsym_aref, -1);
    rb_objc_define_method(rb_cSymbol, "=~", rsym_match, 1);
    rb_objc_define_method(rb_cSymbol, "match", rsym_match, 1);
    rb_objc_define_method(rb_cSymbol, "upcase", rsym_upcase, 0);
    rb_objc_define_method(rb_cSymbol, "downcase", rsym_downcase, 0);
    rb_objc_define_method(rb_cSymbol, "swapcase", rsym_swapcase, 0);
    rb_objc_define_method(rb_cSymbol, "capitalize", rsym_capitalize, 0);
    rb_objc_define_method(rb_cSymbol, "succ", rsym_succ, 0);
    rb_objc_define_method(rb_cSymbol, "next", rsym_succ, 0);

    // Cocoa primitives.
    rb_objc_install_method2((Class)rb_cSymbol, "copy",
	    (IMP)rsym_imp_copy);
    rb_objc_install_method2((Class)rb_cSymbol, "length",
	    (IMP)rsym_imp_length);
    rb_objc_install_method2((Class)rb_cSymbol, "characterAtIndex:",
	    (IMP)rsym_imp_characterAtIndex);
    rb_objc_install_method2((Class)rb_cSymbol, "encodeWithCoder:",
	    (IMP)rsym_imp_encodeWithCoder);
    rb_objc_install_method2((Class)rb_cSymbol, "initWithCoder:",
	    (IMP)rsym_imp_initWithCoder);
    rb_objc_install_method2((Class)rb_cSymbol, "classForKeyedArchiver",
	    (IMP)rsym_imp_classForKeyedArchiver);
}
Beispiel #4
0
void
Init_Encoding(void)
{
    // rb_cEncoding is defined earlier in Init_PreVM().
    rb_set_class_path(rb_cEncoding, rb_cObject, "Encoding");
    rb_const_set(rb_cObject, rb_intern("Encoding"), rb_cEncoding);

    rb_undef_alloc_func(rb_cEncoding);

    rb_objc_define_method(rb_cEncoding, "to_s", mr_enc_name, 0);
    rb_objc_define_method(rb_cEncoding, "inspect", mr_enc_inspect, 0);
    rb_objc_define_method(rb_cEncoding, "name", mr_enc_name, 0);
    rb_objc_define_method(rb_cEncoding, "names", mr_enc_names, 0);
    rb_objc_define_method(rb_cEncoding, "dummy?", mr_enc_dummy_p, 0);
    rb_objc_define_method(rb_cEncoding, "ascii_compatible?",
	    mr_enc_ascii_compatible_p, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "list", mr_enc_s_list, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "name_list",
	    mr_enc_s_name_list, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "aliases",
	    mr_enc_s_aliases, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "find", mr_enc_s_find, 1);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "compatible?",
	    mr_enc_s_is_compatible, 2); // in string.c

    //rb_define_method(rb_cEncoding, "_dump", enc_dump, -1);
    //rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1);

    rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_external",
	    mr_enc_s_default_external, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_external=",
	    mr_enc_set_default_external, 1);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_internal",
	    mr_enc_s_default_internal, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_internal=",
	    mr_enc_set_default_internal, 1);
    //rb_define_singleton_method(rb_cEncoding, "locale_charmap", rb_locale_charmap, 0);

    // Create constants.
    for (unsigned int i = 0; i < ENCODINGS_COUNT; i++) {
	rb_encoding_t *enc = rb_encodings[i];
	define_encoding_constant(enc->public_name, enc);
	for (unsigned int j = 0; j < enc->aliases_count; j++) {
	    define_encoding_constant(enc->aliases[j], enc);
	}
    }
}
Beispiel #5
0
VALUE
rb_define_module_under(VALUE outer, const char *name)
{
    ID id = rb_intern(name);
    if (rb_const_defined_at(outer, id)) {
	VALUE module = rb_const_get_at(outer, id);
	if (TYPE(module) == T_MODULE) {
	    return module;
	}
	rb_raise(rb_eTypeError, "%s::%s:%s is not a module",
		 rb_class2name(outer), name, rb_obj_classname(module));
    }
    VALUE module = rb_define_module_id(id);
    rb_const_set(outer, id, module);
    rb_set_class_path(module, outer, name);
    return module;
}
Beispiel #6
0
void
Init_Set(void)
{
    rb_cCFSet = (VALUE)objc_getClass("NSCFSet");
    rb_cSet = rb_cNSSet = (VALUE)objc_getClass("NSSet");
    rb_cNSMutableSet = (VALUE)objc_getClass("NSMutableSet");
    rb_set_class_path(rb_cNSMutableSet, rb_cObject, "NSMutableSet");
    rb_const_set(rb_cObject, rb_intern("Set"), rb_cNSMutableSet);

    rb_include_module(rb_cSet, rb_mEnumerable);

    rb_define_singleton_method(rb_cSet, "[]", rb_set_s_create, -1);

    rb_define_method(rb_cSet, "dup", rb_set_dup, 0);
    rb_define_method(rb_cSet, "clone", rb_set_clone, 0);
    rb_define_method(rb_cSet, "initialize", rb_set_initialize, -1);

    rb_define_method(rb_cSet, "to_a", rb_set_to_a, 0);
    rb_define_method(rb_cSet, "==", rb_set_equal, 1);
    rb_define_method(rb_cSet, "size", rb_set_size, 0);
    rb_define_method(rb_cSet, "empty?", rb_set_empty_q, 0);
    rb_define_alias(rb_cSet, "length", "size");
    rb_define_method(rb_cSet, "&", rb_set_intersect, 1);
    rb_define_alias(rb_cSet, "intersect", "&");
    rb_define_method(rb_cSet, "|", rb_set_union, 1);
    rb_define_alias(rb_cSet, "union", "|");
    rb_define_alias(rb_cSet, "+", "|");
    rb_define_method(rb_cSet, "merge", rb_set_merge, 1);
    rb_define_method(rb_cSet, "-", rb_set_subtract, 1);
    rb_define_method(rb_cSet, "add", rb_set_add, 1);
    rb_define_alias(rb_cSet, "<<", "add");
    rb_define_method(rb_cSet, "add?", rb_set_add2, 1);
    rb_define_method(rb_cSet, "clear", rb_set_clear, 0);
    rb_define_method(rb_cSet, "delete", rb_set_delete, 1);
    rb_define_method(rb_cSet, "delete?", rb_set_delete2, 1);
    rb_define_method(rb_cSet, "delete_if", rb_set_delete_if, 0);
    rb_define_method(rb_cSet, "reject!", rb_set_reject_bang, 0);
    rb_define_method(rb_cSet, "each", rb_set_each, 0);
    rb_define_method(rb_cSet, "include?", rb_set_include, 1);
    rb_define_alias(rb_cSet, "member?", "include?");
    rb_define_method(rb_cSet, "to_a", rb_set_to_a, 0);
}