Open JoshCheek opened 3 years ago
The def ===(o) = inside RespondTo (works if you switch it over to an ended method)
def ===(o) =
RespondTo
end
seeing_is_believing -ge ' module Types 2.times do using Types private def to_type(o) = (Symbol === o ? RespondTo.new(o) : o) def |(type) = Or.new(to_type(self), to_type(type)) refine(Module) { include Types } refine(Symbol) { include Types } end RespondTo = Struct.new(:name) { def ===(o) = o.respond_to?(name) def inspect() = ".respond_to?(#{name.inspect})" }.include(Types) Or = Struct.new(:left, :right) { def ===(o) left === o || right === o end def inspect() = "(#{left.inspect} | #{right.inspect})" }.include(Types) end using Types Integer | String | (:to_int | :to_str) # => ' -x
The
def ===(o) =
insideRespondTo
(works if you switch it over to anend
ed method)