Sha256: 1a3e4a709e7e92f8c0c532fd36014c7624b0e03fccd7f6af2e8c19b69c20e31e

Contents?: true

Size: 849 Bytes

Versions: 101

Compression:

Stored size: 849 Bytes

Contents

module Tins
  module PartialApplication
    # If this module is included into a Proc (or similar object), it tampers
    # with its Proc#arity method.
    def self.included(modul)
      modul.module_eval do
        old_arity = instance_method(:arity)
        define_method(:arity) do
          @__arity__ or old_arity.bind(self).call
        end
      end
      super
    end

    # Create a partial application of this Proc (or similar object) using
    # _args_ as the already applied arguments.
    def partial(*args)
      if args.empty?
        dup
      elsif args.size > arity
        raise ArgumentError, "wrong number of arguments (#{args.size} for #{arity})"
      else
        f = lambda { |*b| call(*(args + b)) }
        f.instance_variable_set :@__arity__, arity - args.size
        f
      end
    end
  end
end

require 'tins/alias'

Version data entries

101 entries across 98 versions & 9 rubygems

Version Path
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/tins-0.13.2/lib/tins/partial_application.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/tins-0.13.2/lib/tins/partial_application.rb
tdiary-5.0.8 vendor/bundle/gems/tins-0.13.2/lib/tins/partial_application.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/tins-0.13.2/lib/tins/partial_application.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/partial_application.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/partial_application.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/partial_application.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/partial_application.rb
tdiary-5.0.5 vendor/bundle/gems/tins-1.13.2/lib/tins/partial_application.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/tins-1.13.2/lib/tins/partial_application.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/tins-1.13.2/lib/tins/partial_application.rb
tdiary-5.0.4 vendor/bundle/gems/tins-1.13.2/lib/tins/partial_application.rb
tins-1.13.2 lib/tins/partial_application.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/tins-1.13.0/lib/tins/partial_application.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/tins-1.13.0/lib/tins/partial_application.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/tins-1.13.0/lib/tins/partial_application.rb
tins-1.13.0 lib/tins/partial_application.rb
tdiary-5.0.2 vendor/bundle/gems/tins-1.12.0/lib/tins/partial_application.rb
tins-1.12.0 lib/tins/partial_application.rb
tins-1.11.0 lib/tins/partial_application.rb