Class: Algebrick::Matchers::Abstract

Inherits:
Object
  • Object
show all
Includes:
TypeCheck
Defined in:
lib/algebrick/matchers/abstract.rb

Direct Known Subclasses

AbstractLogic, Any, Array, Many, Not, Product, Wrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TypeCheck

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

Constructor Details

#initializeAbstract

Returns a new instance of Abstract.



21
22
23
# File 'lib/algebrick/matchers/abstract.rb', line 21

def initialize
  @assign, @value, @matched = nil
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#!Object



52
53
54
# File 'lib/algebrick/matchers/abstract.rb', line 52

def !
  Not.new self
end

#&(matcher) ⇒ Object



44
45
46
# File 'lib/algebrick/matchers/abstract.rb', line 44

def &(matcher)
  And.new self, matcher
end

#==(other) ⇒ Object

Raises:

  • (NotImplementedError)


102
103
104
# File 'lib/algebrick/matchers/abstract.rb', line 102

def ==(other)
  raise NotImplementedError
end

#===(other) ⇒ Object



82
83
84
# File 'lib/algebrick/matchers/abstract.rb', line 82

def ===(other)
  matching?(other).tap { |matched| @value = other if (@matched = matched) }
end

#>(block) ⇒ Object Also known as: >>



31
32
33
# File 'lib/algebrick/matchers/abstract.rb', line 31

def >(block)
  return self, block
end

#assign!Object Also known as: ~



37
38
39
40
# File 'lib/algebrick/matchers/abstract.rb', line 37

def assign!
  @assign = true
  self
end

#assign?Boolean

Returns:



56
57
58
# File 'lib/algebrick/matchers/abstract.rb', line 56

def assign?
  @assign
end

#assign_to_sObject



86
87
88
# File 'lib/algebrick/matchers/abstract.rb', line 86

def assign_to_s
  assign? ? '~' : ''
end

#assigned?Boolean

Returns:



60
61
62
# File 'lib/algebrick/matchers/abstract.rb', line 60

def assigned?
  !!@value
end

#assignsObject



72
73
74
75
76
# File 'lib/algebrick/matchers/abstract.rb', line 72

def assigns
  collect_assigns.tap do
    return yield *assigns if block_given?
  end
end

#case(&block) ⇒ Object Also known as: when



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

def case(&block)
  return self, block
end

#childrenObject

Raises:

  • (NotImplementedError)


94
95
96
# File 'lib/algebrick/matchers/abstract.rb', line 94

def children
  raise NotImplementedError
end

#children_including_selfObject



68
69
70
# File 'lib/algebrick/matchers/abstract.rb', line 68

def children_including_self
  children.unshift self
end

#inspectObject



90
91
92
# File 'lib/algebrick/matchers/abstract.rb', line 90

def inspect
  to_s
end

#matched?Boolean

Returns:



64
65
66
# File 'lib/algebrick/matchers/abstract.rb', line 64

def matched?
  @matched
end

#to_aObject



78
79
80
# File 'lib/algebrick/matchers/abstract.rb', line 78

def to_a
  assigns
end

#to_sObject

Raises:

  • (NotImplementedError)


98
99
100
# File 'lib/algebrick/matchers/abstract.rb', line 98

def to_s
  raise NotImplementedError
end

#|(matcher) ⇒ Object



48
49
50
# File 'lib/algebrick/matchers/abstract.rb', line 48

def |(matcher)
  Or.new self, matcher
end