Module: ModuleMethods::Extension

Defined in:
lib/module_methods/extension.rb

Overview

Module for module methods, because this module can be included into other modules before including into classes.

Instance Method Summary collapse

Instance Method Details

#included(base = nil) { ... } ⇒ Object

Main logic, which will be applied after extending with this module

Parameters:

  • base (Module, Class, nil) (defaults to: nil)

    a module or a class in which extended module will be included

Yields:

  • a block just will be passed to the ‘super`; it’s for ‘ActiveSupport::Concern` compatibility



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/module_methods/extension.rb', line 17

def included(base = nil, &block)
	super

	return unless base

	if base.instance_of? Module
		base.extend ::ModuleMethods::Extension
		base.modules_with_class_methods.unshift(*modules_with_class_methods)
	end

	modules_with_class_methods.each do |module_with_class_methods|
		next unless module_with_class_methods.const_defined?(:ClassMethods, false)

		base.extend module_with_class_methods::ClassMethods
	end
end

#modules_with_class_methodsObject

Getter for saving the whole chain of including and extending (nested ‘ClassMethods`)



8
9
10
# File 'lib/module_methods/extension.rb', line 8

def modules_with_class_methods
	@modules_with_class_methods ||= [self]
end