We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0efef74 commit d852dcfCopy full SHA for d852dcf
chapter06/extract_surrounding_method.rb
@@ -1,13 +1,19 @@
1
class ExtractSurroundingMethod
2
def charge(amount, credit_card_number)
3
- begin
4
- connection = CreditCardServer.connect(...)
+ connect do |connection|
5
connection.send(amount, credit_card_number)
6
- rescue IOError => e
7
- Logger.log "Could not submit order #{@order_number} to the server: #{e}"
8
- return nil
9
- ensure
10
- connection.close
+ end
+
+ def connect
+ begin
+ connection = CreditCardServer.connect(...)
+ yield connection
11
+ rescue IOError => e
12
+ Logger.log "Could not submit order #{@order_number} to the server: #{e}"
13
+ return nil
14
+ ensure
15
+ connection.close
16
17
end
18
19
0 commit comments