Test and improve "Anything"

This commit is contained in:
Michael Miller 2021-02-09 19:10:11 -07:00
parent 4e3cb5d25f
commit a20f2d4f98
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 70 additions and 0 deletions

View file

@ -1,15 +1,36 @@
module Spectator
# Type dedicated to matching everything.
# This is intended to be used as a value to compare against when the value doesn't matter.
# Can be used like so:
# ```
# anything = Spectator::Anything.new
# array = ["foo", anything]
# expect(["foo", "bar"]).to eq(array)
# ```
struct Anything
# Always returns true.
def ==(other)
true
end
# Always returns true.
def ===(other)
true
end
# Always returns true.
def =~(other)
true
end
# Displays "anything".
def to_s(io)
io << "anything"
end
# Displays "<anything>".
def inspect(io)
io << "<anything>"
end
end
end