def with_logging(description)
begin
@logger.debug("Start #{description}")
yield
@logger.debug("Completed #{description}")
rescue
@logger.error("#{description} failed!")
raise
end
end
# use it
with_logging("compute something") do
25 * 26
end
class Document
attr_accessor :title, :number
def initialize
yield( self ) if block_given?
end
end
# use it
Document.new do |doc|
doc.title = "something"
doc.number = 123
end