1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use array subtraction to compute variables of interest in view_assigns

This commit is contained in:
Vinicius Stock 2020-03-19 15:59:46 -04:00
parent f6bf17058e
commit 9caaf26503
No known key found for this signature in database
GPG key ID: 1A3EC85374C0969A

View file

@ -56,19 +56,15 @@ module AbstractController
Mime[:text]
end
DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %i(
@_action_name @_response_body @_formats @_prefixes
)
DEFAULT_PROTECTED_INSTANCE_VARIABLES = %i(@_action_name @_response_body @_formats @_prefixes)
# This method should return a hash with assigns.
# You can overwrite this configuration per controller.
def view_assigns
protected_vars = _protected_ivars
variables = instance_variables - _protected_ivars
instance_variables.each_with_object({}) do |name, hash|
unless protected_vars.include?(name)
hash[name.slice(1, name.length)] = instance_variable_get(name)
end
variables.each_with_object({}) do |name, hash|
hash[name.slice(1, name.length)] = instance_variable_get(name)
end
end