ArgumentError: wrong number of arguments (given 1, expected 2) Ruby / Rails Origin: Application & API OSI layer 7 · Application Last updated 5 Nov 2026

Ruby: ArgumentError: wrong number of arguments (given 1, expected 2..3)

A method was called with more or fewer arguments than it accepts.

Exact message you may see ArgumentError: wrong number of arguments (given 1, expected 2)wrong number of arguments (given 2, expected 1)ArgumentError (wrong number of arguments (given 1, expected 0))wrong number of arguments (given 1, expected 2..3)wrong number of arguments (given 0, expected 1+)
Seen on: Ruby

Meaning

Compare the call with the method signature. Ruby 3 separates positional and keyword arguments: passing a hash where keywords are expected (or the reverse) raises this. Check initialize signatures, blocks vs lambdas (lambdas are strict) and super calls (super vs super()).

Common causes

  • Wrong number of positional args
  • Ruby 3 keyword vs hash separation (foo(opts) vs foo(**opts))
  • Lambda/proc strictness
  • super passing implicit arguments
  • Method signature changed after a gem upgrade

⚡ Quick fix

  1. Fix the call to match def m(a, b = 1, *rest, key:)
  2. Use **opts when passing a hash as keywords
  3. Use super() to pass none

Detailed fix by platform

Ruby

  1. method(:foo).arity / method(:foo).parameters

How to diagnose

  1. Given — How many?
  2. Expected — Signature?
  3. Ruby 3 — Keyword hash?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

ArgumentError: missing keyword / unknown keyword — Ruby: ArgumentError: missing keyword: :name / unknown keyword: :nmae (Ruby / Rails)ArgumentError: missin…Bundler could not find compatible versions for gem — Bundler: Bundler could not find compatible versions for gem "activesupport": In Gemfile: rails (= 7.1.0) depends on activesupport (= 7.1.0) (Ruby / Rails)Bundler could not fin…Bundler: Could not find gem in locally installed gems — Bundler: Could not find gem 'rails (~> 7.1)' in locally installed gems / Could not find rails-7.1.0 in any of the gem sources listed in your Gemfile (Ruby / Rails)Bundler: Could not fi…FactoryBot::DuplicateDefinitionError: Factory already registered — FactoryBot: FactoryBot::DuplicateDefinitionError: Factory already registered: user (Ruby / Rails)FactoryBot::Duplicate…Failed to build gem native extension — Ruby: ERROR: Failed to build gem native extension. current directory: /gems/pg-1.5.4/ext/pg — An error occurred while installing pg (Ruby / Rails)Failed to build gem n…FrozenError: can't modify frozen String — Ruby: FrozenError: can't modify frozen String: "abc" (Ruby / Rails)FrozenError: can't mo…LoadError: cannot load such file — Ruby: LoadError: cannot load such file -- nokogiri (or: cannot load such file -- bundler/setup) (Ruby / Rails)LoadError: cannot loa…NameError: undefined local variable or method — Ruby: NameError: undefined local variable or method 'x' for main:Object (Ruby / Rails)NameError: undefined …ArgumentE…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.