Sha256: dc32d7461b9f63ecc78cf98a218991ae032e1362f85142bf55b80144a0fe1e33

Contents?: true

Size: 986 Bytes

Versions: 84

Compression:

Stored size: 986 Bytes

Contents

# frozen_string_literal: true

require 'active_support/core_ext/module/introspection'
require 'eac_ruby_utils/patches/class/common_constructor'
require 'eac_ruby_utils/patches/module/common_concern'
require 'eac_ruby_utils/patches/module/module_parent'
require 'eac_ruby_utils/patches/string/inflector'

module EacRubyUtils
  module MethodClass
    common_concern do
      ::EacRubyUtils::MethodClass::Setup.new(self)
    end

    class Setup
      common_constructor :method_class, :static_method, default: [false] do
        perform
      end

      def perform
        the_setup = self
        sender_module.define_method(method_name) do |*args, &block|
          the_setup.method_class.new(self, *args, &block).result
        end
      end

      def method_name
        method_class.name.demodulize.underscore.variableize
      end

      def sender_module
        r = method_class.module_parent
        r = r.singleton_class if static_method
        r
      end
    end
  end
end

Version data entries

84 entries across 84 versions & 2 rubygems

Version Path
eac_tools-0.33.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_tools-0.32.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_ruby_utils-0.104.0 lib/eac_ruby_utils/method_class.rb
eac_tools-0.31.1 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb