2008-08-19から1日間の記事一覧

Ruby拡張ライブラリのコード中で`オブジェクトがあるクラスのインスタンスである'ことを確認する方法

こうかな? VALUE rb_cUserDefined; /* … */ VALUE test(VALUE self, VALUE input) { if (rb_cUserDefined == rb_obj_class(input)) { return Qtrue; } else { return Qfalse; } } /* … */ void Init_your_ext(void) { /* … */ rb_cUserDefined = rb_define_…

C++でClass#allocateを登録する

Ruby 1.8.7 p72 VALUE rb_cUserDefined; /* … */ VALUE your_class_singleton_allocate(VALUE klass) { VALUE allocated; /* … */ return allocated; } /* … */ #ifdef __cplusplus extern "C" { #endif void Init_your_ext(void) { /* … */ rb_cUserDefined…