Class: ComposableProc

Inherits:
Object show all
Defined in:
lib/lab419/core/extensions/composable_proc.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#my_lambdaObject (readonly)

Returns the value of attribute my_lambda.



3
4
5
# File 'lib/lab419/core/extensions/composable_proc.rb', line 3

def my_lambda
  @my_lambda
end

Class Method Details

.identityObject



35
# File 'lib/lab419/core/extensions/composable_proc.rb', line 35

def identity; Proc.identity end

Instance Method Details

#and(lmbda = nil, &block) ⇒ Object Also known as: +

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lab419/core/extensions/composable_proc.rb', line 5

def and lmbda=nil, &block
  raise ArgumentError, "either use a lambda or a block" if !!block == !!lmbda
  self.class.new do | *args, &blk |
    nxt = lmbda || block
    results = my_lambda.( *args, &blk )
    if Array === results
      if nxt.arity < 0 || nxt.arity == results.size
        nxt.( *results )
      elsif nxt.arity.zero?
        nxt.()
      else
        nxt.( results )
      end
    else
      nxt.( results )
    end
  end
end

#arityObject



25
# File 'lib/lab419/core/extensions/composable_proc.rb', line 25

def arity; my_lambda.arity end

#call(*args, &blk) ⇒ Object Also known as: []



27
28
29
# File 'lib/lab419/core/extensions/composable_proc.rb', line 27

def call *args, &blk
  my_lambda.call( *args, &blk )
end

#to_procObject



32
# File 'lib/lab419/core/extensions/composable_proc.rb', line 32

def to_proc; my_lambda.to_proc end