mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
split DELEGATION_RESERVED_METHOD_NAMES in half
This commit is contained in:
parent
7407d35c54
commit
d9ff835b99
5 changed files with 17 additions and 10 deletions
|
@ -326,7 +326,7 @@ module ActionView
|
||||||
def locals_code #:nodoc:
|
def locals_code #:nodoc:
|
||||||
# Only locals with valid variable names get set directly. Others will
|
# Only locals with valid variable names get set directly. Others will
|
||||||
# still be available in local_assigns.
|
# still be available in local_assigns.
|
||||||
locals = @locals.to_set - Module::DELEGATION_RESERVED_METHOD_NAMES.dup.delete("block")
|
locals = @locals - Module::RUBY_RESERVED_KEYWORDS
|
||||||
locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
|
locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
|
||||||
|
|
||||||
# Double assign to suppress the dreaded 'assigned but unused variable' warning
|
# Double assign to suppress the dreaded 'assigned but unused variable' warning
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
<%= block %>
|
|
1
actionview/test/fixtures/test/test_template_with_delegation_reserved_keywords.erb
vendored
Normal file
1
actionview/test/fixtures/test/test_template_with_delegation_reserved_keywords.erb
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<%= _ %> <%= arg %> <%= args %> <%= block %>
|
|
@ -14,10 +14,6 @@ class CompiledTemplatesTest < ActiveSupport::TestCase
|
||||||
render(file: "test/render_file_with_ruby_keyword_locals", locals: { class: "foo" })
|
render(file: "test/render_file_with_ruby_keyword_locals", locals: { class: "foo" })
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_template_with_block_variable
|
|
||||||
assert_equal "foo", render(file: "test/test_template_with_block_variable", locals: { block: "foo" })
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_template_with_invalid_identifier_locals
|
def test_template_with_invalid_identifier_locals
|
||||||
locals = {
|
locals = {
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
|
@ -28,6 +24,16 @@ class CompiledTemplatesTest < ActiveSupport::TestCase
|
||||||
assert_equal locals.inspect, render(file: "test/render_file_inspect_local_assigns", locals: locals)
|
assert_equal locals.inspect, render(file: "test/render_file_inspect_local_assigns", locals: locals)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_template_with_delegation_reserved_keywords
|
||||||
|
locals = {
|
||||||
|
_: "one",
|
||||||
|
arg: "two",
|
||||||
|
args: "three",
|
||||||
|
block: "four",
|
||||||
|
}
|
||||||
|
assert_equal "one two three four", render(file: "test/test_template_with_delegation_reserved_keywords", locals: locals)
|
||||||
|
end
|
||||||
|
|
||||||
def test_template_with_unicode_identifier
|
def test_template_with_unicode_identifier
|
||||||
assert_equal "🎂", render(file: "test/render_file_unicode_local", locals: { 🎃: "🎂" })
|
assert_equal "🎂", render(file: "test/render_file_unicode_local", locals: { 🎃: "🎂" })
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,11 +6,12 @@ class Module
|
||||||
# option is not used.
|
# option is not used.
|
||||||
class DelegationError < NoMethodError; end
|
class DelegationError < NoMethodError; end
|
||||||
|
|
||||||
|
RUBY_RESERVED_KEYWORDS = %w(alias and BEGIN begin break case class def defined? do
|
||||||
|
else elsif END end ensure false for if in module next nil not or redo rescue retry
|
||||||
|
return self super then true undef unless until when while yield)
|
||||||
|
DELEGATION_RESERVED_KEYWORDS = %w(_ arg args block)
|
||||||
DELEGATION_RESERVED_METHOD_NAMES = Set.new(
|
DELEGATION_RESERVED_METHOD_NAMES = Set.new(
|
||||||
%w(_ arg args alias and BEGIN begin block break case class def defined? do
|
RUBY_RESERVED_KEYWORDS + DELEGATION_RESERVED_KEYWORDS
|
||||||
else elsif END end ensure false for if in module next nil not or redo
|
|
||||||
rescue retry return self super then true undef unless until when while
|
|
||||||
yield)
|
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
# Provides a +delegate+ class method to easily expose contained objects'
|
# Provides a +delegate+ class method to easily expose contained objects'
|
||||||
|
|
Loading…
Reference in a new issue