Proposal: New "ends" keyword

Ok, here are 2 simple rules that control (can make more if necessary).

  1. an end statement can only resolve 1 open thing.
  2. an ends statement must resolve 2 or more open things.

Thus this

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))
    end 
  end 
end

could also be written as

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 
end

or

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))
    end 
ends

but not

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
ends

For your example

class Foo
  def bar
    while true
    ends

    if foo
      while true
ends

you would then know to unambiguously write as this (if this is what you mean).

class Foo
  def bar
    while true
  ends

  if foo
    while true
  ends
end

Initially at least, the best practice will be to write it with standard format to get the program working correctly, then syntactically simplify afterwards.This would be no different than writing programs now. First make it work, then see how to refactor|rewrite to make it faster, more modular, etc afterwards.

Again, this would not be a coding requirement, but would be syntactical sugar.