Skip to content

Commit

Permalink
Fix handling for blocks with arity > 1 where expected arity is 1
Browse files Browse the repository at this point in the history
Looks like this was broken in Roda 3.18.0.
  • Loading branch information
jeremyevans committed Apr 7, 2019
1 parent 8588ec2 commit 3fdf0f0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
= master

* Fix handling for blocks with arity > 1 where expected arity is 1 (jeremyevans)

* Improve performance for handling blocks with arity 0 where expected arity is 1 by avoiding instance_exec (jeremyevans)

* Improve terminal maching by around 4x (jeremyevans)
Expand Down
3 changes: 3 additions & 0 deletions lib/roda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ def define_roda_method(meth, expected_arity, &block)
undef_method temp_method
private meth
meth = :"#{meth}_arity"
elsif required_args > 1
b = block
block = lambda{|r| instance_exec(r, &b)} # Fallback
end
when :any
if check_dynamic_arity = opts.fetch(:check_dynamic_arity, check_arity)
Expand Down
3 changes: 3 additions & 0 deletions spec/define_roda_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@

m1 = app.define_roda_method("x", 1){2}
@scope.send(m1, 3).must_equal 2

m1 = app.define_roda_method("x", 1){|x, y| [x, y]}
@scope.send(m1, 4).must_equal [4, nil]
end

it "should raise for unexpected expected_arity" do
Expand Down

0 comments on commit 3fdf0f0

Please sign in to comment.