Automatic insertion of end blocks for Ruby