From 86afbf7464e96dd156895eba2fa44b41678cdd6e Mon Sep 17 00:00:00 2001 From: David Workman Date: Mon, 23 May 2011 22:33:03 +0100 Subject: Using .try to test for the existence of a method option in a nil-resistent manner. Inlined the determination of the options hash for reversing using a ternary operator. Shortens the method in a way that keeps the code neat --- activerecord/lib/active_record/migration/command_recorder.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb index 5923993229..88752aa013 100644 --- a/activerecord/lib/active_record/migration/command_recorder.rb +++ b/activerecord/lib/active_record/migration/command_recorder.rb @@ -80,11 +80,8 @@ module ActiveRecord def invert_add_index(args) table, columns, options = *args - if options && options[:name] - options_hash = {:name => options[:name]} - else - options_hash = {:column => columns} - end + index_name = options.try(:[], :name) + options_hash = index_name ? {:name => index_name} : {:column => columns} [:remove_index, [table, options_hash]] end -- cgit v1.2.3