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

Use keyword arguments instead of last parameter Hash

this would eliminate warnings when calling keyworded method,
and this still works with methods taking last parameter Hash
This commit is contained in:
Akira Matsuda 2019-09-13 19:19:22 +09:00
parent 154b7ffd97
commit cd31e113c0

View file

@ -14,16 +14,21 @@ module ActiveSupport
private private
def method_missing(method, *arguments, &block) def method_missing(method, *arguments, &block)
options = nil
if arguments.first.is_a?(Proc) if arguments.first.is_a?(Proc)
proc = arguments.pop proc = arguments.pop
arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) } arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
elsif arguments.last.respond_to?(:to_hash) elsif arguments.last.respond_to?(:to_hash)
arguments << @options.deep_merge(arguments.pop) options = @options.deep_merge(arguments.pop)
else else
arguments << @options.dup options = @options.dup
end end
@context.__send__(method, *arguments, &block) if options
@context.__send__(method, *arguments, **options, &block)
else
@context.__send__(method, *arguments, &block)
end
end end
end end
end end