module Outbox::DefineInheritableMethod

Public Instance Methods

define_inheritable_method(mod_name, *args, &block) click to toggle source

Similar to .define_method, but adds a dynamic module in the inheritance change to attach the method to. See:

thepugautomatic.com/2013/07/dsom/

# File lib/outbox/define_inheritable_method.rb, line 7
def define_inheritable_method(mod_name, *args, &block)
  mod = get_inheritable_module(mod_name)
  mod.module_eval do
    define_method(*args, &block)
  end
end

Protected Instance Methods

get_inheritable_module(mod_name) click to toggle source
# File lib/outbox/define_inheritable_method.rb, line 16
def get_inheritable_module(mod_name)
  if const_defined?(mod_name, false)
    const_get(mod_name)
  else
    include const_set(mod_name, Module.new)
  end
end