Gem install wrong number of arguments (given 1, expected 0)
This was happening on my system, so I dug into it for a while. It appears to be an incompatibility between Ruby 2.5 and RubyGems < 2.6.10.
Short answer
If you want to install Ruby 2.5, make sure you have RubyGems >= 2.6.10. You may be able to explicitly specify which version of RubyGems to use (for example, I called rvm rubygems 2.7.7
) or it may work to just update to a newer version of RVM/rbenv/etc.
Longer explanation
As shown in the backtrace in the question, the error occurs when calling require
. This is a version of require
that RubyGems has written to replace the definition that comes with Ruby. In RubyGems before 2.6.10, this part of the code looks something like:
spec = Gem.find_unresolved_default_spec(path)
if spec
Gem.remove_unresolved_default_spec(spec)
gem(spec.name)
end
(source)
The error occurs when calling gem(spec.name)
, but why?
It ends up having to do with a quirk of Ruby. Even though require
seems kind of like a built-in keyword, it's actually a method in the Kernel
module. That module is included in Object
, so the method can be called from any object that descends from Object
(including the "main" object at the top level of a script/console). But in the end it's still a method on whatever object you call it from, so any method calls within require
that don't have an explicit receiver are called on that same object.
Normal inheritance rules apply, so if your object doesn't have an explicit gem
method, the one defined in Kernel
by RubyGems will be called, which is great. But if your object does have its own gem
method, that'll be called instead, which is unlikely to work. In this case, require 'fileutils'
is called from within the initializer for Gem::Installer
(https://github.com/rubygems/rubygems/blob/v2.6.9/lib/rubygems/installer.rb#L162). The Gem::Installer
class has its own gem
method with zero parameters, created by attr_reader :gem
. The require
code tries to call it with one parameter, and there we have our error.
(This issue was resolved in RubyGems 2.6.10 by changing the gem
call to Kernel.send(:gem, spec.name)
in https://github.com/rubygems/rubygems/pull/1822. This was prompted by somewhat similar difficulties in the Bundler library, which also had an object defining its own gem
method.)
The last question is why this occurred in Ruby 2.5 but not before. It turns out that this particular call to gem
only occurs when trying to require a "default" gem. In versions of Ruby before 2.5, "fileutils" has not been a default gem, so those versions have managed to avoid this particular issue, even with older versions of RubyGems. It's only with Ruby 2.5 making "fileutils" a default gem that this odd issue has cropped up.
Capistrano deployment throws psych error: wrong number of arguments (given 4, expected 1) :`safe_load'
Solution:
I looked for the Gem that is adding Psych Gem (it is not listed in Gemfile directly). Then I restricted that parent Gem's version to previous version that does not download Psych.
Then I ran gem uninstall psych
on the server where I was deploying the code. Removed all versions of Psych from that server.
Then the deployment worked fine.
Jekyll installation, wrong number of arguments
I guess the ruby version was the problem. Once I installed ruby 2.4 using https://rvm.io/ installation was successful
bundle exec jekyll build: wrong number of arguments (given 2, expected 1) (ArgumentError)
Ruby 3 breaks a few number of gems with this error message because of the separation of positional and keyword arguments in Ruby 3. See this for more info: Separation of positional and keyword arguments in Ruby 3.0
I was able to reproduce your exact problem. In your case it's jekyll-assets 3.0.12 which requires liquid-tag-parser 1.9.0 that creates the second error message. Unfortunately upgrading to Jekyll 4 will not solve this problem.
I found two solutions:
1. Downgrade to Ruby 2.7
This is by far the easiest way to fix this problem.
2. Use jekyll-assets from Github
Proceed at your own risk!
First you will need to use Jekyll 3.9.2 because of another problem between Ruby 3.X and the pathutil gem which is required by Jekyll 3.8.6. Jekyll 3.9.2 drops the dependency on pathutil. Change these lines in your Gemfile:
gem "jekyll", "~>3.9"
gem "sprockets"
You will also need to pull the latest code for jekyll-assets from Github. While looking at this problem, I found further issues with the wrong number of arguments in a few function calls in jekyll-assets. I submitted a pull request to fix those. Modify this line in your Gemfile to use this pull request as source for the gem:
gem "jekyll-assets", git: "https://github.com/envygeeks/jekyll-assets", ref: "refs/pull/666/head"
By doing this, I was able to install the gems and run Jekyll successfully with jekyll-assets. You may also want to consider using another plugin as jekyll-assets hasn't been updated in a few years.
ArgumentError (wrong number of arguments (given 2, expected 1)) after updating to Ruby 3.0
The issue has to do with how keyword arguments are handled in ruby 3.0 and how ice_cube
is passing its arguments to I18n.localize
.
So, extracting and simplifying the buggy code, this worked on ruby < 3
RUBY_VERSION # "2.7.2"
def foo(*args)
bar(*args)
end
def bar(object, locale: nil, format: nil, **options)
puts "object:#{object}"
puts "locale:#{locale}"
puts "format:#{format}"
puts "options:#{options}"
end
foo('date', format: 'whatever')
# object:date
# locale:
# format:whatever
# options:{}
And from ruby >= 3
RUBY_VERSION # "3.0.0"
def foo(*args)
bar(*args)
end
def bar(object, locale: nil, format: nil, **options)
puts "object:#{object}"
puts "locale:#{locale}"
puts "format:#{format}"
puts "options:#{options}"
end
foo('date', format: 'whatever')
# Traceback (most recent call last):
# 16: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli.rb:24:in `start'
# 15: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
# 14: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli.rb:30:in `dispatch'
# 13: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
# 12: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
# 11: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
# 10: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli.rb:497:in `exec'
# 9: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:28:in `run'
# 8: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `kernel_load'
# 7: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `load'
# 6: from /Users/alter/.rbenv/versions/3.0.0/bin/irb:23:in `<top (required)>'
# 5: from /Users/alter/.rbenv/versions/3.0.0/bin/irb:23:in `load'
# 4: from /Users/alter/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/irb-1.3.0/exe/irb:11:in `<top (required)>'
# 3: from (irb):11:in `<main>'
# 2: from (irb):3:in `foo'
# 1: from (irb):5:in `bar'
# ArgumentError (wrong number of arguments (given 2, expected 1))
So, the fix I can see is to explicitely passing the parameters to the method:
def foo2(object, **options)
bar(object, **options)
end
foo2('date', format: 'whatever')
# object:date
# locale:
# format:whatever
# options:{}
Or in terms of the involved module:
module IceCube
module I18n
def self.l(object, **options)
backend.l(object, **options)
end
end
end
and send a PR, use your own fork, monkey-patch, whatever works best for you.
But most important, brace yourself to find this issue in a lot of other gems, as the first stable ruby 3 version was just released 2 days ago, so probably you'll have these type of issues with other gems, specially the unmaintained ones.
Good luck.
Update
Looking your PR I didn't remember part of the code that you modified it, then I realized I was focused on 0.16.3
version, which it was the one you mentioned in the question. Things are, master
branch has a lot more changes than the last 0.16.3
version, specially this change where is delegating the locale/translate methods to the backend that, at the end of the day, is a better solution than mine, and it should fix your issue.
So, in your Gemfile
gem 'ice_cube', git: 'https://github.com/seejohnrun/ice_cube.git', branch: :master
should do the trick. Anyway I'll left my previous response as reference for anyone having the issue in general terms and not specifically with ice_cube
.
ArgumentError: Wrong Number of Arguments Errors when upgrading Rails 6.1.3
web-console
gem was breaking with Rails 6.1, an upgrade to 4.1.0 fixed the error.
Related Topics
Ruby on Rails: Create Confirmation View Before Creating the Object
Uri::Invalidurierror: Bad Uri(Is Not Uri) Testing Rails Controllers
How to HTML_Escape Text Data in a Sinatra App
Official Expansion of ||= Conditional Assignment Operator
Determining Method's Visibility on the Fly
Rails Syntax Error: Unexpected Keyword_Ensure, Expecting Keyword_End
Uri::Invalidurierror (Uri Must Be Ascii Only)
Grouping an Array by Comparing 2 Adjacent Elements
Can Nokogiri Use Single Quotes for Attributes on Saving Xml
Getting a Rogue Iteration from My .Each Loop
Restart Rails Server Automatically After Every Change in Controllers
Problems with Jslint-V8 Ruby Gem Installation on Windows7 64-Bit
Twitter::Error::Unauthorized in Postscontroller#Create - Invalid or Expired Token
Update Field Through Link_To in Rails
Import CSV in Batches of Lines in Rails
Undefined Method 'Email' for Nil:Nilclass in Exibe the Mail of Table Father