JoshCheek / seeing_is_believing

Displays the results of every line of code in your file
1.3k stars 54 forks source link

Ruby3 endless method bug #163

Open JoshCheek opened 3 years ago

JoshCheek commented 3 years ago

The def ===(o) = inside RespondTo (works if you switch it over to an ended method)

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