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

This commit is contained in:
David Workman
2011-05-23 22:33:03 +01:00
parent 8588dd431b
commit 86afbf7464

View File

@@ -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