-
-
Save Asher-/619045 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* (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