Read more

Dynamic super-overridable methods in Ruby – The Pug Automatic

Henning Koch
January 27, 2023Software engineer at makandra GmbH

How a macro can dynamically define a method that can be overridden with super in the same class.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

You can use the with_module_inheritance helper below if you want. It can be handy to make parts of a modularity Show archive.org snapshot trait super-able.

# ./lib/ext/module/with_module_inheritance.rb
#
# This macro allows you to define methods in a modularity trait that can be
# modified using the `super` keyword
# See https://thepugautomatic.com/2013/07/dsom/
module WithModuleInheritance
  def with_module_inheritance(&block)
    anonymous_module = Module.new
    include anonymous_module
    anonymous_module.module_eval &block
  end
end
Module.include(WithModuleInheritance)
Posted by Henning Koch to makandra dev (2023-01-27 16:25)