sinatra/sinatra — pull request #421 by banister (2011-11-30 13:37:52+00:00)
Title: Simplify some of the block-handling complexity with instance_exec()

Currently a very unusual trick (https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1186-1191) is used to ensure some blocks execute in the correct context (I assume this is a hold-over from 1.8.6 support where `instance_exec()` was not available.)

Now that Sinatra no longer supports 1.8.6 we can maybe switch from the `define_method` / `remove_method` approach and use `instance_exec()` instead.

Lambda-like arity semantics are maintained by wrapping the block in a proc that checks arity. As in the previous situation an exception is made for arity 0 blocks, where normal block semantics hold.