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.70.1 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_tools-0.70.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_tools-0.69.1 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_ruby_utils-0.117.1 lib/eac_ruby_utils/method_class.rb
eac_tools-0.69.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_tools-0.68.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_tools-0.67.1 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_ruby_utils-0.117.0 lib/eac_ruby_utils/method_class.rb
eac_tools-0.67.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_tools-0.66.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_tools-0.65.1 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_ruby_utils-0.116.0 lib/eac_ruby_utils/method_class.rb
eac_ruby_utils-0.115.0 lib/eac_ruby_utils/method_class.rb
eac_tools-0.65.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_ruby_utils-0.114.0 lib/eac_ruby_utils/method_class.rb
eac_tools-0.64.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_ruby_utils-0.113.0 lib/eac_ruby_utils/method_class.rb
eac_tools-0.63.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_tools-0.62.1 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb
eac_tools-0.62.0 sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb