• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rb_singleton_class函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中rb_singleton_class函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_singleton_class函数的具体用法?C++ rb_singleton_class怎么用?C++ rb_singleton_class使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rb_singleton_class函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: add_module

static void add_module(VALUE self, VALUE module)
{
    VALUE super = RCLASS_SUPER(rb_singleton_class(self));

#ifdef RUBY_19
    VALUE klass = class_alloc(T_ICLASS, rb_cClass);
#else
    NEWOBJ(klass, struct RClass);
    OBJSETUP(klass, rb_cClass, T_ICLASS);
#endif

    if (BUILTIN_TYPE(module) == T_ICLASS) {
        module = KLASS_OF(module);
    }
    if (!RCLASS_IV_TBL(module)) {
        RCLASS_IV_TBL(module) = (void*)st_init_numtable();
    }

    RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
    RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
    RCLASS_SUPER(klass) = super;

    if (TYPE(module) == T_ICLASS) {
        KLASS_OF(klass) = KLASS_OF(module);
    } else {
        KLASS_OF(klass) = module;
    }
    OBJ_INFECT(klass, module);
    OBJ_INFECT(klass, super);

    RCLASS_SUPER(rb_singleton_class(self)) = (VALUE)klass;
}
开发者ID:kristianmandrup,项目名称:mixology,代码行数:32,代码来源:mixology.c


示例2: Init_wkhtml_native

void Init_wkhtml_native() {
  //Global initialization of library and when Ruby shuts down
  wkhtmltopdf_init(USE_GRAPHICS_INT);
  wkhtmltoimage_init(USE_GRAPHICS_INT);
  rb_set_end_proc(Deinit_wkhtml_native, Qnil);

  idReady = rb_intern("ready");

  mWkHtml = rb_define_module("WkHtml");
  rb_define_const(mWkHtml, "LIBRARY_VERSION", rb_obj_freeze(rb_str_new_cstr(wkhtmltopdf_version())));
  rb_define_const(mWkHtml, "USE_GRAPHICS", INT2BOOL(USE_GRAPHICS_INT));

  mWkHtmlToPdf = rb_define_module_under(mWkHtml, "ToPdf");

  cWkHtmlToPdfGlobalSettings = rb_define_class_under(mWkHtmlToPdf, "GlobalSettings", rb_cObject);
  rb_define_alloc_func(cWkHtmlToPdfGlobalSettings, wkhtml_topdf_globalsettings_alloc);
  rb_define_method(cWkHtmlToPdfGlobalSettings, "[]=", wkhtml_topdf_globalsettings_aset, 2);
  rb_define_method(cWkHtmlToPdfGlobalSettings, "[]", wkhtml_topdf_globalsettings_aref, 1);

  cWkHtmlToPdfObjectSettings = rb_define_class_under(mWkHtmlToPdf, "ObjectSettings", rb_cObject);
  rb_define_alloc_func(cWkHtmlToPdfObjectSettings, wkhtml_topdf_objectsettings_alloc);
  rb_define_method(cWkHtmlToPdfObjectSettings, "[]=", wkhtml_topdf_objectsettings_aset, 2);
  rb_define_method(cWkHtmlToPdfObjectSettings, "[]", wkhtml_topdf_objectsettings_aref, 1);

  cWkHtmlToPdfConverter = rb_define_class_under(mWkHtmlToPdf, "Converter", rb_cObject);
  /*
  TODO
  rb_define_singleton_method(klass, "new", constructor, 1); //Uses Data_Wrap_Struct -> rb_obj_call_init(t_data, 1, argv);
  rb_define_method(klass, "initialize", initialize, 1);
  */
  rb_define_singleton_method(cWkHtmlToPdfConverter, "create", wkhtml_topdf_converter_create, 1);
  rb_define_method(cWkHtmlToPdfConverter, "add_object", wkhtml_topdf_converter_add_object, 2);
  rb_define_method(cWkHtmlToPdfConverter, "convert", wkhtml_topdf_converter_convert, 0);
  rb_define_method(cWkHtmlToPdfConverter, "http_error_code", wkhtml_topdf_converter_http_error_code, 0);
  rb_define_method(cWkHtmlToPdfConverter, "get_output", wkhtml_topdf_converter_get_output, 0);
  //Force use of factory method
  rb_undef_alloc_func(cWkHtmlToPdfConverter);
  rb_undef_method(rb_singleton_class(cWkHtmlToPdfConverter), "new");

  mWkHtmlToImage = rb_define_module_under(mWkHtml, "ToImage");

  cWkHtmlToImageGlobalSettings = rb_define_class_under(mWkHtmlToImage, "GlobalSettings", rb_cObject);
  rb_define_alloc_func(cWkHtmlToImageGlobalSettings, wkhtml_toimage_globalsettings_alloc);
  rb_define_method(cWkHtmlToImageGlobalSettings, "[]=", wkhtml_toimage_globalsettings_aset, 2);
  rb_define_method(cWkHtmlToImageGlobalSettings, "[]", wkhtml_toimage_globalsettings_aref, 1);

  cWkHtmlToImageConverter = rb_define_class_under(mWkHtmlToImage, "Converter", rb_cObject);
  rb_define_singleton_method(cWkHtmlToImageConverter, "create", wkhtml_toimage_converter_create, 2);
  rb_define_method(cWkHtmlToImageConverter, "convert", wkhtml_toimage_converter_convert, 0);
  rb_define_method(cWkHtmlToImageConverter, "http_error_code", wkhtml_toimage_converter_http_error_code, 0);
  rb_define_method(cWkHtmlToImageConverter, "get_output", wkhtml_toimage_converter_get_output, 0);
  //Force use of factory method
  rb_undef_alloc_func(cWkHtmlToImageConverter);
  rb_undef_method(rb_singleton_class(cWkHtmlToImageConverter), "new");
}
开发者ID:carsonreinke,项目名称:wkhtml,代码行数:55,代码来源:wkhtml.c


示例3: rb_obj_define_method

static VALUE
rb_obj_define_method(VALUE obj, SEL sel, int argc, VALUE *argv)
{
    VALUE klass = rb_singleton_class(obj);

    return rb_mod_define_method(klass, 0, argc, argv);
}
开发者ID:MSch,项目名称:MacRuby,代码行数:7,代码来源:proc.c


示例4: init_curb_postfield

/* =================== INIT LIB =====================*/
void init_curb_postfield() {
  VALUE sc;

  idCall = rb_intern("call");
  
  cCurlPostField = rb_define_class_under(mCurl, "PostField", rb_cObject);

  /* Class methods */
  rb_define_singleton_method(cCurlPostField, "content", ruby_curl_postfield_new_content, -1);
  rb_define_singleton_method(cCurlPostField, "file", ruby_curl_postfield_new_file, -1);
  
  sc = rb_singleton_class(cCurlPostField);
  rb_undef(sc, rb_intern("new"));
  
  rb_define_method(cCurlPostField, "name=", ruby_curl_postfield_name_set, 1);
  rb_define_method(cCurlPostField, "name", ruby_curl_postfield_name_get, 0);  
  rb_define_method(cCurlPostField, "content=", ruby_curl_postfield_content_set, 1);
  rb_define_method(cCurlPostField, "content", ruby_curl_postfield_content_get, 0);  
  rb_define_method(cCurlPostField, "content_type=", ruby_curl_postfield_content_type_set, 1);
  rb_define_method(cCurlPostField, "content_type", ruby_curl_postfield_content_type_get, 0);  
  rb_define_method(cCurlPostField, "local_file=", ruby_curl_postfield_local_file_set, 1);
  rb_define_method(cCurlPostField, "local_file", ruby_curl_postfield_local_file_get, 0);  
  rb_define_method(cCurlPostField, "remote_file=", ruby_curl_postfield_remote_file_set, 1);
  rb_define_method(cCurlPostField, "remote_file", ruby_curl_postfield_remote_file_get, 0);  
  
  rb_define_method(cCurlPostField, "set_content_proc", ruby_curl_postfield_content_proc_set, -1);  

  rb_define_method(cCurlPostField, "to_str", ruby_curl_postfield_to_str, 0);  
  rb_define_alias(cCurlPostField, "to_s", "to_str");
}
开发者ID:marklatham,项目名称:gvmp,代码行数:31,代码来源:curb_postfield.c


示例5: rb_obj_define_method

static VALUE
rb_obj_define_method(int argc, VALUE *argv, VALUE obj)
{
    VALUE klass = rb_singleton_class(obj);

    return rb_mod_define_method(argc, argv, klass);
}
开发者ID:srirammca53,项目名称:update_status,代码行数:7,代码来源:proc.c


示例6: rb_define_alloc_func

void
rb_define_alloc_func(VALUE klass, VALUE (*func)(VALUE))
{
    Check_Type(klass, T_CLASS);
    rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0),
		  NOEX_PRIVATE);
}
开发者ID:genki,项目名称:ruby,代码行数:7,代码来源:vm_method.c


示例7: rb_define_alloc_func

void
rb_define_alloc_func(VALUE klass, VALUE (*func)(VALUE))
{
    Check_Type(klass, T_CLASS);
    rb_add_mri_method(rb_singleton_class(klass), "alloc", func, 0,
	    NOEX_PUBLIC);
}
开发者ID:MSch,项目名称:MacRuby,代码行数:7,代码来源:class.c


示例8: rb_extend_object

void
rb_extend_object(VALUE obj, VALUE module)
{
    VALUE klass;
    if (TYPE(obj) == T_CLASS && RCLASS_RUBY(obj)) {
	VALUE sklass = rb_make_singleton_class(RCLASS_SUPER(obj));
	RCLASS_SET_SUPER(obj, sklass);
	klass = *(VALUE *)sklass;
    }
    else {
	klass = rb_singleton_class(obj);
    }

    rb_include_module(klass, module);

    VALUE m = module;
    do {
	VALUE ary = rb_attr_get(m, idIncludedModules);
	if (ary != Qnil) {
	    for (int i = 0, count = RARRAY_LEN(ary); i < count; i++) {
		VALUE mod = RARRAY_AT(ary, i);
		rb_extend_object(obj, mod);
	    }
	}
	m = RCLASS_SUPER(m);
    }
    while (m == 0 || RCLASS_SINGLETON(m));
}
开发者ID:JosephKu,项目名称:MacRuby,代码行数:28,代码来源:eval.c


示例9: rb_to_module

VALUE
rb_to_module(VALUE self)
{
    VALUE rclass, chain_start, jcur, klass;

    switch(BUILTIN_TYPE(self)) {
    case T_MODULE:
        return self;
    case T_CLASS:
        klass = self;
        break;
    case T_OBJECT:
    default:
        klass = rb_singleton_class(self);            
    }
            
    chain_start = j_class_new(klass, rb_cObject);

    KLASS_OF(chain_start) = rb_cModule;
    RBASIC(chain_start)->flags = T_MODULE;

    jcur = chain_start;
    for(rclass = RCLASS_SUPER(klass); rclass != rb_cObject;
        rclass = RCLASS_SUPER(rclass)) {
                
        RCLASS_SUPER(jcur) = j_class_new(rclass, rb_cObject);
        jcur = RCLASS_SUPER(jcur);
    }

    RCLASS_SUPER(jcur) = (VALUE)NULL;

    return chain_start;
}
开发者ID:RavensKrag,项目名称:texplay,代码行数:33,代码来源:object2module.c


示例10: Init_nkf

void
Init_nkf()
{
    VALUE mNKF = rb_define_module("NKF");

    rb_define_module_function(mNKF, "nkf", rb_nkf_convert, 2);
    rb_define_module_function(mNKF, "guess", rb_nkf_guess, 1);
    rb_define_alias(rb_singleton_class(mNKF), "guess", "guess");

    rb_define_const(mNKF, "AUTO",	Qnil);
    rb_define_const(mNKF, "NOCONV",	Qnil);
    rb_define_const(mNKF, "UNKNOWN",	Qnil);
    rb_define_const(mNKF, "BINARY",	rb_enc_from_encoding(rb_nkf_enc_get("BINARY")));
    rb_define_const(mNKF, "ASCII",	rb_enc_from_encoding(rb_nkf_enc_get("US-ASCII")));
    rb_define_const(mNKF, "JIS",	rb_enc_from_encoding(rb_nkf_enc_get("ISO-2022-JP")));
    rb_define_const(mNKF, "EUC",	rb_enc_from_encoding(rb_nkf_enc_get("EUC-JP")));
    rb_define_const(mNKF, "SJIS",	rb_enc_from_encoding(rb_nkf_enc_get("Shift_JIS")));
    rb_define_const(mNKF, "UTF8",	rb_enc_from_encoding(rb_utf8_encoding()));
    rb_define_const(mNKF, "UTF16",	rb_enc_from_encoding(rb_nkf_enc_get("UTF-16BE")));
    rb_define_const(mNKF, "UTF32",	rb_enc_from_encoding(rb_nkf_enc_get("UTF-32BE")));

    /* Full version string of nkf */
    rb_define_const(mNKF, "VERSION", rb_str_new2(RUBY_NKF_VERSION));
    /* Version of nkf */
    rb_define_const(mNKF, "NKF_VERSION", rb_str_new2(NKF_VERSION));
    /* Release date of nkf */
    rb_define_const(mNKF, "NKF_RELEASE_DATE", rb_str_new2(NKF_RELEASE_DATE));
}
开发者ID:alloy,项目名称:mr-experimental,代码行数:28,代码来源:nkf.c


示例11: Init_unmixer_mri

void Init_unmixer_mri() {
#ifndef RUBINIUS
  
  VALUE container = rb_singleton_class(rb_define_module_under(rb_define_module("Blockenspiel"), "Unmixer"));
  rb_define_method(container, "unmix", do_unmix, 2);
  
#endif
}
开发者ID:meh,项目名称:blockenspiel,代码行数:8,代码来源:unmixer_mri.c


示例12: Init_bamfcsv

void Init_bamfcsv() {

  BAMFCSV_module = rb_define_module("BAMFCSV");
  VALUE bamfcsv_singleton_class = rb_singleton_class(BAMFCSV_module);
  rb_define_private_method(bamfcsv_singleton_class, "__parse_string", parse_string, 1);

  BAMFCSV_MalformedCSVError_class = rb_define_class_under(BAMFCSV_module, "MalformedCSVError", rb_eRuntimeError);
}
开发者ID:jdpace,项目名称:bamfcsv,代码行数:8,代码来源:bamfcsv_ext.c


示例13: Init_flock

void Init_flock(void) {
    mFlock  = rb_define_module("Flock");
    scFlock = rb_singleton_class(mFlock);

    rb_define_private_method(scFlock, "do_kcluster",            RUBY_METHOD_FUNC(rb_do_kcluster),            -1);
    rb_define_private_method(scFlock, "do_self_organizing_map", RUBY_METHOD_FUNC(rb_do_self_organizing_map), -1);
    rb_define_private_method(scFlock, "do_treecluster",         RUBY_METHOD_FUNC(rb_do_treecluster),         -1);

    /* kcluster method - K-Means */
    rb_define_const(mFlock, "METHOD_AVERAGE", INT2NUM('a'));

    /* kcluster method - K-Medians */
    rb_define_const(mFlock, "METHOD_MEDIAN",  INT2NUM('m'));

    /* treecluster method - pairwise single-linkage clustering */
    rb_define_const(mFlock, "METHOD_SINGLE_LINKAGE",   INT2NUM('s'));
    /* treecluster method - pairwise maximum- (or complete-) linkage clustering */
    rb_define_const(mFlock, "METHOD_MAXIMUM_LINKAGE",  INT2NUM('m'));
    /* treecluster method - pairwise average-linkage clustering */
    rb_define_const(mFlock, "METHOD_AVERAGE_LINKAGE",  INT2NUM('a'));
    /* treecluster method - pairwise centroid-linkage clustering */
    rb_define_const(mFlock, "METHOD_CENTROID_LINKAGE", INT2NUM('c'));


    rb_define_const(mFlock, "METRIC_EUCLIDIAN",                       INT2NUM('e'));
    rb_define_const(mFlock, "METRIC_CITY_BLOCK",                      INT2NUM('b'));
    rb_define_const(mFlock, "METRIC_CORRELATION",                     INT2NUM('c'));
    rb_define_const(mFlock, "METRIC_ABSOLUTE_CORRELATION",            INT2NUM('a'));
    rb_define_const(mFlock, "METRIC_UNCENTERED_CORRELATION",          INT2NUM('u'));
    rb_define_const(mFlock, "METRIC_ABSOLUTE_UNCENTERED_CORRELATION", INT2NUM('x'));
    rb_define_const(mFlock, "METRIC_SPEARMAN",                        INT2NUM('s'));
    rb_define_const(mFlock, "METRIC_KENDALL",                         INT2NUM('k'));

    /* Randomly assign data points to clusters using a uniform distribution. */
    rb_define_const(mFlock, "SEED_RANDOM",          INT2NUM(0));

    /*
        K-Means++ style initialization where data points are probabilistically assigned to clusters
        based on their distance from closest cluster.
    */
    rb_define_const(mFlock, "SEED_KMEANS_PLUSPLUS", INT2NUM(1));

    /*
        Deterministic cluster assignment by spreading out initial clusters as far away from each other
        as possible.
    */
    rb_define_const(mFlock, "SEED_SPREADOUT",       INT2NUM(2));

    rb_define_module_function(mFlock, "euclidian_distance", RUBY_METHOD_FUNC(rb_euclid), -1);
    rb_define_module_function(mFlock, "cityblock_distance", RUBY_METHOD_FUNC(rb_cityblock), -1);
    rb_define_module_function(mFlock, "correlation_distance", RUBY_METHOD_FUNC(rb_correlation), -1);
    rb_define_module_function(mFlock, "absolute_correlation_distance", RUBY_METHOD_FUNC(rb_acorrelation), -1);
    rb_define_module_function(mFlock, "uncentered_correlation_distance", RUBY_METHOD_FUNC(rb_ucorrelation), -1);
    rb_define_module_function(mFlock, "absolute_uncentered_correlation_distance", RUBY_METHOD_FUNC(rb_uacorrelation), -1);
    rb_define_module_function(mFlock, "spearman_distance", RUBY_METHOD_FUNC(rb_spearman), -1);
    rb_define_module_function(mFlock, "kendall_distance", RUBY_METHOD_FUNC(rb_kendall), -1);
}
开发者ID:deepfryed,项目名称:flock,代码行数:57,代码来源:flock.c


示例14: Init_Result

void
Init_Result (VALUE mXmms)
{
	cResult = rb_define_class_under (mXmms, "Result", rb_cObject);

	/* ugh, we have to define the "new" method,
	 * so we can remove it again :(
	 */
	rb_define_singleton_method (cResult, "new", NULL, 0);
	rb_undef_method (rb_singleton_class (cResult), "new");

	rb_define_method (cResult, "notifier", c_notifier_set, 0);
	rb_define_method (cResult, "wait", c_wait, 0);
	rb_define_method (cResult, "value", c_value_get, 0);
	rb_define_method (cResult, "error?", c_is_error, 0);
	rb_define_method (cResult, "error", c_get_error, 0);

	cBroadcastResult = rb_define_class_under (mXmms,
	                                          "BroadcastResult",
	                                          cResult);
	rb_define_method (cBroadcastResult, "disconnect", c_disconnect, 0);

	cSignalResult = rb_define_class_under (mXmms, "SignalResult",
	                                       cResult);
	rb_define_method (cSignalResult, "disconnect", c_disconnect, 0);

	eResultError = rb_define_class_under (cResult, "ResultError",
	                                      rb_eStandardError);
	eValueError = rb_define_class_under (cResult, "ValueError",
	                                     eResultError);

	cDict = rb_define_class_under (mXmms, "Dict", rb_cObject);

#ifdef HAVE_RB_PROTECT_INSPECT
	rb_define_method (cDict, "inspect", c_dict_inspect, 0);
#endif /* HAVE_RB_PROTECT_INSPECT */

	rb_define_method (cDict, "size", c_dict_size, 0);
	rb_define_method (cDict, "empty?", c_dict_empty, 0);
	rb_define_method (cDict, "[]", c_dict_aref, 1);
	rb_define_method (cDict, "has_key?", c_dict_has_key, 1);
	rb_define_method (cDict, "each", c_dict_each, 0);
	rb_define_method (cDict, "each_key", c_dict_each_key, 0);
	rb_define_method (cDict, "each_value", c_dict_each_value, 0);

	rb_define_alias (cDict, "length", "size");
	rb_define_alias (cDict, "include?", "has_key?");
	rb_define_alias (cDict, "key?", "has_key?");
	rb_define_alias (cDict, "member?", "has_key?");
	rb_define_alias (cDict, "each_pair", "each");

	rb_include_module (cDict, rb_mEnumerable);

	cRawDict = rb_define_class_under (mXmms, "RawDict", cDict);

	rb_define_method (cRawDict, "to_propdict", c_raw_dict_to_propdict, -1);
}
开发者ID:vdust,项目名称:xmms2-devel,代码行数:57,代码来源:rb_result.c


示例15: rb_undef_alloc_func

void
rb_undef_alloc_func(VALUE klass)
{
    // TODO
#if 0
    Check_Type(klass, T_CLASS);
    rb_add_mri_method(rb_singleton_class(klass), ID_ALLOCATOR, 0, NOEX_UNDEF);
#endif
}
开发者ID:MSch,项目名称:MacRuby,代码行数:9,代码来源:class.c


示例16: rb_define_alloc_func

void
rb_define_alloc_func(VALUE klass, VALUE (*func)(VALUE))
{
    // TODO
#if 0
    Check_Type(klass, T_CLASS);
    rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0),
		  NOEX_PUBLIC);
#endif
}
开发者ID:alloy,项目名称:mr-experimental,代码行数:10,代码来源:vm_method.c


示例17: evilr_to_class

/* call-seq:
 *   to_class(klass=Object) -> Class
 * 
 * Makes a copy of the module, converts the copy to a class, and returns it. The
 * returned class can then have instances created from it. The +klass+ argument
 * sets the superclass of the returned class.  If +klass+ is not a Class,
 * raises +TypeError+. */
static VALUE evilr_to_class(int argc, VALUE *argv, VALUE self) {
  VALUE klass = evilr__optional_class(argc, argv);

  self = rb_obj_clone(self);
  RBASIC_SET_KLASS(self, rb_singleton_class(klass));
  RCLASS_SET_SUPER(self, klass);
  FL_UNSET(self, T_MASK);
  FL_SET(self, T_CLASS);
  return self;
}
开发者ID:jeremyevans,项目名称:evilr,代码行数:17,代码来源:evilr.c


示例18: Init_dir

void Init_dir(){
  cNervaDir = rb_define_class("NDir", rb_cObject);

  // Allocation
  rb_define_alloc_func(cNervaDir, dir_allocate);

  // Singleton Methods
  rb_define_singleton_method(cNervaDir, "chdir", dir_s_chdir, -1);
  rb_define_singleton_method(cNervaDir, "entries", dir_s_entries, 1);
  rb_define_singleton_method(cNervaDir, "exists?", dir_s_exists, 1);
  rb_define_singleton_method(cNervaDir, "foreach", dir_s_foreach, 1);
  rb_define_singleton_method(cNervaDir, "glob", dir_s_glob, 1);
  rb_define_singleton_method(cNervaDir, "home", dir_s_home, -1);
  rb_define_singleton_method(cNervaDir, "mkdir", dir_s_mkdir, -1);
  rb_define_singleton_method(cNervaDir, "pwd", dir_s_pwd, 0);
  rb_define_singleton_method(cNervaDir, "rmdir", dir_s_rmdir, 1);

  // Instance Methods
  rb_define_method(cNervaDir, "initialize", dir_initialize, -1);

  rb_define_method(cNervaDir, "close", dir_close, 0);
  rb_define_method(cNervaDir, "each", dir_each, 0);
  rb_define_method(cNervaDir, "fileno", dir_fileno, 0);
  rb_define_method(cNervaDir, "read", dir_read, 0);
  rb_define_method(cNervaDir, "pos", dir_get_pos, 0);
  rb_define_method(cNervaDir, "pos=", dir_set_pos, 1);
  rb_define_method(cNervaDir, "rewind", dir_rewind, 0);
  rb_define_method(cNervaDir, "seek", dir_seek, 1);

  // Accessors
  rb_define_attr(cNervaDir, "path", 1, 0);

  // Singleton aliases
  rb_define_alias(rb_singleton_class(cNervaDir), "[]", "glob");
  rb_define_alias(rb_singleton_class(cNervaDir), "exist?", "exists?");
  rb_define_alias(rb_singleton_class(cNervaDir), "delete", "rmdir");
  rb_define_alias(rb_singleton_class(cNervaDir), "getwd", "pwd");
  rb_define_alias(rb_singleton_class(cNervaDir), "unlink", "rmdir");

  // Instance aliases
  rb_define_alias(cNervaDir, "tell", "pos");
  rb_define_alias(cNervaDir, "to_path", "path");
}
开发者ID:djberg96,项目名称:Nerva,代码行数:43,代码来源:nerva_dir.c


示例19: Init_native

/**
 * Initialize the bson c extension.
 *
 * @since 2.0.0
 */
void Init_native()
{
  // Get all the constants to be used in the extensions.
  VALUE bson = rb_const_get(rb_cObject, rb_intern("BSON"));
  VALUE integer = rb_const_get(bson, rb_intern("Integer"));
  VALUE time = rb_const_get(bson, rb_intern("Time"));
  VALUE int32 = rb_const_get(bson, rb_intern("Int32"));
  VALUE int32_class = rb_singleton_class(int32);
  VALUE int64 = rb_const_get(bson, rb_intern("Int64"));
  VALUE int64_class = rb_singleton_class(int64);
  VALUE object_id = rb_const_get(bson, rb_intern("ObjectId"));
  VALUE generator = rb_const_get(object_id, rb_intern("Generator"));
  VALUE string = rb_const_get(bson, rb_intern("String"));

  // Redefine the serialization methods on the Integer class.
  rb_undef_method(integer, "to_bson_int32");
  rb_define_method(integer, "to_bson_int32", rb_integer_to_bson_int32, 1);
  rb_undef_method(integer, "to_bson_int64");
  rb_define_method(integer, "to_bson_int64", rb_integer_to_bson_int64, 1);

  // Redefine deserialization methods on Int32 class.
  rb_undef_method(int32_class, "from_bson_int32");
  rb_define_private_method(int32_class, "from_bson_int32", rb_integer_from_bson_int32, 1);

  // Redefine deserialization methods on Int64 class.
  rb_undef_method(int64_class, "from_bson_int64");
  rb_define_private_method(int64_class, "from_bson_int64", rb_integer_from_bson_int64, 1);

  // Redefine the serialization methods on the time class.
  rb_undef_method(time, "to_bson_time");
  rb_define_method(time, "to_bson_time", rb_time_to_bson, 2);

  // Redefine the setint32 method on the String class.
  rb_undef_method(string, "setint32");
  rb_define_method(string, "setint32", rb_string_setint32, 2);

  // Setup the machine id for object id generation.
  /* memcpy(rb_bson_machine_id, RSTRING_PTR(machine_id), 16); */
  rb_undef_method(generator, "next");
  rb_define_method(generator, "next", rb_object_id_generator_next, -1);
}
开发者ID:gjmurakami-10gen,项目名称:mongo-meta-driver,代码行数:46,代码来源:native.c


示例20: rbffi_Struct_Init

void
rbffi_Struct_Init(VALUE moduleFFI)
{
    VALUE StructClass;

    rbffi_StructLayout_Init(moduleFFI);

    rbffi_StructClass = StructClass = rb_define_class_under(moduleFFI, "Struct", rb_cObject);
    rb_global_variable(&rbffi_StructClass);

    rbffi_StructInlineArrayClass = rb_define_class_under(rbffi_StructClass, "InlineArray", rb_cObject);
    rb_global_variable(&rbffi_StructInlineArrayClass);

    rbffi_StructLayoutCharArrayClass = rb_define_class_under(rbffi_StructLayoutClass,
        "CharArray", rbffi_StructInlineArrayClass);
    rb_global_variable(&rbffi_StructLayoutCharArrayClass);


    rb_define_alloc_func(StructClass, struct_allocate);
    rb_define_method(StructClass, "initialize", struct_initialize, -1);
    rb_define_method(StructClass, "order", struct_order, -1);
    
    rb_define_alias(rb_singleton_class(StructClass), "alloc_in", "new");
    rb_define_alias(rb_singleton_class(StructClass), "alloc_out", "new");
    rb_define_alias(rb_singleton_class(StructClass), "alloc_inout", "new");
    rb_define_alias(rb_singleton_class(StructClass), "new_in", "new");
    rb_define_alias(rb_singleton_class(StructClass), "new_out", "new");
    rb_define_alias(rb_singleton_class(StructClass), "new_inout", "new");

    rb_define_method(StructClass, "pointer", struct_get_pointer, 0);
    rb_define_private_method(StructClass, "pointer=", struct_set_pointer, 1);

    rb_define_method(StructClass, "layout", struct_get_layout, 0);
    rb_define_private_method(StructClass, "layout=", struct_set_layout, 1);

    rb_define_method(StructClass, "[]", struct_aref, 1);
    rb_define_method(StructClass, "[]=", struct_aset, 2);
    rb_define_method(StructClass, "null?", struct_null_p, 0);

    rb_include_module(rbffi_StructInlineArrayClass, rb_mEnumerable);
    rb_define_alloc_func(rbffi_StructInlineArrayClass, inline_array_allocate);
    rb_define_method(rbffi_StructInlineArrayClass, "initialize", inline_array_initialize, 2);
    rb_define_method(rbffi_StructInlineArrayClass, "[]", inline_array_aref, 1);
    rb_define_method(rbffi_StructInlineArrayClass, "[]=", inline_array_aset, 2);
    rb_define_method(rbffi_StructInlineArrayClass, "each", inline_array_each, 0);
    rb_define_method(rbffi_StructInlineArrayClass, "size", inline_array_size, 0);
    rb_define_method(rbffi_StructInlineArrayClass, "to_a", inline_array_to_a, 0);
    rb_define_method(rbffi_StructInlineArrayClass, "to_ptr", inline_array_to_ptr, 0);

    rb_define_method(rbffi_StructLayoutCharArrayClass, "to_s", inline_array_to_s, 0);
    rb_define_alias(rbffi_StructLayoutCharArrayClass, "to_str", "to_s");

    id_pointer_ivar = rb_intern("@pointer");
    id_layout_ivar = rb_intern("@layout");
    id_layout = rb_intern("layout");
    id_get = rb_intern("get");
    id_put = rb_intern("put");
    id_to_ptr = rb_intern("to_ptr");
    id_to_s = rb_intern("to_s");
}
开发者ID:sgonyea,项目名称:ffi,代码行数:60,代码来源:Struct.c



注:本文中的rb_singleton_class函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rb_sprintf函数代码示例发布时间:2022-05-30
下一篇:
C++ rb_settimeout函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap