This method just checks that I can correctly see the elements of the ruby array.
static VALUE print_cards(self) VALUE self; { VALUE cards; int i; cards = rb_ivar_get(self, rb_intern("@cards")); VALUE *ary_ptr = RARRAY_PTR(cards); int ary_length = RARRAY_LEN(cards); for(i=0; i< ary_length; i++) printf("%d\n", ary_ptr[i]); return Qnil; } void Init_ev() { rb_eval_string("require './lib/ev/pair_counter'"); VALUE PairCounter = rb_path2class("EV::PairCounter"); rb_define_method(PairCounter, "print_cards", print_cards, 0); }
But when I use the method to use, the array elements are erroneous. It is strange that this does not look like I am receiving any address information, since the size of the printed number approximately corresponds to the size of the number in the ruby array. The numbers are also consistent every time I create a new object and run print_cards.
ruby-1.9.2-p180 :001 > p = EV::PairCounter.new
source share