Proposal: New "ends" keyword

I’m open to you being right about me making this harder than it has to be. In the spirit of trying to understand, here’s where I’m getting tripped up by this ends thing.

module Graphics
  class Renderer
    def render(scene, image, screenWidth, screenHeight)
      screenHeight.times do |y|
        screenWidth.times do |x|
          color = self.traceRay(....)
          r, g, b = Color.toDrawingColor(color)
          image.set(x, y, StumpyCore::RGBA.from_rgb(r, g, b))
    ends # <----- This line

    def do_something_else
      . . .
    end
ends

I understand that the parser, at that point, will need to sort of “unroll” the contexts it’s in (I don’t know if this is implemented as a stack, but it reminds me of going up and down the call stack with method calls and then returns). What I don’t understand is how, in the process of that unrolling, it knows to stop unrolling once it gets to the class context. In particular, I don’t know how the parser is supposed to know, when it gets to that line, the difference between that code above and

module Graphics
  class Renderer
    def render(scene, image, screenWidth, screenHeight)
      screenHeight.times do |y|
        screenWidth.times do |x|
          color = self.traceRay(....)
          r, g, b = Color.toDrawingColor(color)
          image.set(x, y, StumpyCore::RGBA.from_rgb(r, g, b))
ends

The compiler needs to be able to know (in the first of my two code examples) whether that next method is in the class or not. It doesn’t know about the indentation, and as far as I’m aware it doesn’t know about the ends after that other method. I just don’t see how it has the context to know that it’s still in the class. Even worse, how does the compiler (and how do I) know whether that second method is in the class or the module?