Skip to content

Instantly share code, notes, and snippets.

@Asher-
Forked from banister/prepend.c
Created October 10, 2010 07:11
Show Gist options
  • Save Asher-/619045 to your computer and use it in GitHub Desktop.
Save Asher-/619045 to your computer and use it in GitHub Desktop.
/* (c) 2010 John Mair (banisterfiend), Asher (Asher), MIT license */
#include "compat.h"
#include "ruby.h"
VALUE
rb_prepend_methods(VALUE klass)
{
VALUE m = rb_module_new();
st_free_table(RCLASS_M_TBL(m));
RCLASS_M_TBL(m) = RCLASS_M_TBL(klass);
/* create module, and set its M_TBL to a copy of the klass's (we'll include this module later) */
RCLASS_M_TBL(klass) = st_init_numtable();
rb_funcall(klass, rb_intern("include"), 1, m);
rb_clear_cache();
return klass;
}
VALUE
rb_prepend_module(VALUE klass, VALUE module)
{
rb_prepend_methods( klass );
rb_funcall(klass, rb_intern("include"), 1, *args);
return klass;
}
void
Init_prepend() {
rb_define_method(rb_cModule, "prepend_methods", rb_prepend_methods, 0);
rb_define_method(rb_cModule, "prepend_module", rb_prepend_module, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment