On 11/13/05, Timothy Hunter <cyclists / nc.rr.com> wrote:
> Eric Hofreiter wrote:
> > I'm doing some experimenting with writing C extensions, and so far it is fairly simple and intuitive.  However, there is one thing that I cannot figure out.  In ruby.h there are the native types define as T_STRING, T_FIXNUM, etc., allowing you to take an argument and see if it is a string or fixnum and act accordingly.  How would I go about testing if the argument is a user-defined type?  Is this even possible?  Thanks in advance.
> >
> >
> > ---------------------------------
> >  Yahoo! FareChase - Search multiple travel sites in one click.
>
> CLASS_OF(obj) == my_class
>
> where 'my_class' is a class object VALUE such as that returned by
> rb_define_class or rb_const_get (if the class is defined in Ruby).
>
>

I investigated a little more. I found it In ruby.h:

#define CLASS_OF(v) rb_class_of((VALUE)(v))

static inline VALUE
rb_class_of(VALUE obj)
{
    if (IMMEDIATE_P(obj)) {
        if (FIXNUM_P(obj)) return rb_cFixnum;
        if (obj == Qtrue)  return rb_cTrueClass;
        if (SYMBOL_P(obj)) return rb_cSymbol;
    }
    else if (!RTEST(obj)) {
        if (obj == Qnil)   return rb_cNilClass;
        if (obj == Qfalse) return rb_cFalseClass;
    }
    return RBASIC(obj)->klass;
}

--
http://nohmad.sub-port.net