ruby-concurrency/concurrent-ruby · error · ArgumentError
wrong number of arguments (0 for 1+)
Error message
wrong number of arguments (0 for 1+)
What it means
SettableStruct.new is the class factory that defines a new struct class, not an instance constructor: it requires at least one argument (a member list, optionally preceded by a String class name). Calling it with zero arguments raises ArgumentError('wrong number of arguments (0 for 1+)'). Instances are created afterwards by calling new (or []) on the generated class, where values are optional.
Source
Thrown at lib/concurrent-ruby/concurrent/settable_struct.rb:108
rescue NoMethodError
raise NameError.new("no member '#{member}' in struct")
end
private
# @!visibility private
def initialize_copy(original)
synchronize do
super(original)
ns_initialize_copy
end
end
# @!macro struct_new
def self.new(*args, &block)
clazz_name = nil
if args.length == 0
raise ArgumentError.new('wrong number of arguments (0 for 1+)')
elsif args.length > 0 && args.first.is_a?(String)
clazz_name = args.shift
end
FACTORY.define_struct(clazz_name, args, &block)
end
FACTORY = Class.new(Synchronization::LockableObject) do
def define_struct(name, members, &block)
synchronize do
clazz = Synchronization::AbstractStruct.define_struct_class(SettableStruct, Synchronization::LockableObject, name, members, &block)
members.each_with_index do |member, index|
clazz.send :remove_method, member if clazz.instance_methods.include? member
clazz.send(:define_method, member) do
synchronize { @values[index] }
end
clazz.send(:define_method, "#{member}=") do |value|
synchronize do
unless @values[index].nil?View on GitHub (pinned to 0b88d5ff75)
Solutions
- Define the class with members: Point = Concurrent::SettableStruct.new(:x, :y)
- Instantiate via the generated class: Point.new(1, 2) — values may be omitted there
- If you only need a mutable record with no fixed schema, use a Hash or Struct from core Ruby instead
Example fix
# before Struct = Concurrent::SettableStruct.new # ArgumentError # after Point = Concurrent::SettableStruct.new(:x, :y) pt = Point.new # instance constructor; values optional
Defensive patterns
Strategy: validation
Validate before calling
raise ArgumentError, 'at least one member required' if members.empty? Klass = Concurrent::SettableStruct.new(*members)
Prevention
- Remember SettableStruct.new defines a class; instantiation happens on the generated class
- Pass at least one member symbol when defining
- For zero-field records, prefer a plain object or Hash
When it happens
Trigger: Concurrent::SettableStruct.new with no args; intending to instantiate an already-defined struct class but calling the factory by mistake (MyStruct is right, SettableStruct.new is wrong); copy-paste that drops the member symbols.
Common situations: Confusion between the definition step and the instantiation step, which differs from core Struct's ergonomics; scaffolding code generated without a member list.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- offset #{member} too large for struct(size:#{length})
- no member '#{member}' in struct
- struct size differs
- no block given
- Not all dependencies are IVars. Dependencies: #{ inputs.insp
AI-assisted analysis of ruby-concurrency/concurrent-ruby@0b88d5ff75 (2026-08-21).
Data as JSON: /api/errors/3e7dba6b5ac876a6.
Report an issue: GitHub.