The document discusses Ruby's === operator and how it can be used to emulate pattern matching. It explains how === is used internally by classes like Integer, Regexp, and Range to check object equality. It then shows how to write custom matcher classes and procedures to select objects based on multiple criteria, like selecting people objects that match a name regex and fall within an age range. Finally, it provides examples of pattern matching libraries like Qo that build on these concepts.
39. CLASS WRAPPERS
class Query
def initialize(*ms) @ms = ms end
def to_proc
proc { |v| self.call(v) }
end
def call(v)
@ms.all? { |m| m === v }
end
alias_method :===, :call
end
@keystonelemur
40. CLASS WRAPPERS
class Query
def initialize(*ms) @ms = ms end
def to_proc
proc { |v| self.call(v) }
end
def call(v)
@ms.all? { |m| m === v }
end
alias_method :===, :call
end
@keystonelemur
41. CLASS WRAPPERS
class Query
def initialize(*ms) @ms = ms end
def to_proc
proc { |v| self.call(v) }
end
def call(v)
@ms.all? { |m| m === v }
end
alias_method :===, :call
end
@keystonelemur
42. CLASS WRAPPERS
class Query
def initialize(*ms) @ms = ms end
def to_proc
proc { |v| self.call(v) }
end
def call(v)
@ms.all? { |m| m === v }
end
alias_method :===, :call
end
@keystonelemur