Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"wrong number of arguments (2 for 0)" error when running on Ruby 1.9 #8

Open
TylerRick opened this issue Mar 4, 2010 · 2 comments
Open

Comments

@TylerRick
Copy link

When I go to http://localhost:3002/, I get this error:

wrong number of arguments (2 for 0)

vendor/plugins/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb:7:in `around_recognize'
vendor/plugins/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/base.rb:15:in `run'
vendor/plugins/adva_cms/vendor/plugins/routing-filter/lib/routing_filter.rb:12:in `run'
vendor/plugins/adva_cms/vendor/plugins/routing-filter/lib/routing_filter.rb:57:in `recognize_path_with_filtering'
/var/lib/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:441:in `recognize'
/var/lib/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:436:in `call'

I don't get that error when I change script/server to use ruby1.8:

-#!/usr/bin/env ruby
+#!/usr/bin/env ruby1.8

(But that is not an option for me.)

@TylerRick
Copy link
Author

It looks like the problem is that the lambda in vendor/plugins/routing-filter/lib/routing_filter/base.rb is not defined with any parameters but it is called with 2.

Unlike Ruby 1.8, 1.9 actually enforces the arity of procs created with lambda:

RUBY_VERSION = 1.9.1
 > proc = lambda {}; proc.call(1,2)
ArgumentError: wrong number of arguments (2 for 0)
    from (irb):2:in `call'

RUBY_VERSION = 1.8.7
 > proc = lambda {}; proc.call(1,2)
=> nil

Changing it to a proc fixed it for me:

diff --git a/engines/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/base.rb b/engines/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/base.rb
index 73964ad..c8d2c80 100644
--- a/engines/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/base.rb
+++ b/engines/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/base.rb
@@ -11,8 +11,8 @@ module RoutingFilter
     end
 
     def run(method, *args, &block)
-      successor = @successor ? lambda { @successor.run(method, *args, &block) } : block
+      successor = @successor ? proc {|path, env| @successor.run(method, *args, &block) } : block
       active ? send(method, *args, &successor) : successor.call(*args)
     end
   end
-end
\ No newline at end of file
+end

(procs created with Kernel#proc aren't subject to the arity check that those created with Kernel#lambda are. And if we simply add the 2 parameters, I got this opposite error instead: wrong number of arguments (0 for 2))

@TylerRick
Copy link
Author

I've fixed this and to other Ruby 1.9 issues in my fork. Please pull from git://github.com/TylerRick/adva_cms.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant