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, #collect_assigns, #find_children, #inspect, #matchable!, #matched?, #to_a, #|

Methods included from TypeCheck

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

Constructor Details

- (Wrapper) initialize(something)

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

- (Object) something (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

+ (Object) call(something)



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

def self.call(something)
  new something
end

Instance Method Details

- (Object) ==(other)



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

- (Object) children



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

def children
  find_children [@something]
end

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

Returns:



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

def matching?(other)
  @something === other
end

- (Object) to_s



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

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