G
Graham Jenkins
I'm considering raising an RCR: "allow multiple ensure blocks". I've
searched for this to some extent - have I missed anything obvious?
I want to be able to write:
begin
raise 'something bad'
ensure
puts 1
ensure
puts 2
end
This is so I can reliably cleanup all request resources in my fcgi
scripts (rollback database connection, finish the request, cleanup
environment and session objects) without having to nest
begin...ensure...end blocks inside the only ensure block I'm allowed
to write.
I know that the Ruby Way is probably to nest separate blocks for each
of these resources
Database.use { |dbh|
Request.use { |req|
Session.use { |ses|
...
# my code here
}
}
}
but I end up nesting the real code about 10 layers deep if I do that.
searched for this to some extent - have I missed anything obvious?
I want to be able to write:
begin
raise 'something bad'
ensure
puts 1
ensure
puts 2
end
This is so I can reliably cleanup all request resources in my fcgi
scripts (rollback database connection, finish the request, cleanup
environment and session objects) without having to nest
begin...ensure...end blocks inside the only ensure block I'm allowed
to write.
I know that the Ruby Way is probably to nest separate blocks for each
of these resources
Database.use { |dbh|
Request.use { |req|
Session.use { |ses|
...
# my code here
}
}
}
but I end up nesting the real code about 10 layers deep if I do that.