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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)