Step aside ActiveSupport::Concern. SuperModule is the new sheriff in town!

Though the example you provide is not practical enough to be sufficient grounds for declaring SuperModule broken, I forgave you and implemented a fix for it anyways in the branch "b003_self_friendly_algorithm", which should be merged shortly.

Below is your code executed and working as expected with regards to "self" returning the class World. Please ignore the debugging output included, though I kept it in case you are curious how it works. I plan to disable/remove debugging output before merging in.

You can also go ahead and pull that branch "b003_self_friendly_algorithm" and try it yourself.

By the way, just when I was wrapping up my implementation, which included code for displaying the source of a method, I stumbled on the Ruby gem banister/method_source, which addresses the same concern and I believe was written by you. I refactored some of my implementation to use the source_location aspect of it, and I plan to perform more refactorings to use the method_source aspect next. Or you can do it yourself, send me a Pull Request, and I'll include your name as a contributor to SuperModule (don't worry if you don't get to it before I do though).

Cheers and enjoy the output below:

Andys-MacBook-Air:banister AndyMaleh$ git branch
  b002_ruby_187_support
* b003_self_friendly_algorithm
  master
Andys-MacBook-Air:banister AndyMaleh$ cat foo.rb 
require_relative '../../../lib/super_module'

module Foo
  include SuperModule
  def self.hello
    self
  end
end
Andys-MacBook-Air:banister AndyMaleh$ cat world.rb 
require_relative 'foo'

class World
  include Foo
end
Andys-MacBook-Air:banister AndyMaleh$ irb
2.2.1 :001 > require_relative 'world'
Foo includes SuperModule
Foo requests recording def method: singleton_method_added
Foo requests recording def method: __record_method_call
Foo requests recording def method: __invoke_super_module_class_method_calls
Foo requests recording def method: __define_super_module_class_methods
Foo requests recording def method: included
Foo requests recording def method: hello
method_file: /Users/AndyMaleh/Documents/code/super_module/examples/reddit-readers/banister/foo.rb
method_source_location: 5
s(:defs, s(:self), :hello, s(:args), s(:self))
method_source_location_end: 6
  define_method hello
Foo request for recording def method: hello has been accepted
118: Foo.included(World) ...
World includes Foo
Foo.__define_super_module_class_methods(World)
  <<< new method begins
    class << self
define_method('hello') do ||


    self
  end
end
  >>> new method ends
end of 'Foo.__define_super_module_class_methods(World)'
Foo.__invoke_super_module_class_method_calls(World)
  __super_module_class_method_calls.inspect: []
  included_super_modules: []
  included_super_modules.map(&:__super_module_class_method_calls).flatten(1): []
end of 'Foo.__invoke_super_module_class_method_calls(World)'
 => true 
2.2.1 :002 > World.hello
/r/ruby Thread Parent Link - airpair.com