Class: LogicalLambda

Inherits:
Proc
  • Object
show all
Defined in:
lib/logical_lambda.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_comparable(compare_method) ⇒ Object

Comparables #############



21
22
23
24
25
26
27
28
29
30
# File 'lib/logical_lambda.rb', line 21

def self.define_comparable(compare_method)
  define_method compare_method do |other|
    if other.respond_to?(:call)
      LogicalLambda.new {|*args| call(*args).send(compare_method, other.call(*args)) }
    else
      # Must not be a block
      LogicalLambda.new {|*args| call(*args).send(compare_method, other) }
    end
  end
end

Instance Method Details

#!@Object

Override the negative and bang as in -is_true !is_true



10
# File 'lib/logical_lambda.rb', line 10

def !@; LogicalLambda.new {|*args| !call(*args)}; end

#&(other) ⇒ Object

AND



5
6
7
# File 'lib/logical_lambda.rb', line 5

def &(other)
  LogicalLambda.new {|*args| call(*args) && other.call(*args) }
end

#|(other) ⇒ Object

OR



15
16
17
# File 'lib/logical_lambda.rb', line 15

def |(other)
  LogicalLambda.new {|*args| call(*args) || other.call(*args) }
end