Skip to content

Commit

Permalink
Fix ArgumentError when block given with keyword arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoshidajp committed Jul 21, 2022
1 parent 63e40e6 commit 20a56bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rabl/engine.rb
Expand Up @@ -356,8 +356,8 @@ def respond_to?(name, include_private = false)
end

# Supports calling helpers defined for the template context_scope using method_missing hook
def method_missing(name, *args, &block)
context_scope.respond_to?(name, true) ? context_scope.__send__(name, *args, &block) : super
def method_missing(name, *args, **kwargs, &block)
context_scope.respond_to?(name, true) ? context_scope.__send__(name, *args, **kwargs, &block) : super
end

def copy_instance_variables_from(object, exclude = []) #:nodoc:
Expand Down
9 changes: 9 additions & 0 deletions test/engine_test.rb
Expand Up @@ -27,6 +27,15 @@
denies("that it raises exception when given frozen locals").raises(RuntimeError) do
Rabl::Engine.new("").apply(Object.new, {}.freeze)
end

asserts "that it can call method in block with positional and keyword arguments" do
template = RablTemplate.new("code") { 'node(:foo) { func("bar", kw: "baz") }' }
obj = Object.new
def obj.func(arg, kw:)
"#{arg}-#{kw}"
end
template.render(obj)
end.equals "{\"foo\":\"bar-baz\"}"
end

context "#request_format" do
Expand Down

0 comments on commit 20a56bc

Please sign in to comment.