Sha256: 84dc4febd1ac7b0631f6f5ca328493ce71ca2d2f8022774ea5221bda7a2d7ab2

Contents?: true

Size: 876 Bytes

Versions: 19

Compression:

Stored size: 876 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/module_parent'
require 'eac_ruby_utils/patches/string/inflector'

module EacRubyUtils
  class ActsAsInstanceMethod
    common_constructor :method_class

    # @param sender_module [Module, nil]
    # @return [self]
    def setup(sender_module = nil)
      sender_module ||= default_sender_module
      the_setup = self
      sender_module.define_method(method_name) do |*args, &block|
        the_setup.method_class.new(self, *args, &block).result
      end

      self
    end

    # @return [String]
    def method_name
      method_class.name.demodulize.underscore.variableize
    end

    # @return [Module]
    def default_sender_module
      method_class.module_parent
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
eac_ruby_utils-0.124.0 lib/eac_ruby_utils/acts_as_instance_method.rb
eac_tools-0.97.2 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb
eac_ruby_utils-0.123.0 lib/eac_ruby_utils/acts_as_instance_method.rb
eac_ruby_utils-0.121.0 lib/eac_ruby_utils/acts_as_instance_method.rb
eac_ruby_utils-0.120.0 lib/eac_ruby_utils/acts_as_instance_method.rb
eac_tools-0.76.1 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb
eac_tools-0.76.0 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb
eac_tools-0.75.2 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb
eac_ruby_utils-0.119.2 lib/eac_ruby_utils/acts_as_instance_method.rb
eac_tools-0.75.1 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb
eac_tools-0.75.0 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb
eac_ruby_utils-0.119.1 lib/eac_ruby_utils/acts_as_instance_method.rb
eac_tools-0.74.1 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb
eac_tools-0.74.0 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb
eac_tools-0.73.0 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb
eac_ruby_utils-0.119.0 lib/eac_ruby_utils/acts_as_instance_method.rb
eac_tools-0.72.0 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb
eac_ruby_utils-0.118.1 lib/eac_ruby_utils/acts_as_instance_method.rb
eac_ruby_utils-0.118.0 lib/eac_ruby_utils/acts_as_instance_method.rb