Sha256: 9e35202c59d02516aec0eef5f74ae2225daef0ab6e4cd1b32169ace2bed888ab
Contents?: true
Size: 734 Bytes
Versions: 11
Compression:
Stored size: 734 Bytes
Contents
# MissingArgument exception class is used to represent an argument "hole". class MissingArgument < ArgumentError end # Convenience method for an argument hole. # It simple returns the MissingArgument exception class. def __ MissingArgument end class Proc # Convert a Proc object into new partial Proc object. # # a = proc { |a,b,c| a+b+c } # b = a.partial(__, 2, __) # b[1,3] #=> 6 # # This method is similar to Proc#curry. # # CREDT Trans # # TODO: Parhaps ArgumentError would suffice, and we don't need MissingArgument? def partial(*args) Proc.new do |*spice| result = args.collect do |a| MissingArgument == a ? spice.pop : a end call(*result) end end end
Version data entries
11 entries across 11 versions & 2 rubygems