Permalink
Browse files

use Hash#fetch to eliminate conditional

  • Loading branch information...
1 parent bf62077 commit 9cbb6d2b20a8e3352bedd791fafe3c58f8bef328 @tenderlove tenderlove committed Aug 25, 2012
@@ -174,14 +174,9 @@ def transaction(options = {})
options.assert_valid_keys :requires_new, :joinable
last_transaction_joinable = @transaction_joinable
- if options.has_key?(:joinable)
- @transaction_joinable = options[:joinable]
- else
- @transaction_joinable = true
- end
- requires_new = options[:requires_new] || !last_transaction_joinable
-
- transaction_open = false
+ @transaction_joinable = options.fetch(:joinable, true)
+ requires_new = options[:requires_new] || !last_transaction_joinable
+ transaction_open = false
begin
if requires_new || open_transactions == 0

1 comment on commit 9cbb6d2

Contributor

SamSaffron commented on 9cbb6d2 Aug 25, 2012

reduces to st_lookup(RHASH(hash)->ntbl, key, &val), so this is both faster and more elegant than the original

Please sign in to comment.