Skip to content

Fix the JSON::Coder.new call-seq - #1074

Merged
byroot merged 1 commit into
ruby:masterfrom
dduugg:coder-call-seq
Sep 9, 2026
Merged

Fix the JSON::Coder.new call-seq#1074
byroot merged 1 commit into
ruby:masterfrom
dduugg:coder-call-seq

Conversation

@dduugg

@dduugg dduugg commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

The JSON::Coder#initialize call-seq is inaccurate in two ways:

# :call-seq:
#   JSON.new(options = nil, &block)

JSON is a module and has no .new, so the name should be JSON::Coder.new. More substantively, the positional options = nil has not been accurate since 3.0.0 (28a2b0b), which changed the signature to initialize(object_class: nil, array_class: nil, on_load: nil, **options, &as_json). Passing options positionally now raises:

$ ruby -rjson -e 'JSON::Coder.new({ symbolize_names: true })'
-e:1:in 'JSON::Coder#initialize': wrong number of arguments (given 1, expected 0) (ArgumentError)

whereas it worked on 2.x, so the documented form is the one that no longer works. The prose immediately below ("Argument options, if given, contains a Hash of options") has the same problem, so this updates it to describe keyword arguments.

This survived the 3.0 docs pass in 8bdd517, and it is currently what https://docs.ruby-lang.org/en/master/JSON/Coder.html renders. It misled me while migrating Homebrew off json/add/exception, which is the migration CHANGES.md recommends JSON::Coder for, so it seems worth correcting now that more people will be reading this method.

Documentation only, no behaviour change.

`JSON` has no `.new`, and options have been keyword arguments since 3.0,
so passing a positional Hash raises ArgumentError.
@byroot
byroot merged commit effca27 into ruby:master Sep 9, 2026
42 checks passed
@dduugg
dduugg deleted the coder-call-seq branch September 9, 2026 14:08
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

Successfully merging this pull request may close these issues.

2 participants