Project

General

Profile

Bug #14160

JSON#generate documentation wrong/misleading

Added by StefanPochmann (Stefan Pochmann) almost 2 years ago. Updated about 2 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:84128]

Description

https://docs.ruby-lang.org/en/trunk/JSON.html#module-JSON-label-Generating+JSON
That says JSON.generate only allows "objects or arrays", that to_json allows more, and uses 1.to_json as an example for that. But I just tried JSON.generate(1) and it works as well. What's up with that?

https://docs.ruby-lang.org/en/trunk/JSON.html#method-i-generate
That talks about state a lot. I think it should say opts, as that is the argument name, no? Also, it says "state is * a JSON::State object". Note the "*". I think this should be a bullet point, i.e., "a JSON::State object" should be an item in the list following it.

Associated revisions

Revision b5e0ca47
Added by sorah (Sorah Fukumori) almost 2 years ago

Log exception with bold and underline for TTYs

Print error message in bold/underlined text if STDERR is unchanged and a tty.
[Feature #14160] [experimental]

Screenshot: https://img.sorah.jp/s/2017-11-29_1711_xj2fu.png

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 60935
Added by sorah (Sorah Fukumori) almost 2 years ago

Log exception with bold and underline for TTYs

Print error message in bold/underlined text if STDERR is unchanged and a tty.
[Feature #14160] [experimental]

Screenshot: https://img.sorah.jp/s/2017-11-29_1711_xj2fu.png

Revision 60935
Added by sorah (Sorah Fukumori) almost 2 years ago

Log exception with bold and underline for TTYs

Print error message in bold/underlined text if STDERR is unchanged and a tty.
[Feature #14160] [experimental]

Screenshot: https://img.sorah.jp/s/2017-11-29_1711_xj2fu.png

History

Updated by shevegen (Robert A. Heiler) almost 2 years ago

You are right, the statement in the documentation that .generate() only allows "objects
or arrays" is technically not logical. Firstly, in ruby everything is an object, or
at the least, when we include Integers and Symbols, object-like in their behaviour (they
have the same object_id all the time of course, unlike e. g. String objects). So when
the documenation mentions "objects or arrays", this is not logical because arrays are
objects too; and even more importantly, the documentation claims that 1 is not valid
but it becomes a String object, so the documented behaviour is not the real behaviour.

I would suggest to change the wording, to also expand it with more examples, not just
via "1" alone, and to clear up the comment about JSON.generate().

Updated by jeremyevans0 (Jeremy Evans) about 2 months ago

I added a pull request to fix the first issue: https://github.com/flori/json/pull/384

There is an existing pull request to fix the second issue: https://github.com/flori/json/pull/347

Also available in: Atom PDF