Skip to content

Commit 7d86235

Browse files
committed
get rid of using instance_variable_names method from AS
- instance_variables return symbols in 1.9 - there is instance_variable_defined? method
1 parent ba168e8 commit 7d86235

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

actionmailer/lib/action_mailer/base.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ class Base < AbstractController::Base
332332
include AbstractController::Translation
333333
include AbstractController::AssetPaths
334334

335-
self.protected_instance_variables = %w(@_action_has_layout)
335+
self.protected_instance_variables = [:@_action_has_layout]
336336

337337
helper ActionMailer::MailHelper
338338

actionpack/lib/abstract_controller/rendering.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require "abstract_controller/base"
22
require "action_view"
3-
require "active_support/core_ext/object/instance_variables"
43

54
module AbstractController
65
class DoubleRenderError < Error
@@ -109,17 +108,17 @@ def _render_template(options) #:nodoc:
109108
view_renderer.render(view_context, options)
110109
end
111110

112-
DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w(
113-
@_action_name @_response_body @_formats @_prefixes @_config
114-
@_view_context_class @_view_renderer @_lookup_context
115-
)
111+
DEFAULT_PROTECTED_INSTANCE_VARIABLES = [
112+
:@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config,
113+
:@_view_context_class, :@_view_renderer, :@_lookup_context
114+
]
116115

117116
# This method should return a hash with assigns.
118117
# You can overwrite this configuration per controller.
119118
# :api: public
120119
def view_assigns
121120
hash = {}
122-
variables = instance_variable_names
121+
variables = instance_variables
123122
variables -= protected_instance_variables
124123
variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
125124
variables.each { |name| hash[name.to_s[1, name.length]] = instance_variable_get(name) }

actionpack/lib/action_controller/metal/compatibility.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class << self
1818
delegate :default_charset=, :to => "ActionDispatch::Response"
1919
end
2020

21-
self.protected_instance_variables = %w(
22-
@_status @_headers @_params @_env @_response @_request
23-
@_view_runtime @_stream @_url_options @_action_has_layout
24-
)
21+
self.protected_instance_variables = [
22+
:@_status, :@_headers, :@_params, :@_env, :@_response, :@_request,
23+
:@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout
24+
]
2525

2626
def rescue_action(env)
2727
raise env["action_dispatch.rescue.exception"]

actionpack/lib/action_controller/test_case.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ def rescue_action_in_public!
506506
def check_required_ivars
507507
# Sanity check for required instance variables so we can give an
508508
# understandable error message.
509-
%w(@routes @controller @request @response).each do |iv_name|
510-
if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
509+
[:@routes, :@controller, :@request, :@response].each do |iv_name|
510+
if !instance_variable_defined?(iv_name) || instance_variable_get(iv_name).nil?
511511
raise "#{iv_name} is nil: make sure you set it in your test's setup method."
512512
end
513513
end

actionpack/test/controller/filters_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def before_filters
1616

1717
def assigns(key = nil)
1818
assigns = {}
19-
instance_variable_names.each do |ivar|
19+
instance_variables.each do |ivar|
2020
next if ActionController::Base.protected_instance_variables.include?(ivar)
2121
assigns[ivar[1..-1]] = instance_variable_get(ivar)
2222
end

activerecord/test/cases/associations/inner_join_association_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_find_with_implicit_inner_joins_honors_readonly_false
6767
def test_find_with_implicit_inner_joins_does_not_set_associations
6868
authors = Author.joins(:posts).select('authors.*')
6969
assert !authors.empty?, "expected authors to be non-empty"
70-
assert authors.all? {|a| !a.send(:instance_variable_names).include?("@posts")}, "expected no authors to have the @posts association loaded"
70+
assert authors.all? { |a| !a.instance_variable_defined?(:@posts) }, "expected no authors to have the @posts association loaded"
7171
end
7272

7373
def test_count_honors_implicit_inner_joins

0 commit comments

Comments
 (0)