Skip to content

Commit 2e244c4

Browse files
authored
Merge pull request #600 from affinity/moberegger/method_missing
Optimize `method_missing` via `alias_method`
2 parents 9013595 + 64204f4 commit 2e244c4

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

lib/jbuilder.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ def set!(key, value = BLANK, *args, &block)
7070
_set_value key, result
7171
end
7272

73-
def method_missing(*args, &block)
74-
if ::Kernel.block_given?
75-
set!(*args, &block)
76-
else
77-
set!(*args)
78-
end
79-
end
80-
8173
# Specifies formatting to be applied to the key. Passing in a name of a function
8274
# will cause that function to be called on the key. So :upcase will upper case
8375
# the key. You can also pass in lambdas for more complex transformations.
@@ -283,6 +275,8 @@ def target!
283275

284276
private
285277

278+
alias_method :method_missing, :set!
279+
286280
def _extract(object, attributes)
287281
if ::Hash === object
288282
_extract_hash_values(object, attributes)

lib/jbuilder/jbuilder_template.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def set!(name, object = BLANK, *args)
139139

140140
private
141141

142+
alias_method :method_missing, :set!
143+
142144
def _render_partial_with_options(options)
143145
options.reverse_merge! locals: options.except(:partial, :as, :collection, :cached)
144146
options.reverse_merge! ::JbuilderTemplate.template_lookup_options

0 commit comments

Comments
 (0)