diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb
index 75aa9df812..1b35cbe403 100644
--- a/actionpack/lib/action_controller/caching.rb
+++ b/actionpack/lib/action_controller/caching.rb
@@ -222,7 +222,7 @@ module ActionController #:nodoc:
class ActionCacheFilter #:nodoc:
def initialize(*actions, &block)
- @options = actions.last.is_a?(Hash) ? actions.pop : {}
+ @options = actions.extract_options!
@actions = Set.new actions
end
@@ -596,7 +596,7 @@ module ActionController #:nodoc:
module ClassMethods #:nodoc:
def cache_sweeper(*sweepers)
return unless perform_caching
- configuration = sweepers.last.is_a?(Hash) ? sweepers.pop : {}
+ configuration = sweepers.extract_options!
sweepers.each do |sweeper|
ActiveRecord::Base.observers << sweeper if defined?(ActiveRecord) and defined?(ActiveRecord::Base)
sweeper_instance = Object.const_get(Inflector.classify(sweeper)).instance
diff --git a/actionpack/lib/action_controller/filters.rb b/actionpack/lib/action_controller/filters.rb
index c2f2c2a432..ec3f5096e3 100644
--- a/actionpack/lib/action_controller/filters.rb
+++ b/actionpack/lib/action_controller/filters.rb
@@ -601,7 +601,7 @@ module ActionController #:nodoc:
def extract_conditions(*filters, &block) #:nodoc:
filters.flatten!
- conditions = filters.last.is_a?(Hash) ? filters.pop : {}
+ conditions = filters.extract_options!
filters << block if block_given?
return filters, conditions
end
diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb
index 1cfb7c11d0..3cb9367fc2 100644
--- a/actionpack/lib/action_controller/resources.rb
+++ b/actionpack/lib/action_controller/resources.rb
@@ -295,7 +295,7 @@ module ActionController
# HTTP POST on new_message_url will raise a RoutingError exception. The default route in
# config/routes.rb overrides this and allows invalid HTTP methods for resource routes.
def resources(*entities, &block)
- options = entities.last.is_a?(Hash) ? entities.pop : { }
+ options = entities.extract_options!
entities.each { |entity| map_resource(entity, options.dup, &block) }
end
@@ -369,7 +369,7 @@ module ActionController
# edit_account edit_account_url, hash_for_edit_account_url,
# edit_account_path, hash_for_edit_account_path
def resource(*entities, &block)
- options = entities.last.is_a?(Hash) ? entities.pop : { }
+ options = entities.extract_options!
entities.each { |entity| map_singleton_resource(entity, options.dup, &block) }
end
diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb
index 97ddc41c7e..08abdbd8a8 100644
--- a/actionpack/lib/action_view/helpers/active_record_helper.rb
+++ b/actionpack/lib/action_view/helpers/active_record_helper.rb
@@ -118,7 +118,7 @@ module ActionView
# you need is significantly different from the default presentation, it makes plenty of sense to access the object.errors
# instance yourself and set it up. View the source of this method to see how easy it is.
def error_messages_for(*params)
- options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
+ options = params.extract_options!.symbolize_keys
objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
count = objects.inject(0) {|sum, object| sum + object.errors.count }
unless count.zero?
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 6c4eb0931c..46b08fce76 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -172,7 +172,7 @@ module ActionView
# javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false =>
#
def javascript_include_tag(*sources)
- options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
+ options = sources.extract_options!.stringify_keys
cache = options.delete("cache")
if ActionController::Base.perform_caching && cache
@@ -281,7 +281,7 @@ module ActionView
# stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true =>
#
def stylesheet_link_tag(*sources)
- options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
+ options = sources.extract_options!.stringify_keys
cache = options.delete("cache")
if ActionController::Base.perform_caching && cache
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 22d2984adb..9c31fb6c90 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -158,7 +158,7 @@ module ActionView
def form_for(record_or_name_or_array, *args, &proc)
raise ArgumentError, "Missing block" unless block_given?
- options = args.last.is_a?(Hash) ? args.pop : {}
+ options = args.extract_options!
case record_or_name_or_array
when String, Symbol
@@ -212,7 +212,7 @@ module ActionView
# like FormOptionHelper#collection_select and DateHelper#datetime_select.
def fields_for(object_name, *args, &block)
raise ArgumentError, "Missing block" unless block_given?
- options = args.last.is_a?(Hash) ? args.pop : {}
+ options = args.extract_options!
object = args.first
builder = options[:builder] || ActionView::Base.default_form_builder
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb
index 4dd7854367..51cbfb95d9 100644
--- a/actionpack/lib/action_view/helpers/javascript_helper.rb
+++ b/actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -80,7 +80,7 @@ module ActionView
# return false;">Show me more
#
def link_to_function(name, *args, &block)
- html_options = args.last.is_a?(Hash) ? args.pop : {}
+ html_options = args.extract_options!
function = args[0] || ''
html_options.symbolize_keys!
@@ -111,7 +111,7 @@ module ActionView
# page[:details].visual_effect :toggle_slide
# end
def button_to_function(name, *args, &block)
- html_options = args.last.is_a?(Hash) ? args.pop : {}
+ html_options = args.extract_options!
function = args[0] || ''
html_options.symbolize_keys!
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index d1f992486f..0da5cc5579 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -182,7 +182,7 @@ module ActionView
# Works like form_remote_tag, but uses form_for semantics.
def remote_form_for(record_or_name, *args, &proc)
- options = args.last.is_a?(Hash) ? args.pop : {}
+ options = args.extract_options!
case record_or_name
when String, Symbol
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb
index 96cbd3043a..1fe1fee748 100644
--- a/activerecord/lib/active_record/associations/association_proxy.rb
+++ b/activerecord/lib/active_record/associations/association_proxy.rb
@@ -98,10 +98,6 @@ module ActiveRecord
@reflection.klass.send(:sanitize_sql, sql)
end
- def extract_options_from_args!(args)
- @owner.send(:extract_options_from_args!, args)
- end
-
def set_belongs_to_association_for(record)
if @reflection.options[:as]
record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new_record?
diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
index b5f718ae52..d06af335ef 100644
--- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -29,7 +29,7 @@ module ActiveRecord
end
def find(*args)
- options = Base.send(:extract_options_from_args!, args)
+ options = args.extract_options!
# If using a custom finder_sql, scan the entire collection.
if @reflection.options[:finder_sql]
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index 393d59b084..838eb00863 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -38,7 +38,7 @@ module ActiveRecord
end
def find(*args)
- options = Base.send(:extract_options_from_args!, args)
+ options = args.extract_options!
# If using a custom finder_sql, scan the entire collection.
if @reflection.options[:finder_sql]
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index 3d60da76b3..ebe1be04e5 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -9,7 +9,7 @@ module ActiveRecord
end
def find(*args)
- options = Base.send(:extract_options_from_args!, args)
+ options = args.extract_options!
conditions = "#{@finder_sql}"
if sanitized_conditions = sanitize_sql(options[:conditions])
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 5ab761932f..5319ec6ec2 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -421,7 +421,7 @@ module ActiveRecord #:nodoc:
# person.save!
# end
def find(*args)
- options = extract_options_from_args!(args)
+ options = args.extract_options!
validate_find_options(options)
set_readonly_option!(options)
@@ -1604,10 +1604,6 @@ module ActiveRecord #:nodoc:
end
end
- def extract_options_from_args!(args) #:nodoc:
- args.last.is_a?(Hash) ? args.pop : {}
- end
-
VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset,
:order, :select, :readonly, :group, :from, :lock ]
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index b6c3949a5a..d4143cee3c 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -364,7 +364,7 @@ module ActiveRecord
%w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
class_eval <<-EOV
def #{column_type}(*args)
- options = args.last.is_a?(Hash) ? args.pop : {}
+ options = args.extract_options!
column_names = args
column_names.each { |name| column(name, '#{column_type}', options) }
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
index 79247e00cb..eee61d48c4 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -21,7 +21,7 @@ class Class # :nodoc:
end
def cattr_writer(*syms)
- options = syms.last.is_a?(Hash) ? syms.pop : {}
+ options = syms.extract_options!
syms.flatten.each do |sym|
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined? @@#{sym}
diff --git a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
index 2dd0c577d1..371d074d34 100644
--- a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
+++ b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
@@ -23,7 +23,7 @@ class Class # :nodoc:
end
def class_inheritable_writer(*syms)
- options = syms.last.is_a?(Hash) ? syms.pop : {}
+ options = syms.extract_options!
syms.each do |sym|
class_eval <<-EOS
def self.#{sym}=(obj)
@@ -40,7 +40,7 @@ class Class # :nodoc:
end
def class_inheritable_array_writer(*syms)
- options = syms.last.is_a?(Hash) ? syms.pop : {}
+ options = syms.extract_options!
syms.each do |sym|
class_eval <<-EOS
def self.#{sym}=(obj)
@@ -57,7 +57,7 @@ class Class # :nodoc:
end
def class_inheritable_hash_writer(*syms)
- options = syms.last.is_a?(Hash) ? syms.pop : {}
+ options = syms.extract_options!
syms.each do |sym|
class_eval <<-EOS
def self.#{sym}=(obj)
diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
index 8127150a96..58ff363244 100644
--- a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
@@ -21,7 +21,7 @@ class Module # :nodoc:
end
def mattr_writer(*syms)
- options = syms.last.is_a?(Hash) ? syms.pop : {}
+ options = syms.extract_options!
syms.each do |sym|
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined? @@#{sym}
diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb
index 8499ad6e2d..2baa667c03 100644
--- a/activesupport/lib/active_support/deprecation.rb
+++ b/activesupport/lib/active_support/deprecation.rb
@@ -85,7 +85,7 @@ module ActiveSupport
module ClassMethods #:nodoc:
# Declare that a method has been deprecated.
def deprecate(*method_names)
- options = method_names.last.is_a?(Hash) ? method_names.pop : {}
+ options = method_names.extract_options!
method_names = method_names + options.keys
method_names.each do |method_name|
alias_method_chain(method_name, :deprecation) do |target, punctuation|