Q:

Method-lookup path for Ruby

I'm reading the book "Well Grounded Rubyist" and I have a question about the method-lookup path:
module M
  def report
    puts "'report' method in module M"
  end
end

module N
  def report
    puts "'report' method in module N"
  end
end

class C
  include M
  include N
  def report
    puts "'report' method in class C"
    puts "About to call super..."
    super
    puts "Back from super..."
  end
end

obj = C.new
obj.report

Based on my understanding, obj.report will output:
'report' method in class C
About to call super...
'report' method in module N
Back from super...

However, I'm curious if it's possible to call M's report method, by bypassing N's report, from within class C. I know if I add "super" within module N, it'll call N's report and then M's report before putting "Back from super..." but is there a way to do this directly from C?

A:

You can use ancestor reflection:
class C
  def report
    my_ancestors = self.class.ancestors
    puts "my ancestors are: #{my_ancestors}"
    method = my_ancestors[2].instance_method(:report)
    method.bind(self).call
  end
end

C.new.report
=> my ancestors are: [C, N, M, Object, PP::ObjectMixin, Kernel, BasicObject]
=> 'report' method in module M

