Method: Module#heir_module
- Defined in:
- lib/y_support/core_ext/module/misc.rb
#heir_module(**parameters, &block) ⇒ Object
Creates a module that inherits from the receiver and is parametrized with the given set of parameters. The parameters have form { symbol: value } and they cause singleton method(s) named “symbol” be defined on the heir, returning “value”.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/y_support/core_ext/module/misc.rb', line 16 def heir_module **parameters, &block s = self Module.new { include s }.tap do |m| parameters.each_pair { |symbol, value| m.define_singleton_method symbol do value end } m.define_singleton_method inspect do s.inspect + "<" end m.module_exec &block if block end end |