On Dec 9, 11:24 pm, Trans <transf... / gmail.com> wrote:
> If we define Module#include as:
>
>   class Module
>
>     alias _include include
>
>     def include(*mods)
>       mods.each do |mod|
>         if mod.const_defined?(:Self)
>           extend mod::Self
>           # pass it along if module
>           if instance_of?(Module)
>             const_set(:Self, Module.new) unless const_defined?(:Self)
>             const_get(:Self).send(:include, mod::Self)
>           end
>         end
>       end
>       _include(*mods)
>     end
>
>   end
>
> Example:
>
>   module X
>     def x; "x"; end
>
>     module Self
>       def q; "q"; end
>     end
>   end
>
>   class C
>     include X
>   end
>
>   C.q  #=> "q"
>
> Benefits:
>
>   * Documents well in RDoc
>   * Fairly concise and clear
>   * Self module fits in well with "class << self"
>   * No callbacks used.
>
> T.

Clever. :) It doesn't seem to grok class vars inside of ::Self (?),
but class/module_eval works. Weird since class methods work without
the eval.

Regards,
Jordan