assert

rackのソースをゆっくり読んでる。

読んだのは、周辺の lint.rb.
アプリケーション呼び出しの、事前(引数 env)チェック、事後(app実行結果のstatus, headers, body)チェックしてる。

if文を並べる変わりに、assert(”条件の説明”) { <条件> }の記述で、
宣言的に事前/事後の条件をすっきり記述してるのが印象に残った。

    ## === The Status
    def check_status(status)
      ## This is an HTTP status. When parsed as integer (+to_i+), it must be
      ## greater than or equal to 100.
      assert("Status must be >=100 seen as integer") { status.to_i >= 100 }
    end

https://github.com/rack/rack/blob/master/lib/rack/lint.rb


rackは、

  def call(env)
    <何か処理>
    [status, headers, [body]]
  end

を軸に 呼び出し連鎖をするんだが、その一つが lintになる。