Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 6a1d0bdd38
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 73 lines (59 sloc) 1.668 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#include <ruby.h>
#include "compat.h"

/* return the actual class of an object */
static VALUE
get_class(VALUE self) {
    return CLASS_OF(self);
}

/* set the class of an object */
static VALUE
set_class(VALUE self, VALUE klass) {
    KLASS_OF(self) = klass;
    return klass;
}


/* get the actual super class of an object */
static VALUE
get_super(VALUE self)
{
    return RCLASS_SUPER(self);
}

/* set the super class of an object */
static VALUE
set_super(VALUE self, VALUE klass) {
    RCLASS_SUPER(self) = klass;
    return klass;
}

/* is the object a singleton class ? */
static VALUE
is_singleton(VALUE self, VALUE klass) {
    return FL_TEST(self, FL_SINGLETON) ? Qtrue : Qfalse;
}

/* get the attached class if receiver is a singleton class */
static VALUE
get_attached(VALUE self)
{
    if(FL_TEST(self, FL_SINGLETON))
        return rb_iv_get(self, "__attached__");
    else
        return Qnil;
}


/* set the attached class if receiver is a singleton class */
static VALUE
set_attached(VALUE self, VALUE klass) {
    if(FL_TEST(self, FL_SINGLETON)) {
        rb_iv_set(self, "__attached__", klass);
        return self;
    }
    else
        return Qnil;
}

void
Init_mult() {
    rb_define_method(rb_cObject, "actual_class", get_class, 0);
    rb_define_method(rb_cObject, "actual_class=", set_class, 1);

    rb_define_method(rb_cModule, "actual_super", get_super, 0);
    rb_define_method(rb_cModule, "actual_super=", set_super, 1);

    rb_define_method(rb_cClass, "is_singleton?", is_singleton, 0);
    
    rb_define_method(rb_cClass, "attached", get_attached, 0);
    rb_define_method(rb_cClass, "attached=", set_attached, 1);
}
Something went wrong with that request. Please try again.