Module: ToProcInterface

Extended by:
Hooks
Includes:
Delegations, Mixin
Included in:
CallToMaybe, CallingService, Initializer, PerformingService, Singleton, WrappingCall
Defined in:
lib/to_proc_interface.rb,
lib/to_proc_interface/hooks.rb,
lib/to_proc_interface/version.rb,
lib/to_proc_interface/singleton.rb,
lib/to_proc_interface/initializer.rb,
lib/to_proc_interface/call_to_maybe.rb,
lib/to_proc_interface/wrapping_call.rb,
lib/to_proc_interface/calling_service.rb,
lib/to_proc_interface/performing_service.rb

Overview

Examples:

Extended to a class

class Sum
  extend ToProcInterface

  def self.call(a, b)
    a + b
  end
end

Sum[1, 2] # => 3

Included to a class

class Sum
  include ToProcInterface

  def call(a, b)
    a + b
  end
end

Sum.new[1, 2] # => 3

Included to a module

module YieldToInstanceCall
  # @!parse extend ToProcInterface::Hooks::Extended
  # @!parse extend ToProcInterface::Hooks::Inherited
  include ToProcInterface

  def call(*args, **opts, &block)
    new(*args, **opts).call(&block)
  end
end

class BinaryOp
  extend YieldToInstanceCall

  def initialize(a, b)
    @a, @b = a, b
  end

  def call
    yield(@a, @b)
  end
end

BinaryOp.(1, 2, &:+) # => 3

Defined Under Namespace

Modules: CallToMaybe, CallingService, Delegations, Hooks, Initializer, Mixin, PerformingService, Singleton, WrappingCall

Constant Summary collapse

METHODS =
[
  :parameters,
  :<<,
  :yield,
  :[],
  :>>,
  :arity,
  :lambda?,
  :binding,
  :curry,
  :source_location
].freeze
VERSION =
"0.2.0"

Instance Attribute Summary

Attributes included from Mixin

#to_proc

Class Method Summary collapse

Methods included from Mixin

#call

Class Method Details

.loaderObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/to_proc_interface.rb', line 103

def self.loader
  @loader ||=
    Zeitwerk::Loader.for_gem.tap do |loader|
      root = __dir__
      loader.tag = "to_proc_interface"
      loader.push_dir root
      loader.ignore \
        "#{root}/to_proc_interface/call_to_maybe.rb",
        "#{root}/to_proc_interface/hooks.rb",
        "#{root}/to_proc_interface/performing_service.rb",
        "#{root}/to_proc_interface/singleton.rb",
        "#{root}/to_proc_interface/wrapping_call.rb"

      if defined?(Pry)
        loader.log!
        loader.enable_reloading
      end
    end
end