rbs 3.3.2 → 3.4.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +2 -5
- data/.github/workflows/ruby.yml +7 -8
- data/.github/workflows/typecheck.yml +37 -0
- data/CHANGELOG.md +50 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +11 -11
- data/Steepfile +2 -2
- data/core/array.rbs +19 -49
- data/core/basic_object.rbs +2 -2
- data/core/comparable.rbs +17 -8
- data/core/complex.rbs +82 -43
- data/core/data.rbs +2 -4
- data/core/dir.rbs +635 -295
- data/core/enumerable.rbs +11 -18
- data/core/enumerator.rbs +37 -31
- data/core/errors.rbs +4 -0
- data/core/false_class.rbs +34 -15
- data/core/fiber.rbs +23 -0
- data/core/file.rbs +329 -120
- data/core/float.rbs +17 -32
- data/core/gc.rbs +17 -11
- data/core/hash.rbs +22 -44
- data/core/integer.rbs +82 -113
- data/core/io/buffer.rbs +90 -47
- data/core/io.rbs +39 -116
- data/core/kernel.rbs +442 -489
- data/core/match_data.rbs +55 -56
- data/core/module.rbs +45 -1
- data/core/nil_class.rbs +98 -35
- data/core/numeric.rbs +22 -32
- data/core/object_space/weak_key_map.rbs +102 -0
- data/core/process.rbs +1242 -655
- data/core/ractor.rbs +139 -120
- data/core/range.rbs +100 -4
- data/core/rational.rbs +0 -4
- data/core/rbs/unnamed/argf.rbs +16 -8
- data/core/rbs/unnamed/env_class.rbs +0 -24
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +1149 -598
- data/core/ruby_vm.rbs +126 -12
- data/core/rubygems/platform.rbs +9 -0
- data/core/rubygems/rubygems.rbs +1 -1
- data/core/rubygems/version.rbs +5 -1
- data/core/set.rbs +20 -22
- data/core/signal.rbs +4 -4
- data/core/string.rbs +283 -230
- data/core/string_io.rbs +2 -14
- data/core/struct.rbs +404 -24
- data/core/symbol.rbs +1 -19
- data/core/thread.rbs +29 -12
- data/core/time.rbs +227 -104
- data/core/trace_point.rbs +2 -5
- data/core/true_class.rbs +54 -21
- data/core/warning.rbs +14 -11
- data/docs/data_and_struct.md +29 -0
- data/docs/syntax.md +3 -5
- data/docs/tools.md +1 -0
- data/ext/rbs_extension/lexer.c +643 -559
- data/ext/rbs_extension/lexer.re +5 -1
- data/ext/rbs_extension/parser.c +12 -3
- data/ext/rbs_extension/unescape.c +7 -47
- data/lib/rbs/cli/diff.rb +4 -1
- data/lib/rbs/cli/validate.rb +280 -0
- data/lib/rbs/cli.rb +2 -194
- data/lib/rbs/collection/config.rb +5 -6
- data/lib/rbs/collection/sources/git.rb +1 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/diff.rb +7 -4
- data/lib/rbs/errors.rb +11 -0
- data/lib/rbs/test/errors.rb +4 -1
- data/lib/rbs/test/guaranteed.rb +2 -3
- data/lib/rbs/test/type_check.rb +15 -10
- data/lib/rbs/test.rb +3 -3
- data/lib/rbs/types.rb +29 -0
- data/lib/rbs/unit_test/convertibles.rb +176 -0
- data/lib/rbs/unit_test/spy.rb +136 -0
- data/lib/rbs/unit_test/type_assertions.rb +341 -0
- data/lib/rbs/unit_test/with_aliases.rb +143 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/version.rb +1 -1
- data/sig/cli/validate.rbs +43 -0
- data/sig/diff.rbs +3 -1
- data/sig/errors.rbs +8 -0
- data/sig/rbs.rbs +1 -1
- data/sig/test/errors.rbs +52 -0
- data/sig/test/guranteed.rbs +9 -0
- data/sig/test/type_check.rbs +19 -0
- data/sig/test.rbs +82 -0
- data/sig/types.rbs +6 -1
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +28 -0
- data/sig/unit_test/type_assertions.rbs +194 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/stdlib/base64/0/base64.rbs +307 -45
- data/stdlib/bigdecimal/0/big_decimal.rbs +35 -15
- data/stdlib/coverage/0/coverage.rbs +2 -2
- data/stdlib/csv/0/csv.rbs +25 -55
- data/stdlib/date/0/date.rbs +1 -43
- data/stdlib/date/0/date_time.rbs +1 -13
- data/stdlib/delegate/0/delegator.rbs +186 -0
- data/stdlib/delegate/0/kernel.rbs +47 -0
- data/stdlib/delegate/0/simple_delegator.rbs +98 -0
- data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -1
- data/stdlib/erb/0/erb.rbs +2 -2
- data/stdlib/fileutils/0/fileutils.rbs +0 -19
- data/stdlib/io-console/0/io-console.rbs +12 -1
- data/stdlib/ipaddr/0/ipaddr.rbs +2 -1
- data/stdlib/json/0/json.rbs +320 -81
- data/stdlib/logger/0/logger.rbs +9 -5
- data/stdlib/monitor/0/monitor.rbs +78 -0
- data/stdlib/net-http/0/net-http.rbs +1880 -543
- data/stdlib/objspace/0/objspace.rbs +19 -13
- data/stdlib/openssl/0/openssl.rbs +508 -127
- data/stdlib/optparse/0/optparse.rbs +25 -11
- data/stdlib/pathname/0/pathname.rbs +1 -1
- data/stdlib/pp/0/pp.rbs +2 -5
- data/stdlib/prettyprint/0/prettyprint.rbs +2 -2
- data/stdlib/pstore/0/pstore.rbs +2 -4
- data/stdlib/rdoc/0/comment.rbs +1 -2
- data/stdlib/resolv/0/resolv.rbs +4 -2
- data/stdlib/socket/0/socket.rbs +2 -2
- data/stdlib/socket/0/unix_socket.rbs +2 -2
- data/stdlib/strscan/0/string_scanner.rbs +3 -2
- data/stdlib/tempfile/0/tempfile.rbs +1 -1
- data/stdlib/uri/0/common.rbs +245 -123
- metadata +23 -4
- data/lib/rbs/test/spy.rb +0 -6
data/stdlib/json/0/json.rbs
CHANGED
@@ -385,6 +385,15 @@ type json_state = singleton(JSON::Ext::Generator::State) | singleton(JSON::Pure:
|
|
385
385
|
# # Raises JSON::NestingError (nesting of 2 is too deep):
|
386
386
|
# JSON.generate(obj, max_nesting: 2)
|
387
387
|
#
|
388
|
+
# ###### Escaping Options
|
389
|
+
#
|
390
|
+
# Options `script_safe` (boolean) specifies wether `'\u2028'`, `'\u2029'` and
|
391
|
+
# `'/'` should be escaped as to make the JSON object safe to interpolate in
|
392
|
+
# script tags.
|
393
|
+
#
|
394
|
+
# Options `ascii_only` (boolean) specifies wether all characters outside the
|
395
|
+
# ASCII range should be escaped.
|
396
|
+
#
|
388
397
|
# ###### Output Options
|
389
398
|
#
|
390
399
|
# The default formatting options generate the most compact JSON data, all on one
|
@@ -747,14 +756,14 @@ module JSON
|
|
747
756
|
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
748
757
|
# Sets or returns the default options for the JSON.dump method. Initially:
|
749
758
|
# opts = JSON.dump_default_options
|
750
|
-
# opts # => {:max_nesting=>false, :allow_nan=>true, :
|
759
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true, :script_safe=>false}
|
751
760
|
#
|
752
761
|
def self.dump_default_options: () -> json_options
|
753
762
|
|
754
763
|
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
755
764
|
# Sets or returns the default options for the JSON.dump method. Initially:
|
756
765
|
# opts = JSON.dump_default_options
|
757
|
-
# opts # => {:max_nesting=>false, :allow_nan=>true, :
|
766
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true, :script_safe=>false}
|
758
767
|
#
|
759
768
|
def self.dump_default_options=: (json_options) -> json_options
|
760
769
|
|
@@ -1280,9 +1289,7 @@ class BigDecimal
|
|
1280
1289
|
# rdoc-file=ext/json/lib/json/add/bigdecimal.rb
|
1281
1290
|
# - json_create(object)
|
1282
1291
|
# -->
|
1283
|
-
#
|
1284
|
-
#
|
1285
|
-
# method used for JSON marshalling support.
|
1292
|
+
# See #as_json.
|
1286
1293
|
#
|
1287
1294
|
def self.json_create: (Hash[String, String] object) -> instance
|
1288
1295
|
|
@@ -1290,9 +1297,23 @@ class BigDecimal
|
|
1290
1297
|
# rdoc-file=ext/json/lib/json/add/bigdecimal.rb
|
1291
1298
|
# - as_json(*)
|
1292
1299
|
# -->
|
1293
|
-
#
|
1300
|
+
# Methods `BigDecimal#as_json` and `BigDecimal.json_create` may be used to
|
1301
|
+
# serialize and deserialize a BigDecimal object; see
|
1302
|
+
# [Marshal](rdoc-ref:Marshal).
|
1303
|
+
#
|
1304
|
+
# Method `BigDecimal#as_json` serializes `self`, returning a 2-element hash
|
1305
|
+
# representing `self`:
|
1306
|
+
#
|
1307
|
+
# require 'json/add/bigdecimal'
|
1308
|
+
# x = BigDecimal(2).as_json # => {"json_class"=>"BigDecimal", "b"=>"27:0.2e1"}
|
1309
|
+
# y = BigDecimal(2.0, 4).as_json # => {"json_class"=>"BigDecimal", "b"=>"36:0.2e1"}
|
1310
|
+
# z = BigDecimal(Complex(2, 0)).as_json # => {"json_class"=>"BigDecimal", "b"=>"27:0.2e1"}
|
1311
|
+
#
|
1312
|
+
# Method `JSON.create` deserializes such a hash, returning a BigDecimal object:
|
1294
1313
|
#
|
1295
|
-
#
|
1314
|
+
# BigDecimal.json_create(x) # => 0.2e1
|
1315
|
+
# BigDecimal.json_create(y) # => 0.2e1
|
1316
|
+
# BigDecimal.json_create(z) # => 0.2e1
|
1296
1317
|
#
|
1297
1318
|
def as_json: (*untyped) -> Hash[String, String]
|
1298
1319
|
|
@@ -1300,7 +1321,18 @@ class BigDecimal
|
|
1300
1321
|
# rdoc-file=ext/json/lib/json/add/bigdecimal.rb
|
1301
1322
|
# - to_json(*args)
|
1302
1323
|
# -->
|
1303
|
-
#
|
1324
|
+
# Returns a JSON string representing `self`:
|
1325
|
+
#
|
1326
|
+
# require 'json/add/bigdecimal'
|
1327
|
+
# puts BigDecimal(2).to_json
|
1328
|
+
# puts BigDecimal(2.0, 4).to_json
|
1329
|
+
# puts BigDecimal(Complex(2, 0)).to_json
|
1330
|
+
#
|
1331
|
+
# Output:
|
1332
|
+
#
|
1333
|
+
# {"json_class":"BigDecimal","b":"27:0.2e1"}
|
1334
|
+
# {"json_class":"BigDecimal","b":"36:0.2e1"}
|
1335
|
+
# {"json_class":"BigDecimal","b":"27:0.2e1"}
|
1304
1336
|
#
|
1305
1337
|
def to_json: (?JSON::State state) -> String
|
1306
1338
|
end
|
@@ -1311,8 +1343,7 @@ class Complex
|
|
1311
1343
|
# rdoc-file=ext/json/lib/json/add/complex.rb
|
1312
1344
|
# - json_create(object)
|
1313
1345
|
# -->
|
1314
|
-
#
|
1315
|
-
# a Complex object.
|
1346
|
+
# See #as_json.
|
1316
1347
|
#
|
1317
1348
|
def self.json_create: (Hash[String, String | Numeric] object) -> instance
|
1318
1349
|
|
@@ -1320,8 +1351,20 @@ class Complex
|
|
1320
1351
|
# rdoc-file=ext/json/lib/json/add/complex.rb
|
1321
1352
|
# - as_json(*)
|
1322
1353
|
# -->
|
1323
|
-
#
|
1324
|
-
# object.
|
1354
|
+
# Methods `Complex#as_json` and `Complex.json_create` may be used to serialize
|
1355
|
+
# and deserialize a Complex object; see [Marshal](rdoc-ref:Marshal).
|
1356
|
+
#
|
1357
|
+
# Method `Complex#as_json` serializes `self`, returning a 2-element hash
|
1358
|
+
# representing `self`:
|
1359
|
+
#
|
1360
|
+
# require 'json/add/complex'
|
1361
|
+
# x = Complex(2).as_json # => {"json_class"=>"Complex", "r"=>2, "i"=>0}
|
1362
|
+
# y = Complex(2.0, 4).as_json # => {"json_class"=>"Complex", "r"=>2.0, "i"=>4}
|
1363
|
+
#
|
1364
|
+
# Method `JSON.create` deserializes such a hash, returning a Complex object:
|
1365
|
+
#
|
1366
|
+
# Complex.json_create(x) # => (2+0i)
|
1367
|
+
# Complex.json_create(y) # => (2.0+4i)
|
1325
1368
|
#
|
1326
1369
|
def as_json: (*untyped) -> Hash[String, String | Numeric]
|
1327
1370
|
|
@@ -1329,8 +1372,16 @@ class Complex
|
|
1329
1372
|
# rdoc-file=ext/json/lib/json/add/complex.rb
|
1330
1373
|
# - to_json(*args)
|
1331
1374
|
# -->
|
1332
|
-
#
|
1333
|
-
#
|
1375
|
+
# Returns a JSON string representing `self`:
|
1376
|
+
#
|
1377
|
+
# require 'json/add/complex'
|
1378
|
+
# puts Complex(2).to_json
|
1379
|
+
# puts Complex(2.0, 4).to_json
|
1380
|
+
#
|
1381
|
+
# Output:
|
1382
|
+
#
|
1383
|
+
# {"json_class":"Complex","r":2,"i":0}
|
1384
|
+
# {"json_class":"Complex","r":2.0,"i":4}
|
1334
1385
|
#
|
1335
1386
|
def to_json: (?JSON::State state) -> String
|
1336
1387
|
end
|
@@ -1341,8 +1392,7 @@ class Date
|
|
1341
1392
|
# rdoc-file=ext/json/lib/json/add/date.rb
|
1342
1393
|
# - json_create(object)
|
1343
1394
|
# -->
|
1344
|
-
#
|
1345
|
-
# Day of Calendar Reform `sg` to Date.
|
1395
|
+
# See #as_json.
|
1346
1396
|
#
|
1347
1397
|
def self.json_create: (Hash[String, String | Integer | Float] object) -> instance
|
1348
1398
|
|
@@ -1350,8 +1400,20 @@ class Date
|
|
1350
1400
|
# rdoc-file=ext/json/lib/json/add/date.rb
|
1351
1401
|
# - as_json(*)
|
1352
1402
|
# -->
|
1353
|
-
#
|
1354
|
-
# object.
|
1403
|
+
# Methods `Date#as_json` and `Date.json_create` may be used to serialize and
|
1404
|
+
# deserialize a Date object; see [Marshal](rdoc-ref:Marshal).
|
1405
|
+
#
|
1406
|
+
# Method `Date#as_json` serializes `self`, returning a 2-element hash
|
1407
|
+
# representing `self`:
|
1408
|
+
#
|
1409
|
+
# require 'json/add/date'
|
1410
|
+
# x = Date.today.as_json
|
1411
|
+
# # => {"json_class"=>"Date", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}
|
1412
|
+
#
|
1413
|
+
# Method `JSON.create` deserializes such a hash, returning a Date object:
|
1414
|
+
#
|
1415
|
+
# Date.json_create(x)
|
1416
|
+
# # => #<Date: 2023-11-21 ((2460270j,0s,0n),+0s,2299161j)>
|
1355
1417
|
#
|
1356
1418
|
def as_json: (*untyped) -> Hash[String, String | Integer | Float]
|
1357
1419
|
|
@@ -1359,8 +1421,14 @@ class Date
|
|
1359
1421
|
# rdoc-file=ext/json/lib/json/add/date.rb
|
1360
1422
|
# - to_json(*args)
|
1361
1423
|
# -->
|
1362
|
-
#
|
1363
|
-
#
|
1424
|
+
# Returns a JSON string representing `self`:
|
1425
|
+
#
|
1426
|
+
# require 'json/add/date'
|
1427
|
+
# puts Date.today.to_json
|
1428
|
+
#
|
1429
|
+
# Output:
|
1430
|
+
#
|
1431
|
+
# {"json_class":"Date","y":2023,"m":11,"d":21,"sg":2299161.0}
|
1364
1432
|
#
|
1365
1433
|
def to_json: (?JSON::State state) -> String
|
1366
1434
|
end
|
@@ -1371,9 +1439,7 @@ class DateTime
|
|
1371
1439
|
# rdoc-file=ext/json/lib/json/add/date_time.rb
|
1372
1440
|
# - json_create(object)
|
1373
1441
|
# -->
|
1374
|
-
#
|
1375
|
-
# minute `M`, second `S`, offset `of` and Day of Calendar Reform `sg` to
|
1376
|
-
# DateTime.
|
1442
|
+
# See #as_json.
|
1377
1443
|
#
|
1378
1444
|
def self.json_create: (Hash[String, String | Integer | Float] object) -> instance
|
1379
1445
|
|
@@ -1381,8 +1447,19 @@ class DateTime
|
|
1381
1447
|
# rdoc-file=ext/json/lib/json/add/date_time.rb
|
1382
1448
|
# - as_json(*)
|
1383
1449
|
# -->
|
1384
|
-
#
|
1385
|
-
# object.
|
1450
|
+
# Methods `DateTime#as_json` and `DateTime.json_create` may be used to serialize
|
1451
|
+
# and deserialize a DateTime object; see [Marshal](rdoc-ref:Marshal).
|
1452
|
+
#
|
1453
|
+
# Method `DateTime#as_json` serializes `self`, returning a 2-element hash
|
1454
|
+
# representing `self`:
|
1455
|
+
#
|
1456
|
+
# require 'json/add/datetime'
|
1457
|
+
# x = DateTime.now.as_json
|
1458
|
+
# # => {"json_class"=>"DateTime", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}
|
1459
|
+
#
|
1460
|
+
# Method `JSON.create` deserializes such a hash, returning a DateTime object:
|
1461
|
+
#
|
1462
|
+
# DateTime.json_create(x) # BUG? Raises Date::Error "invalid date"
|
1386
1463
|
#
|
1387
1464
|
def as_json: (*untyped) -> Hash[String, String | Integer | Float]
|
1388
1465
|
|
@@ -1390,9 +1467,14 @@ class DateTime
|
|
1390
1467
|
# rdoc-file=ext/json/lib/json/add/date_time.rb
|
1391
1468
|
# - to_json(*args)
|
1392
1469
|
# -->
|
1393
|
-
#
|
1394
|
-
#
|
1395
|
-
#
|
1470
|
+
# Returns a JSON string representing `self`:
|
1471
|
+
#
|
1472
|
+
# require 'json/add/datetime'
|
1473
|
+
# puts DateTime.now.to_json
|
1474
|
+
#
|
1475
|
+
# Output:
|
1476
|
+
#
|
1477
|
+
# {"json_class":"DateTime","y":2023,"m":11,"d":21,"sg":2299161.0}
|
1396
1478
|
#
|
1397
1479
|
def to_json: (?JSON::State state) -> String
|
1398
1480
|
end
|
@@ -1403,8 +1485,7 @@ class Exception
|
|
1403
1485
|
# rdoc-file=ext/json/lib/json/add/exception.rb
|
1404
1486
|
# - json_create(object)
|
1405
1487
|
# -->
|
1406
|
-
#
|
1407
|
-
# and backtrace `b` serialized with `to_json`
|
1488
|
+
# See #as_json.
|
1408
1489
|
#
|
1409
1490
|
def self.json_create: (Hash[String, String | Array[String] | nil] object) -> instance
|
1410
1491
|
|
@@ -1412,8 +1493,18 @@ class Exception
|
|
1412
1493
|
# rdoc-file=ext/json/lib/json/add/exception.rb
|
1413
1494
|
# - as_json(*)
|
1414
1495
|
# -->
|
1415
|
-
#
|
1416
|
-
# object.
|
1496
|
+
# Methods `Exception#as_json` and `Exception.json_create` may be used to
|
1497
|
+
# serialize and deserialize a Exception object; see [Marshal](rdoc-ref:Marshal).
|
1498
|
+
#
|
1499
|
+
# Method `Exception#as_json` serializes `self`, returning a 2-element hash
|
1500
|
+
# representing `self`:
|
1501
|
+
#
|
1502
|
+
# require 'json/add/exception'
|
1503
|
+
# x = Exception.new('Foo').as_json # => {"json_class"=>"Exception", "m"=>"Foo", "b"=>nil}
|
1504
|
+
#
|
1505
|
+
# Method `JSON.create` deserializes such a hash, returning a Exception object:
|
1506
|
+
#
|
1507
|
+
# Exception.json_create(x) # => #<Exception: Foo>
|
1417
1508
|
#
|
1418
1509
|
def as_json: (*untyped) -> Hash[String, String | Array[String] | nil]
|
1419
1510
|
|
@@ -1421,8 +1512,14 @@ class Exception
|
|
1421
1512
|
# rdoc-file=ext/json/lib/json/add/exception.rb
|
1422
1513
|
# - to_json(*args)
|
1423
1514
|
# -->
|
1424
|
-
#
|
1425
|
-
#
|
1515
|
+
# Returns a JSON string representing `self`:
|
1516
|
+
#
|
1517
|
+
# require 'json/add/exception'
|
1518
|
+
# puts Exception.new('Foo').to_json
|
1519
|
+
#
|
1520
|
+
# Output:
|
1521
|
+
#
|
1522
|
+
# {"json_class":"Exception","m":"Foo","b":null}
|
1426
1523
|
#
|
1427
1524
|
def to_json: (?JSON::State state) -> String
|
1428
1525
|
end
|
@@ -1433,8 +1530,7 @@ class OpenStruct
|
|
1433
1530
|
# rdoc-file=ext/json/lib/json/add/ostruct.rb
|
1434
1531
|
# - json_create(object)
|
1435
1532
|
# -->
|
1436
|
-
#
|
1437
|
-
# serialized by `to_json`.
|
1533
|
+
# See #as_json.
|
1438
1534
|
#
|
1439
1535
|
def self.json_create: (Hash[String, String | Hash[Symbol, untyped]] object) -> instance
|
1440
1536
|
|
@@ -1442,8 +1538,21 @@ class OpenStruct
|
|
1442
1538
|
# rdoc-file=ext/json/lib/json/add/ostruct.rb
|
1443
1539
|
# - as_json(*)
|
1444
1540
|
# -->
|
1445
|
-
#
|
1446
|
-
# object
|
1541
|
+
# Methods `OpenStruct#as_json` and `OpenStruct.json_create` may be used to
|
1542
|
+
# serialize and deserialize a OpenStruct object; see
|
1543
|
+
# [Marshal](rdoc-ref:Marshal).
|
1544
|
+
#
|
1545
|
+
# Method `OpenStruct#as_json` serializes `self`, returning a 2-element hash
|
1546
|
+
# representing `self`:
|
1547
|
+
#
|
1548
|
+
# require 'json/add/ostruct'
|
1549
|
+
# x = OpenStruct.new('name' => 'Rowdy', :age => nil).as_json
|
1550
|
+
# # => {"json_class"=>"OpenStruct", "t"=>{:name=>'Rowdy', :age=>nil}}
|
1551
|
+
#
|
1552
|
+
# Method `JSON.create` deserializes such a hash, returning a OpenStruct object:
|
1553
|
+
#
|
1554
|
+
# OpenStruct.json_create(x)
|
1555
|
+
# # => #<OpenStruct name='Rowdy', age=nil>
|
1447
1556
|
#
|
1448
1557
|
def as_json: (*untyped) -> Hash[String, String | Hash[Symbol, untyped]]
|
1449
1558
|
|
@@ -1451,7 +1560,14 @@ class OpenStruct
|
|
1451
1560
|
# rdoc-file=ext/json/lib/json/add/ostruct.rb
|
1452
1561
|
# - to_json(*args)
|
1453
1562
|
# -->
|
1454
|
-
#
|
1563
|
+
# Returns a JSON string representing `self`:
|
1564
|
+
#
|
1565
|
+
# require 'json/add/ostruct'
|
1566
|
+
# puts OpenStruct.new('name' => 'Rowdy', :age => nil).to_json
|
1567
|
+
#
|
1568
|
+
# Output:
|
1569
|
+
#
|
1570
|
+
# {"json_class":"OpenStruct","t":{'name':'Rowdy',"age":null}}
|
1455
1571
|
#
|
1456
1572
|
def to_json: (?JSON::State state) -> String
|
1457
1573
|
end
|
@@ -1462,8 +1578,7 @@ class Range[out Elem]
|
|
1462
1578
|
# rdoc-file=ext/json/lib/json/add/range.rb
|
1463
1579
|
# - json_create(object)
|
1464
1580
|
# -->
|
1465
|
-
#
|
1466
|
-
# serialized by `to_json`.
|
1581
|
+
# See #as_json.
|
1467
1582
|
#
|
1468
1583
|
def self.json_create: [A] (Hash[String, String | [ A, A, bool ]] object) -> Range[A]
|
1469
1584
|
|
@@ -1471,8 +1586,22 @@ class Range[out Elem]
|
|
1471
1586
|
# rdoc-file=ext/json/lib/json/add/range.rb
|
1472
1587
|
# - as_json(*)
|
1473
1588
|
# -->
|
1474
|
-
#
|
1475
|
-
# object.
|
1589
|
+
# Methods `Range#as_json` and `Range.json_create` may be used to serialize and
|
1590
|
+
# deserialize a Range object; see [Marshal](rdoc-ref:Marshal).
|
1591
|
+
#
|
1592
|
+
# Method `Range#as_json` serializes `self`, returning a 2-element hash
|
1593
|
+
# representing `self`:
|
1594
|
+
#
|
1595
|
+
# require 'json/add/range'
|
1596
|
+
# x = (1..4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, false]}
|
1597
|
+
# y = (1...4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, true]}
|
1598
|
+
# z = ('a'..'d').as_json # => {"json_class"=>"Range", "a"=>["a", "d", false]}
|
1599
|
+
#
|
1600
|
+
# Method `JSON.create` deserializes such a hash, returning a Range object:
|
1601
|
+
#
|
1602
|
+
# Range.json_create(x) # => 1..4
|
1603
|
+
# Range.json_create(y) # => 1...4
|
1604
|
+
# Range.json_create(z) # => "a".."d"
|
1476
1605
|
#
|
1477
1606
|
def as_json: (*untyped) -> Hash[String, String | [ Elem, Elem, bool ]]
|
1478
1607
|
|
@@ -1480,9 +1609,18 @@ class Range[out Elem]
|
|
1480
1609
|
# rdoc-file=ext/json/lib/json/add/range.rb
|
1481
1610
|
# - to_json(*args)
|
1482
1611
|
# -->
|
1483
|
-
#
|
1484
|
-
#
|
1485
|
-
#
|
1612
|
+
# Returns a JSON string representing `self`:
|
1613
|
+
#
|
1614
|
+
# require 'json/add/range'
|
1615
|
+
# puts (1..4).to_json
|
1616
|
+
# puts (1...4).to_json
|
1617
|
+
# puts ('a'..'d').to_json
|
1618
|
+
#
|
1619
|
+
# Output:
|
1620
|
+
#
|
1621
|
+
# {"json_class":"Range","a":[1,4,false]}
|
1622
|
+
# {"json_class":"Range","a":[1,4,true]}
|
1623
|
+
# {"json_class":"Range","a":["a","d",false]}
|
1486
1624
|
#
|
1487
1625
|
def to_json: (?JSON::State state) -> String
|
1488
1626
|
end
|
@@ -1493,8 +1631,7 @@ class Rational
|
|
1493
1631
|
# rdoc-file=ext/json/lib/json/add/rational.rb
|
1494
1632
|
# - json_create(object)
|
1495
1633
|
# -->
|
1496
|
-
#
|
1497
|
-
# `d`, to a Rational object.
|
1634
|
+
# See #as_json.
|
1498
1635
|
#
|
1499
1636
|
def self.json_create: (Hash[String, String | Integer] object) -> instance
|
1500
1637
|
|
@@ -1502,8 +1639,20 @@ class Rational
|
|
1502
1639
|
# rdoc-file=ext/json/lib/json/add/rational.rb
|
1503
1640
|
# - as_json(*)
|
1504
1641
|
# -->
|
1505
|
-
#
|
1506
|
-
# object.
|
1642
|
+
# Methods `Rational#as_json` and `Rational.json_create` may be used to serialize
|
1643
|
+
# and deserialize a Rational object; see [Marshal](rdoc-ref:Marshal).
|
1644
|
+
#
|
1645
|
+
# Method `Rational#as_json` serializes `self`, returning a 2-element hash
|
1646
|
+
# representing `self`:
|
1647
|
+
#
|
1648
|
+
# require 'json/add/rational'
|
1649
|
+
# x = Rational(2, 3).as_json
|
1650
|
+
# # => {"json_class"=>"Rational", "n"=>2, "d"=>3}
|
1651
|
+
#
|
1652
|
+
# Method `JSON.create` deserializes such a hash, returning a Rational object:
|
1653
|
+
#
|
1654
|
+
# Rational.json_create(x)
|
1655
|
+
# # => (2/3)
|
1507
1656
|
#
|
1508
1657
|
def as_json: (*untyped) -> Hash[String, String | Integer]
|
1509
1658
|
|
@@ -1511,8 +1660,14 @@ class Rational
|
|
1511
1660
|
# rdoc-file=ext/json/lib/json/add/rational.rb
|
1512
1661
|
# - to_json(*args)
|
1513
1662
|
# -->
|
1514
|
-
#
|
1515
|
-
#
|
1663
|
+
# Returns a JSON string representing `self`:
|
1664
|
+
#
|
1665
|
+
# require 'json/add/rational'
|
1666
|
+
# puts Rational(2, 3).to_json
|
1667
|
+
#
|
1668
|
+
# Output:
|
1669
|
+
#
|
1670
|
+
# {"json_class":"Rational","n":2,"d":3}
|
1516
1671
|
#
|
1517
1672
|
def to_json: (?JSON::State state) -> String
|
1518
1673
|
end
|
@@ -1523,8 +1678,7 @@ class Regexp
|
|
1523
1678
|
# rdoc-file=ext/json/lib/json/add/regexp.rb
|
1524
1679
|
# - json_create(object)
|
1525
1680
|
# -->
|
1526
|
-
#
|
1527
|
-
# (Regexp or String) and options `o` serialized by `to_json`
|
1681
|
+
# See #as_json.
|
1528
1682
|
#
|
1529
1683
|
def self.json_create: (Hash[String, String | Integer] object) -> instance
|
1530
1684
|
|
@@ -1532,8 +1686,19 @@ class Regexp
|
|
1532
1686
|
# rdoc-file=ext/json/lib/json/add/regexp.rb
|
1533
1687
|
# - as_json(*)
|
1534
1688
|
# -->
|
1535
|
-
#
|
1536
|
-
# object.
|
1689
|
+
# Methods `Regexp#as_json` and `Regexp.json_create` may be used to serialize and
|
1690
|
+
# deserialize a Regexp object; see [Marshal](rdoc-ref:Marshal).
|
1691
|
+
#
|
1692
|
+
# Method `Regexp#as_json` serializes `self`, returning a 2-element hash
|
1693
|
+
# representing `self`:
|
1694
|
+
#
|
1695
|
+
# require 'json/add/regexp'
|
1696
|
+
# x = /foo/.as_json
|
1697
|
+
# # => {"json_class"=>"Regexp", "o"=>0, "s"=>"foo"}
|
1698
|
+
#
|
1699
|
+
# Method `JSON.create` deserializes such a hash, returning a Regexp object:
|
1700
|
+
#
|
1701
|
+
# Regexp.json_create(x) # => /foo/
|
1537
1702
|
#
|
1538
1703
|
def as_json: (*untyped) -> Hash[String, String | Integer]
|
1539
1704
|
|
@@ -1541,8 +1706,14 @@ class Regexp
|
|
1541
1706
|
# rdoc-file=ext/json/lib/json/add/regexp.rb
|
1542
1707
|
# - to_json(*args)
|
1543
1708
|
# -->
|
1544
|
-
#
|
1545
|
-
#
|
1709
|
+
# Returns a JSON string representing `self`:
|
1710
|
+
#
|
1711
|
+
# require 'json/add/regexp'
|
1712
|
+
# puts /foo/.to_json
|
1713
|
+
#
|
1714
|
+
# Output:
|
1715
|
+
#
|
1716
|
+
# {"json_class":"Regexp","o":0,"s":"foo"}
|
1546
1717
|
#
|
1547
1718
|
def to_json: (?JSON::State state) -> String
|
1548
1719
|
end
|
@@ -1553,9 +1724,7 @@ class Set[unchecked out A]
|
|
1553
1724
|
# rdoc-file=ext/json/lib/json/add/set.rb
|
1554
1725
|
# - json_create(object)
|
1555
1726
|
# -->
|
1556
|
-
#
|
1557
|
-
#
|
1558
|
-
# method used for JSON marshalling support.
|
1727
|
+
# See #as_json.
|
1559
1728
|
#
|
1560
1729
|
def self.json_create: [A] (Hash[String, String | Array[A]] object) -> Set[A]
|
1561
1730
|
|
@@ -1563,9 +1732,19 @@ class Set[unchecked out A]
|
|
1563
1732
|
# rdoc-file=ext/json/lib/json/add/set.rb
|
1564
1733
|
# - as_json(*)
|
1565
1734
|
# -->
|
1566
|
-
#
|
1735
|
+
# Methods `Set#as_json` and `Set.json_create` may be used to serialize and
|
1736
|
+
# deserialize a Set object; see [Marshal](rdoc-ref:Marshal).
|
1737
|
+
#
|
1738
|
+
# Method `Set#as_json` serializes `self`, returning a 2-element hash
|
1739
|
+
# representing `self`:
|
1740
|
+
#
|
1741
|
+
# require 'json/add/set'
|
1742
|
+
# x = Set.new(%w/foo bar baz/).as_json
|
1743
|
+
# # => {"json_class"=>"Set", "a"=>["foo", "bar", "baz"]}
|
1567
1744
|
#
|
1568
|
-
#
|
1745
|
+
# Method `JSON.create` deserializes such a hash, returning a Set object:
|
1746
|
+
#
|
1747
|
+
# Set.json_create(x) # => #<Set: {"foo", "bar", "baz"}>
|
1569
1748
|
#
|
1570
1749
|
def as_json: (*untyped) -> Hash[String, String | Array[A]]
|
1571
1750
|
|
@@ -1573,7 +1752,14 @@ class Set[unchecked out A]
|
|
1573
1752
|
# rdoc-file=ext/json/lib/json/add/set.rb
|
1574
1753
|
# - to_json(*args)
|
1575
1754
|
# -->
|
1576
|
-
#
|
1755
|
+
# Returns a JSON string representing `self`:
|
1756
|
+
#
|
1757
|
+
# require 'json/add/set'
|
1758
|
+
# puts Set.new(%w/foo bar baz/).to_json
|
1759
|
+
#
|
1760
|
+
# Output:
|
1761
|
+
#
|
1762
|
+
# {"json_class":"Set","a":["foo","bar","baz"]}
|
1577
1763
|
#
|
1578
1764
|
def to_json: (?JSON::State state) -> String
|
1579
1765
|
end
|
@@ -1584,8 +1770,7 @@ class Struct[Elem]
|
|
1584
1770
|
# rdoc-file=ext/json/lib/json/add/struct.rb
|
1585
1771
|
# - json_create(object)
|
1586
1772
|
# -->
|
1587
|
-
#
|
1588
|
-
# serialized by `to_json`.
|
1773
|
+
# See #as_json.
|
1589
1774
|
#
|
1590
1775
|
def self.json_create: [Elem] (Hash[String, String | Array[Elem]] object) -> Struct[Elem]
|
1591
1776
|
|
@@ -1593,8 +1778,21 @@ class Struct[Elem]
|
|
1593
1778
|
# rdoc-file=ext/json/lib/json/add/struct.rb
|
1594
1779
|
# - as_json(*)
|
1595
1780
|
# -->
|
1596
|
-
#
|
1597
|
-
# object.
|
1781
|
+
# Methods `Struct#as_json` and `Struct.json_create` may be used to serialize and
|
1782
|
+
# deserialize a Struct object; see [Marshal](rdoc-ref:Marshal).
|
1783
|
+
#
|
1784
|
+
# Method `Struct#as_json` serializes `self`, returning a 2-element hash
|
1785
|
+
# representing `self`:
|
1786
|
+
#
|
1787
|
+
# require 'json/add/struct'
|
1788
|
+
# Customer = Struct.new('Customer', :name, :address, :zip)
|
1789
|
+
# x = Struct::Customer.new.as_json
|
1790
|
+
# # => {"json_class"=>"Struct::Customer", "v"=>[nil, nil, nil]}
|
1791
|
+
#
|
1792
|
+
# Method `JSON.create` deserializes such a hash, returning a Struct object:
|
1793
|
+
#
|
1794
|
+
# Struct::Customer.json_create(x)
|
1795
|
+
# # => #<struct Struct::Customer name=nil, address=nil, zip=nil>
|
1598
1796
|
#
|
1599
1797
|
def as_json: (*untyped) -> Hash[String, String | Array[Elem]]
|
1600
1798
|
|
@@ -1602,8 +1800,15 @@ class Struct[Elem]
|
|
1602
1800
|
# rdoc-file=ext/json/lib/json/add/struct.rb
|
1603
1801
|
# - to_json(*args)
|
1604
1802
|
# -->
|
1605
|
-
#
|
1606
|
-
#
|
1803
|
+
# Returns a JSON string representing `self`:
|
1804
|
+
#
|
1805
|
+
# require 'json/add/struct'
|
1806
|
+
# Customer = Struct.new('Customer', :name, :address, :zip)
|
1807
|
+
# puts Struct::Customer.new.to_json
|
1808
|
+
#
|
1809
|
+
# Output:
|
1810
|
+
#
|
1811
|
+
# {"json_class":"Struct","t":{'name':'Rowdy',"age":null}}
|
1607
1812
|
#
|
1608
1813
|
def to_json: (?JSON::State state) -> String
|
1609
1814
|
end
|
@@ -1614,8 +1819,7 @@ class Symbol
|
|
1614
1819
|
# rdoc-file=ext/json/lib/json/add/symbol.rb
|
1615
1820
|
# - json_create(o)
|
1616
1821
|
# -->
|
1617
|
-
#
|
1618
|
-
# to a Symbol
|
1822
|
+
# See #as_json.
|
1619
1823
|
#
|
1620
1824
|
def self.json_create: (Hash[String, String] object) -> instance
|
1621
1825
|
|
@@ -1623,8 +1827,19 @@ class Symbol
|
|
1623
1827
|
# rdoc-file=ext/json/lib/json/add/symbol.rb
|
1624
1828
|
# - as_json(*)
|
1625
1829
|
# -->
|
1626
|
-
#
|
1627
|
-
# object.
|
1830
|
+
# Methods `Symbol#as_json` and `Symbol.json_create` may be used to serialize and
|
1831
|
+
# deserialize a Symbol object; see [Marshal](rdoc-ref:Marshal).
|
1832
|
+
#
|
1833
|
+
# Method `Symbol#as_json` serializes `self`, returning a 2-element hash
|
1834
|
+
# representing `self`:
|
1835
|
+
#
|
1836
|
+
# require 'json/add/symbol'
|
1837
|
+
# x = :foo.as_json
|
1838
|
+
# # => {"json_class"=>"Symbol", "s"=>"foo"}
|
1839
|
+
#
|
1840
|
+
# Method `JSON.create` deserializes such a hash, returning a Symbol object:
|
1841
|
+
#
|
1842
|
+
# Symbol.json_create(x) # => :foo
|
1628
1843
|
#
|
1629
1844
|
def as_json: (*untyped) -> Hash[String, String]
|
1630
1845
|
|
@@ -1632,8 +1847,14 @@ class Symbol
|
|
1632
1847
|
# rdoc-file=ext/json/lib/json/add/symbol.rb
|
1633
1848
|
# - to_json(*a)
|
1634
1849
|
# -->
|
1635
|
-
#
|
1636
|
-
#
|
1850
|
+
# Returns a JSON string representing `self`:
|
1851
|
+
#
|
1852
|
+
# require 'json/add/symbol'
|
1853
|
+
# puts :foo.to_json
|
1854
|
+
#
|
1855
|
+
# Output:
|
1856
|
+
#
|
1857
|
+
# # {"json_class":"Symbol","s":"foo"}
|
1637
1858
|
#
|
1638
1859
|
def to_json: (?JSON::State state) -> String
|
1639
1860
|
end
|
@@ -1644,7 +1865,7 @@ class Time
|
|
1644
1865
|
# rdoc-file=ext/json/lib/json/add/time.rb
|
1645
1866
|
# - json_create(object)
|
1646
1867
|
# -->
|
1647
|
-
#
|
1868
|
+
# See #as_json.
|
1648
1869
|
#
|
1649
1870
|
def self.json_create: (Hash[String, String | Integer] object) -> instance
|
1650
1871
|
|
@@ -1652,8 +1873,20 @@ class Time
|
|
1652
1873
|
# rdoc-file=ext/json/lib/json/add/time.rb
|
1653
1874
|
# - as_json(*)
|
1654
1875
|
# -->
|
1655
|
-
#
|
1656
|
-
# object.
|
1876
|
+
# Methods `Time#as_json` and `Time.json_create` may be used to serialize and
|
1877
|
+
# deserialize a Time object; see [Marshal](rdoc-ref:Marshal).
|
1878
|
+
#
|
1879
|
+
# Method `Time#as_json` serializes `self`, returning a 2-element hash
|
1880
|
+
# representing `self`:
|
1881
|
+
#
|
1882
|
+
# require 'json/add/time'
|
1883
|
+
# x = Time.now.as_json
|
1884
|
+
# # => {"json_class"=>"Time", "s"=>1700931656, "n"=>472846644}
|
1885
|
+
#
|
1886
|
+
# Method `JSON.create` deserializes such a hash, returning a Time object:
|
1887
|
+
#
|
1888
|
+
# Time.json_create(x)
|
1889
|
+
# # => 2023-11-25 11:00:56.472846644 -0600
|
1657
1890
|
#
|
1658
1891
|
def as_json: (*untyped) -> Hash[String, String | Integer]
|
1659
1892
|
|
@@ -1661,8 +1894,14 @@ class Time
|
|
1661
1894
|
# rdoc-file=ext/json/lib/json/add/time.rb
|
1662
1895
|
# - to_json(*args)
|
1663
1896
|
# -->
|
1664
|
-
#
|
1665
|
-
#
|
1897
|
+
# Returns a JSON string representing `self`:
|
1898
|
+
#
|
1899
|
+
# require 'json/add/time'
|
1900
|
+
# puts Time.now.to_json
|
1901
|
+
#
|
1902
|
+
# Output:
|
1903
|
+
#
|
1904
|
+
# {"json_class":"Time","s":1700931678,"n":980650786}
|
1666
1905
|
#
|
1667
1906
|
def to_json: (?JSON::State state) -> String
|
1668
1907
|
end
|