Sha256: cdb39cf9d30a2e2fe7e8d5c5d47e627036d7ef050ba4095ffb969d5983d0bc3a

Contents?: true

Size: 964 Bytes

Versions: 1

Compression:

Stored size: 964 Bytes

Contents

#include <ruby.h>

#ifdef HAVE_RUBY_BACKWARD_CLASSEXT_H
#include <ruby/backward/classext.h>
#endif

#ifndef RCLASS_M_TBL
#define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
#endif

static void uninclude(VALUE klass, VALUE mod) {
  Check_Type(mod, T_MODULE);

  VALUE superklass = RCLASS_SUPER(klass);
  for(; superklass; klass = superklass, klass = RCLASS_SUPER(klass)) {
    if(klass == mod || RCLASS_M_TBL(superklass) == RCLASS_M_TBL(mod)) {
      RCLASS_SUPER(klass) = RCLASS_SUPER(superklass);
      rb_clear_cache_by_class(klass);
      break;
    }
  };
};

static VALUE rb_m_uninclude(VALUE self, VALUE mod) {
  uninclude(self, mod);
  return self;
}

static VALUE rb_m_unextend(VALUE self, VALUE mod) {
  uninclude(rb_singleton_class(self), mod);
  return self;
}

void Init_uninclude(void) {
  rb_define_private_method(rb_cModule, "uninclude", RUBY_METHOD_FUNC(rb_m_uninclude), 1);
  rb_define_method(rb_cObject, "unextend", RUBY_METHOD_FUNC(rb_m_unextend), 1);
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uninclude-1.0.0 ext/uninclude/uninclude.c