Sinatra does a little bit of magic there.

You probably know that in Ruby the content after an __END__ token is
available via the DATA filehandle... as long as you are in the main file
passed to Ruby to execute.

Sinatra extends this idea to other files to offer inline templates,
processing __END__ by hand:


https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1267

Then, it evaluates the text accordingly.