Hi all, I hope someone can help me with this problem I'm having on a
ruby 1.9.2 extension I'm developing:
https://github.com/dcadenas/rubydeps

I'm using rb_add_event_hook on RUBY_EVENT_CALL events to get
information about the class that receives the called method.

I get this information from inside the event hook with
real_class(GET_THREAD()->cfp->iseq->klass) where real_class is this
helper shamelessly stolen from ruby-debug19:

inline static VALUE
real_class(VALUE klass)
{
  if (klass) {
    if (TYPE(klass) == T_ICLASS) {
      return RBASIC(klass)->klass;
    }
    else if (FL_TEST(klass, FL_SINGLETON)) {
      return rb_iv_get(klass, "__attached__");
    }
  }
  return klass;
}

This usually works well as in the following example:

class A
  def self.class_method
  end
end

Then when I run A.class_method and the event hook gets in,
real_class(GET_THREAD()->cfp->iseq->klass) returns A.

The problematic example is this:

module B
  def class_method
  end
end

class A
  extend B
end

Here when I run A.class_method, what I get instead of A is the module
where the method is defined, B, instead of A.

So, is there a way in which I can get the class where the
RUBY_EVENT_CALL is ran instead of the class/module where it's defined?

There's a failing test in my repo showing this situation in case
someone wants to dig in the project:
https://github.com/dcadenas/rubydeps/blob/master/spec/rubydeps_spec.rb#L82