Sha256: 652f65288efaa0a37d45eff5294a8958fda1f0b3465ee8486ef09a20d57ec875
Contents?: true
Size: 999 Bytes
Versions: 4
Compression:
Stored size: 999 Bytes
Contents
require 'abstractivator/enumerable_ext' module MethodAndProcExtensions def loosen_args proc do |*args, &block| Proc.loose_call(self, args, &block) end end end class Proc include MethodAndProcExtensions def compose(other) proc{|x| self.call(other.call(x))} end def self.compose(*procs) procs.map(&:to_proc).inject_right(identity) { |inner, p| p.compose(inner) } end def self.identity proc {|x| x} end def reverse_args proc do |*args, &block| self.call(*args.reverse, &block) end end def self.loose_call(x, args, &block) x.respond_to?(:call) ? x.call(*args.take(x.arity).pad_right(x.arity), &block) : x end end class Method include MethodAndProcExtensions end class UnboundMethod def explicit_receiver proc do |receiver, *args, &block| self.bind(receiver).call(*args, &block) end end end class Array def to_proc raise 'size must be exactly one' unless size == 1 proc{|x| x[first]} end end
Version data entries
4 entries across 4 versions & 1 rubygems