Class: Algebrick::Matchers::Or

Inherits:
AbstractLogic show all
Defined in:
lib/algebrick/matchers/or.rb

Overview

noinspection RubyClassModuleNamingConvention

Instance Attribute Summary

Attributes inherited from AbstractLogic

#matchers

Attributes inherited from Abstract

#value

Instance Method Summary (collapse)

Methods inherited from AbstractLogic

#==, call, #initialize

Methods inherited from Abstract

#!, #&, #==, #===, #>, #assign!, #assign?, #assign_to_s, #assigned?, #assigns, #case, #children_including_self, #find_children, #initialize, #inspect, #matchable!, #matched?, #to_a, #|

Methods included from TypeCheck

#Child!, #Child?, #Match!, #Match?, #Type!, #Type?, error

Constructor Details

This class inherits a constructor from Algebrick::Matchers::AbstractLogic

Instance Method Details

- (Object) assigns_size (private)



45
46
47
48
# File 'lib/algebrick/matchers/or.rb', line 45

def assigns_size
  # TODO is it efficient?
  super_children.map { |ch| ch.assigns.size }.max
end

- (Object) children (protected)



32
33
34
# File 'lib/algebrick/matchers/or.rb', line 32

def children
  super.select &:matched?
end

- (Object) collect_assigns (private)



38
39
40
41
42
43
# File 'lib/algebrick/matchers/or.rb', line 38

def collect_assigns
  super.tap do |assigns|
    missing = assigns_size - assigns.size
    assigns.push(*::Array.new(missing))
  end
end

- (Boolean) matching?(other) (protected)

Returns:



25
26
27
# File 'lib/algebrick/matchers/or.rb', line 25

def matching?(other)
  matchers.any? { |m| m === other }
end

- (Object) super_children (private)



29
# File 'lib/algebrick/matchers/or.rb', line 29

alias_method :super_children, :children

- (Object) to_s



19
20
21
# File 'lib/algebrick/matchers/or.rb', line 19

def to_s
  matchers.join ' | '
end