From 64204f4a8b9b32b515070f90ccc6715675f068e2 Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Mon, 21 Jul 2025 13:54:22 -0400 Subject: [PATCH] Optimize method_missing via alias_method --- lib/jbuilder.rb | 10 ++-------- lib/jbuilder/jbuilder_template.rb | 2 ++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb index 0ed3cb1..024e418 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -70,14 +70,6 @@ def set!(key, value = BLANK, *args, &block) _set_value key, result end - def method_missing(*args, &block) - if ::Kernel.block_given? - set!(*args, &block) - else - set!(*args) - end - end - # Specifies formatting to be applied to the key. Passing in a name of a function # will cause that function to be called on the key. So :upcase will upper case # the key. You can also pass in lambdas for more complex transformations. @@ -283,6 +275,8 @@ def target! private + alias_method :method_missing, :set! + def _extract(object, attributes) if ::Hash === object _extract_hash_values(object, attributes) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index fed4c8e..b95e65f 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -139,6 +139,8 @@ def set!(name, object = BLANK, *args) private + alias_method :method_missing, :set! + def _render_partial_with_options(options) options.reverse_merge! locals: options.except(:partial, :as, :collection, :cached) options.reverse_merge! ::JbuilderTemplate.template_lookup_options