Created
October 10, 2010 07:05
-
-
Save banister/619040 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), MIT license */ | |
#include "compat.h" | |
#include "ruby.h" | |
VALUE | |
rb_prepend_module(VALUE klass, VALUE module) | |
{ | |
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_funcall(klass, rb_intern("include"), 1, module); | |
rb_clear_cache(); | |
return klass; | |
} | |
void | |
Init_prepend() { | |
rb_define_method(rb_cModule, "prepend", rb_prepend_module, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment