Method: Object#against

Defined in:
lib/standard/facets/against.rb

#against(*msg, &blk) ⇒ Object

Objectified message or block application. Only a message or a block can be given, not both.

msg - method and arguments [Array] blk - procedure block [Proc]

Examples

a = [1,2,3,4,5]
c = a.against(:>, 2)
c.select  #=> [3,4,5]

a = [1,2,3,4,5]
c = a.against(:>)
c.select(2)  #=> [3,4,5]

Returns [Functor]

TODO: Better name for this method?

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/standard/facets/against.rb', line 25

def against(*msg, &blk)
  raise ArgumentError, "too many arguments" if blk && !msg.empty?

 this = self

  blk = ::Proc.new{ |x,*a| x.__send__(*msg, *a) } unless blk

  #if blk
  Functor.new do |m, *a, &b|
	  if b
	    b2 = ::Proc.new{ |*x| blk.call(*b.call(*x), *a) }
      else
        b2 = blk
	  end
	  this.__send__(m, &b2)
  end
  #else
 #	Functor.new do |m, *a, &b|
 #		if b
 #		  b2 = ::Proc.new{ |*x| b.call(*x).__send__(*msg, *a) }
 #		else
 #		  b2 = ::Proc.new{ |x| x.__send__(*msg, *a) }
 #		end
 #		this.__send__(m, &b2)
 #	end
  #end
end