Class: Algebrick::Matchers::Wrapper

Inherits:
Abstract show all
Defined in:
lib/algebrick/matchers/wrapper.rb

Overview

wraps any object having #=== method into matcher

Direct Known Subclasses

Atom, Variant

Instance Attribute Summary collapse

Attributes inherited from Abstract

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

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

Methods included from TypeCheck

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

Constructor Details

#initialize(something) ⇒ Wrapper

Returns a new instance of Wrapper.



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

def initialize(something)
  super()
  @something = matchable! something
end

Instance Attribute Details

#somethingObject (readonly)

Returns the value of attribute something.



23
24
25
# File 'lib/algebrick/matchers/wrapper.rb', line 23

def something
  @something
end

Class Method Details

.call(something) ⇒ Object



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

def self.call(something)
  new something
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
41
# File 'lib/algebrick/matchers/wrapper.rb', line 38

def ==(other)
  other.kind_of? self.class and
      self.something == other.something
end

#childrenObject



30
31
32
# File 'lib/algebrick/matchers/wrapper.rb', line 30

def children
  find_children [@something]
end

#to_sObject



34
35
36
# File 'lib/algebrick/matchers/wrapper.rb', line 34

def to_s
  assign_to_s + "Wrapper.(#{@something})"
end