Method: Module#heir_class
- Defined in:
- lib/y_support/core_ext/module/misc.rb
#heir_class(mother = Object, **parameters, &block) ⇒ Object
Creates a class, which is a subclass of a supplied class (defaults to Object if none supplied), and which also inherits from the receiver and is parametrized by the given set of parameters. The parameters have form { symbol: value } and they cause singleton method(s) named “symbol” be defined on the heir class, returning “value”.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/y_support/core_ext/module/misc.rb', line 33 def heir_class mother=Object, **parameters, &block s = self Class.new( mother ) { include s }.tap do |c| parameters.each_pair { |symbol, value| c.define_singleton_method symbol do value end } # TODO: This line is controversial: c.define_singleton_method inspect do s.inspect + "<" end c.module_exec &block if block end end |