【一人 bugs.ruby Advent Calendar 2021】[Feature #17786] Proposal: new "ends" keyword【6日目】
一人 bugs.ruby Advent Calendar 2021 6日目の記事になります。
今回は複数の end を ends という1つのキーワードで定義できるようにしようという提案です。
[Feature #17786] Proposal: new "ends" keyword
複数の end を ends という1つのキーワードで定義できるようにしようという提案です。
例えば以下のようなコードがあった時に
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
これを以下のように記述するイメージです。
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 を最後の ends 1個だけで記述します。
いろいろとコメントされているが流石に否定的な内容が目立つ…。
例えば次のように途中に ends がある場合に class A の end が不用意に閉じられて SyntaxError になるので実装するのはかなり難しそうですね。
class A def b c do d do e ends # ここで class A のスコープが閉じられる def c end end # なのでここで SyntaxError になる
『 end を追加するエディタ使おう』って書かれていてそれはそう。