rbs 3.1.3 → 3.2.0.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -6
  3. data/CHANGELOG.md +68 -0
  4. data/Gemfile +0 -6
  5. data/Gemfile.lock +12 -21
  6. data/README.md +1 -1
  7. data/Rakefile +44 -0
  8. data/Steepfile +3 -3
  9. data/core/array.rbs +0 -8
  10. data/core/builtin.rbs +28 -8
  11. data/core/constants.rbs +13 -5
  12. data/core/exception.rbs +1 -1
  13. data/core/global_variables.rbs +27 -27
  14. data/core/io.rbs +163 -172
  15. data/core/kernel.rbs +7 -4
  16. data/core/module.rbs +34 -32
  17. data/core/object.rbs +2 -2
  18. data/core/string_io.rbs +9 -0
  19. data/core/thread.rbs +25 -1
  20. data/core/time.rbs +3 -3
  21. data/docs/CONTRIBUTING.md +1 -1
  22. data/docs/rbs_by_example.md +16 -35
  23. data/docs/repo.md +1 -1
  24. data/docs/sigs.md +7 -7
  25. data/docs/stdlib.md +2 -3
  26. data/docs/syntax.md +40 -40
  27. data/lib/rbs/cli.rb +15 -4
  28. data/lib/rbs/collection/installer.rb +5 -2
  29. data/lib/rbs/collection/sources/stdlib.rb +5 -1
  30. data/lib/rbs/errors.rb +8 -1
  31. data/lib/rbs/file_finder.rb +1 -1
  32. data/lib/rbs/prototype/rb.rb +64 -6
  33. data/lib/rbs/prototype/rbi.rb +2 -6
  34. data/lib/rbs/prototype/runtime.rb +29 -8
  35. data/lib/rbs/subtractor.rb +17 -0
  36. data/lib/rbs/type_name.rb +4 -4
  37. data/lib/rbs/version.rb +1 -1
  38. data/rbs.gemspec +1 -1
  39. data/schema/decls.json +1 -1
  40. data/sig/errors.rbs +54 -0
  41. data/sig/parser.rbs +2 -2
  42. data/sig/prototype/rb.rbs +9 -1
  43. data/sig/subtractor.rbs +4 -0
  44. data/stdlib/logger/0/logger.rbs +1 -1
  45. data/stdlib/observable/0/observable.rbs +219 -0
  46. data/stdlib/uri/0/common.rbs +24 -0
  47. data/stdlib/zlib/0/buf_error.rbs +79 -0
  48. data/stdlib/zlib/0/data_error.rbs +79 -0
  49. data/stdlib/zlib/0/deflate.rbs +276 -0
  50. data/stdlib/zlib/0/error.rbs +89 -0
  51. data/stdlib/zlib/0/gzip_file/crc_error.rbs +115 -0
  52. data/stdlib/zlib/0/gzip_file/error.rbs +128 -0
  53. data/stdlib/zlib/0/gzip_file/length_error.rbs +115 -0
  54. data/stdlib/zlib/0/gzip_file/no_footer.rbs +114 -0
  55. data/stdlib/zlib/0/gzip_file.rbs +228 -0
  56. data/stdlib/zlib/0/gzip_reader.rbs +362 -0
  57. data/stdlib/zlib/0/gzip_writer.rbs +237 -0
  58. data/stdlib/zlib/0/inflate.rbs +249 -0
  59. data/stdlib/zlib/0/mem_error.rbs +79 -0
  60. data/stdlib/zlib/0/need_dict.rbs +82 -0
  61. data/stdlib/zlib/0/stream_end.rbs +80 -0
  62. data/stdlib/zlib/0/stream_error.rbs +80 -0
  63. data/stdlib/zlib/0/version_error.rbs +80 -0
  64. data/stdlib/zlib/0/zstream.rbs +270 -0
  65. metadata +24 -8
  66. data/stdlib/prime/0/integer-extension.rbs +0 -41
  67. data/stdlib/prime/0/manifest.yaml +0 -2
  68. data/stdlib/prime/0/prime.rbs +0 -372
data/core/module.rbs CHANGED
@@ -235,7 +235,7 @@ class Module < Object
235
235
  #
236
236
  # Exiting with code 99
237
237
  #
238
- def alias_method: (::Symbol | ::String new_name, ::Symbol | ::String old_name) -> ::Symbol
238
+ def alias_method: (id new_name, id old_name) -> ::Symbol
239
239
 
240
240
  # <!--
241
241
  # rdoc-file=object.c
@@ -284,7 +284,7 @@ class Module < Object
284
284
  # end
285
285
  # Mod.instance_methods.sort #=> [:one, :one=, :two, :two=]
286
286
  #
287
- def attr_accessor: (*Object::name arg0) -> Array[Symbol]
287
+ def attr_accessor: (*id arg0) -> Array[Symbol]
288
288
 
289
289
  # <!--
290
290
  # rdoc-file=object.c
@@ -298,7 +298,7 @@ class Module < Object
298
298
  # in turn. String arguments are converted to symbols. Returns an array of
299
299
  # defined method names as symbols.
300
300
  #
301
- def attr_reader: (*Object::name arg0) -> Array[Symbol]
301
+ def attr_reader: (*id arg0) -> Array[Symbol]
302
302
 
303
303
  # <!--
304
304
  # rdoc-file=object.c
@@ -309,7 +309,7 @@ class Module < Object
309
309
  # *symbol*`.id2name`. String arguments are converted to symbols. Returns an
310
310
  # array of defined method names as symbols.
311
311
  #
312
- def attr_writer: (*Object::name arg0) -> Array[Symbol]
312
+ def attr_writer: (*id arg0) -> Array[Symbol]
313
313
 
314
314
  # <!--
315
315
  # rdoc-file=load.c
@@ -328,7 +328,7 @@ class Module < Object
328
328
  # replaced with *filename*. If *const* is defined but not as autoload, does
329
329
  # nothing.
330
330
  #
331
- def autoload: (Symbol _module, String filename) -> NilClass
331
+ def autoload: (id _module, String filename) -> NilClass
332
332
 
333
333
  # <!--
334
334
  # rdoc-file=load.c
@@ -354,7 +354,7 @@ class Module < Object
354
354
  # B.autoload?(:CONST) #=> "const.rb", found in A (ancestor)
355
355
  # B.autoload?(:CONST, false) #=> nil, not found in B itself
356
356
  #
357
- def autoload?: (Symbol name, ?boolish inherit) -> String?
357
+ def autoload?: (id name, ?boolish inherit) -> String?
358
358
 
359
359
  # <!-- rdoc-file=vm_eval.c -->
360
360
  # Evaluates the string or block in the context of *mod*, except that when a
@@ -412,7 +412,7 @@ class Module < Object
412
412
  # Fred.class_variable_defined?(:@@foo) #=> true
413
413
  # Fred.class_variable_defined?(:@@bar) #=> false
414
414
  #
415
- def class_variable_defined?: (Symbol | String arg0) -> bool
415
+ def class_variable_defined?: (id arg0) -> bool
416
416
 
417
417
  # <!--
418
418
  # rdoc-file=object.c
@@ -428,7 +428,7 @@ class Module < Object
428
428
  # end
429
429
  # Fred.class_variable_get(:@@foo) #=> 99
430
430
  #
431
- def class_variable_get: (Symbol | String arg0) -> untyped
431
+ def class_variable_get: (id arg0) -> untyped
432
432
 
433
433
  # <!--
434
434
  # rdoc-file=object.c
@@ -447,7 +447,7 @@ class Module < Object
447
447
  # Fred.class_variable_set(:@@foo, 101) #=> 101
448
448
  # Fred.new.foo #=> 101
449
449
  #
450
- def class_variable_set: (Symbol | String arg0, untyped arg1) -> untyped
450
+ def class_variable_set: (id arg0, untyped arg1) -> untyped
451
451
 
452
452
  # <!--
453
453
  # rdoc-file=object.c
@@ -527,7 +527,7 @@ class Module < Object
527
527
  #
528
528
  # Hash.const_defined? 'foobar' #=> NameError: wrong constant name foobar
529
529
  #
530
- def const_defined?: (Symbol | String name, ?boolish inherit) -> bool
530
+ def const_defined?: (id name, ?boolish inherit) -> bool
531
531
 
532
532
  # <!--
533
533
  # rdoc-file=object.c
@@ -566,7 +566,7 @@ class Module < Object
566
566
  #
567
567
  # Object.const_get 'foobar' #=> NameError: wrong constant name foobar
568
568
  #
569
- def const_get: (Symbol | String name, ?boolish inherit) -> untyped
569
+ def const_get: (id name, ?boolish inherit) -> untyped
570
570
 
571
571
  # <!--
572
572
  # rdoc-file=object.c
@@ -618,7 +618,7 @@ class Module < Object
618
618
  #
619
619
  # Object.const_set('foobar', 42) #=> NameError: wrong constant name foobar
620
620
  #
621
- def const_set: (Symbol | String arg0, untyped arg1) -> untyped
621
+ def const_set: (id arg0, untyped arg1) -> untyped
622
622
 
623
623
  # <!--
624
624
  # rdoc-file=object.c
@@ -668,7 +668,7 @@ class Module < Object
668
668
  # p Object.const_source_location('A::C1') # => ["test.rb", 2] -- nesting is supported
669
669
  # p Object.const_source_location('String') # => [] -- constant is defined in C code
670
670
  #
671
- def const_source_location: (Symbol | String name, ?boolish inherit) -> ([ String, Integer ] | [ ] | nil)
671
+ def const_source_location: (id name, ?boolish inherit) -> ([ String, Integer ] | [ ] | nil)
672
672
 
673
673
  # <!--
674
674
  # rdoc-file=object.c
@@ -726,8 +726,8 @@ class Module < Object
726
726
  # I'm Dino!
727
727
  # #<B:0x401b39e8>
728
728
  #
729
- def define_method: (Symbol | String arg0, ?Proc | Method | UnboundMethod arg1) -> Symbol
730
- | (Symbol | String arg0) { () -> untyped } -> Symbol
729
+ def define_method: (id symbol, Proc | Method | UnboundMethod method) -> Symbol
730
+ | (id symbol) { () -> untyped } -> Symbol
731
731
 
732
732
  # <!--
733
733
  # rdoc-file=object.c
@@ -746,7 +746,7 @@ class Module < Object
746
746
  # HTTP::NOT_FOUND
747
747
  # # warning: constant HTTP::NOT_FOUND is deprecated
748
748
  #
749
- def deprecate_constant: (*Symbol) -> self
749
+ def deprecate_constant: (*id) -> self
750
750
 
751
751
  def eql?: (untyped other) -> bool
752
752
 
@@ -936,7 +936,7 @@ class Module < Object
936
936
  #
937
937
  # Hello there, Dave!
938
938
  #
939
- def instance_method: (Symbol arg0) -> UnboundMethod
939
+ def instance_method: (id arg0) -> UnboundMethod
940
940
 
941
941
  # <!--
942
942
  # rdoc-file=object.c
@@ -1029,7 +1029,7 @@ class Module < Object
1029
1029
  # C.method_defined? "method4" #=> false
1030
1030
  # C.method_defined? "private_method2" #=> false
1031
1031
  #
1032
- def method_defined?: (Symbol | String name, ?boolish inherit) -> bool
1032
+ def method_defined?: (id name, ?boolish inherit) -> bool
1033
1033
 
1034
1034
  # <!--
1035
1035
  # rdoc-file=object.c
@@ -1147,7 +1147,7 @@ class Module < Object
1147
1147
  # Mod.one #=> "This is one"
1148
1148
  # c.call_one #=> "This is the new one"
1149
1149
  #
1150
- def module_function: (*Symbol | String arg0) -> self
1150
+ def module_function: (*id arg0) -> self
1151
1151
 
1152
1152
  # <!--
1153
1153
  # rdoc-file=object.c
@@ -1246,7 +1246,7 @@ class Module < Object
1246
1246
  # end
1247
1247
  # end
1248
1248
  #
1249
- def private_class_method: (*Symbol | String arg0) -> self
1249
+ def private_class_method: (*id arg0) -> self
1250
1250
 
1251
1251
  # <!--
1252
1252
  # rdoc-file=object.c
@@ -1254,7 +1254,7 @@ class Module < Object
1254
1254
  # -->
1255
1255
  # Makes a list of existing constants private.
1256
1256
  #
1257
- def private_constant: (*Symbol arg0) -> self
1257
+ def private_constant: (*id arg0) -> self
1258
1258
 
1259
1259
  # <!--
1260
1260
  # rdoc-file=object.c
@@ -1301,7 +1301,7 @@ class Module < Object
1301
1301
  # C.private_method_defined? "method2", false #=> false
1302
1302
  # C.method_defined? "method2" #=> false
1303
1303
  #
1304
- def private_method_defined?: (Symbol | String name, ?boolish inherit) -> bool
1304
+ def private_method_defined?: (id name, ?boolish inherit) -> bool
1305
1305
 
1306
1306
  # <!--
1307
1307
  # rdoc-file=vm_method.c
@@ -1365,7 +1365,7 @@ class Module < Object
1365
1365
  # C.protected_method_defined? "method2", false #=> false
1366
1366
  # C.method_defined? "method2" #=> true
1367
1367
  #
1368
- def protected_method_defined?: (Symbol | String name, ?boolish inherit) -> bool
1368
+ def protected_method_defined?: (id name, ?boolish inherit) -> bool
1369
1369
 
1370
1370
  # <!--
1371
1371
  # rdoc-file=vm_method.c
@@ -1398,7 +1398,7 @@ class Module < Object
1398
1398
  # String arguments are converted to symbols. An Array of Symbols and/or Strings
1399
1399
  # is also accepted.
1400
1400
  #
1401
- def public_class_method: (*Symbol | String arg0) -> self
1401
+ def public_class_method: (*id arg0) -> self
1402
1402
 
1403
1403
  # <!--
1404
1404
  # rdoc-file=object.c
@@ -1406,7 +1406,7 @@ class Module < Object
1406
1406
  # -->
1407
1407
  # Makes a list of existing constants public.
1408
1408
  #
1409
- def public_constant: (*Symbol arg0) -> self
1409
+ def public_constant: (*id arg0) -> self
1410
1410
 
1411
1411
  # <!--
1412
1412
  # rdoc-file=proc.c
@@ -1414,7 +1414,7 @@ class Module < Object
1414
1414
  # -->
1415
1415
  # Similar to *instance_method*, searches public method only.
1416
1416
  #
1417
- def public_instance_method: (Symbol arg0) -> UnboundMethod
1417
+ def public_instance_method: (id arg0) -> UnboundMethod
1418
1418
 
1419
1419
  # <!--
1420
1420
  # rdoc-file=object.c
@@ -1453,7 +1453,7 @@ class Module < Object
1453
1453
  # C.public_method_defined? "method2" #=> false
1454
1454
  # C.method_defined? "method2" #=> true
1455
1455
  #
1456
- def public_method_defined?: (Symbol | String name, ?boolish inherit) -> bool
1456
+ def public_method_defined?: (id name, ?boolish inherit) -> bool
1457
1457
 
1458
1458
  # <!--
1459
1459
  # rdoc-file=eval.c
@@ -1505,7 +1505,7 @@ class Module < Object
1505
1505
  # 99
1506
1506
  # nil
1507
1507
  #
1508
- def remove_class_variable: (Symbol arg0) -> untyped
1508
+ def remove_class_variable: (id arg0) -> untyped
1509
1509
 
1510
1510
  # <!--
1511
1511
  # rdoc-file=object.c
@@ -1515,7 +1515,7 @@ class Module < Object
1515
1515
  # previous value. If that constant referred to a module, this will not change
1516
1516
  # that module's name and can lead to confusion.
1517
1517
  #
1518
- def remove_const: (Symbol arg0) -> untyped
1518
+ def remove_const: (id arg0) -> untyped
1519
1519
 
1520
1520
  # <!--
1521
1521
  # rdoc-file=vm_method.c
@@ -1525,7 +1525,7 @@ class Module < Object
1525
1525
  # Removes the method identified by *symbol* from the current class. For an
1526
1526
  # example, see Module#undef_method. String arguments are converted to symbols.
1527
1527
  #
1528
- def remove_method: (*Symbol | String arg0) -> self
1528
+ def remove_method: (*id arg0) -> self
1529
1529
 
1530
1530
  # <!--
1531
1531
  # rdoc-file=object.c
@@ -1591,7 +1591,7 @@ class Module < Object
1591
1591
  # In parent
1592
1592
  # prog.rb:23: undefined method `hello' for #<Child:0x401b3bb4> (NoMethodError)
1593
1593
  #
1594
- def undef_method: (*Symbol | String arg0) -> self
1594
+ def undef_method: (*id arg0) -> self
1595
1595
 
1596
1596
  # <!--
1597
1597
  # rdoc-file=object.c
@@ -1629,5 +1629,7 @@ class Module < Object
1629
1629
  # `attr_reader(name)` but deprecated. Returns an array of defined method names
1630
1630
  # as symbols.
1631
1631
  #
1632
- def attr: (*Object::name arg0) -> Array[Symbol]
1632
+ def attr: (*id arg0) -> Array[Symbol]
1633
+
1634
+ type id = Symbol | string
1633
1635
  end
data/core/object.rbs CHANGED
@@ -205,7 +205,7 @@ class Object < BasicObject
205
205
  # chris.define_singleton_method(:greet) {|greeting| "#{greeting}, I'm Chris!" }
206
206
  # chris.greet("Hi") #=> "Hi, I'm Chris!"
207
207
  #
208
- def define_singleton_method: (name, Method | UnboundMethod) -> Symbol
208
+ def define_singleton_method: (name, Method | UnboundMethod | Proc method) -> Symbol
209
209
  | (name) { (*untyped) -> untyped } -> Symbol
210
210
 
211
211
  # <!--
@@ -320,7 +320,7 @@ class Object < BasicObject
320
320
  # enum.first(4) # => [1, 1, 1, 2]
321
321
  # enum.size # => 42
322
322
  #
323
- def enum_for: (Symbol method, *untyped args) ?{ (*untyped args) -> Integer } -> Enumerator[untyped, untyped]
323
+ def enum_for: (Symbol method, *untyped, **untyped) ?{ (*untyped, **untyped) -> Integer } -> Enumerator[untyped, untyped]
324
324
  | () ?{ () -> Integer } -> Enumerator[untyped, self]
325
325
 
326
326
  # <!--
data/core/string_io.rbs CHANGED
@@ -495,6 +495,15 @@ class StringIO
495
495
  #
496
496
  def tell: () -> Integer
497
497
 
498
+ # <!--
499
+ # rdoc-file=ext/stringio/stringio.c
500
+ # - strio.truncate(integer) -> 0
501
+ # -->
502
+ # Truncates the buffer string to at most *integer* bytes. The stream must be
503
+ # opened for writing.
504
+ #
505
+ def truncate: (Integer) -> 0
506
+
498
507
  # <!-- rdoc-file=ext/stringio/stringio.c -->
499
508
  # Returns `false`. Just for compatibility to IO.
500
509
  #
data/core/thread.rbs CHANGED
@@ -971,6 +971,30 @@ class Thread < Object
971
971
  #
972
972
  def self.handle_interrupt: (untyped hash) -> untyped
973
973
 
974
+ # <!--
975
+ # rdoc-file=thread.c
976
+ # - thr.raise
977
+ # - thr.raise(string)
978
+ # - thr.raise(exception [, string [, array]])
979
+ # -->
980
+ # Raises an exception from the given thread. The caller does not have to be
981
+ # `thr`. See Kernel#raise for more information.
982
+ #
983
+ # Thread.abort_on_exception = true
984
+ # a = Thread.new { sleep(200) }
985
+ # a.raise("Gotcha")
986
+ #
987
+ # This will produce:
988
+ #
989
+ # prog.rb:3: Gotcha (RuntimeError)
990
+ # from prog.rb:2:in `initialize'
991
+ # from prog.rb:2:in `new'
992
+ # from prog.rb:2
993
+ #
994
+ def self?.raise: () -> bot
995
+ | (String message, ?cause: Exception?) -> bot
996
+ | (_Exception exception, ?untyped message, ?::Array[String] backtrace, ?cause: Exception?) -> bot
997
+
974
998
  # <!--
975
999
  # rdoc-file=thread.c
976
1000
  # - Thread.kill(thread) -> thread
@@ -1414,7 +1438,7 @@ class Thread::ConditionVariable < Object
1414
1438
  #
1415
1439
  # Returns the slept result on `mutex`.
1416
1440
  #
1417
- def wait: (Thread::Mutex mutex, ?Integer timeout) -> self
1441
+ def wait: (Thread::Mutex mutex, ?Integer | Float? timeout) -> self
1418
1442
  end
1419
1443
 
1420
1444
  # <!-- rdoc-file=thread_sync.c -->
data/core/time.rbs CHANGED
@@ -1093,7 +1093,7 @@ class Time < Object
1093
1093
  #
1094
1094
  # Related: Time#ceil, Time#floor.
1095
1095
  #
1096
- def round: (?Integer arg0) -> Time
1096
+ def round: (?int ndigits) -> Time
1097
1097
 
1098
1098
  # <!--
1099
1099
  # rdoc-file=time.c
@@ -1503,7 +1503,7 @@ class Time < Object
1503
1503
  #
1504
1504
  # Related: Time#ceil, Time#round.
1505
1505
  #
1506
- def floor: (?Integer ndigits) -> Time
1506
+ def floor: (?int ndigits) -> Time
1507
1507
 
1508
1508
  # <!--
1509
1509
  # rdoc-file=time.c
@@ -1530,7 +1530,7 @@ class Time < Object
1530
1530
  #
1531
1531
  # Related: Time#floor, Time#round.
1532
1532
  #
1533
- def ceil: (?Integer ndigits) -> Time
1533
+ def ceil: (?int ndigits) -> Time
1534
1534
  end
1535
1535
 
1536
1536
  Time::RFC2822_DAY_NAME: Array[String]
data/docs/CONTRIBUTING.md CHANGED
@@ -69,7 +69,7 @@ We define the standard members order so that ordering doesn't bother reading dif
69
69
  5. `public` & public instance methods
70
70
  6. `private` & private instance methods
71
71
 
72
- ```
72
+ ```rbs
73
73
  class HelloWorld[X]
74
74
  def self.new: [A] () { (void) -> A } -> HelloWorld[A] # new or initialize comes first
75
75
  def initialize: () -> void
@@ -6,20 +6,20 @@ The purpose of this doc is to teach you how to write RBS signatures by using the
6
6
 
7
7
  ## Examples
8
8
 
9
+ In each example, the first snippet is for *Ruby* and the second one is for *RBS*.
10
+
9
11
  ### Zero argument methods
10
12
 
11
13
  **Example:** `String#empty?`
12
14
 
13
15
  ```ruby
14
- # .rb
15
16
  "".empty?
16
17
  # => true
17
18
  "hello".empty?
18
19
  # => false
19
20
  ```
20
21
 
21
- ```ruby
22
- # .rbs
22
+ ```rbs
23
23
  class String
24
24
  def empty?: () -> bool
25
25
  end
@@ -32,14 +32,13 @@ end
32
32
  **Example:** `String#include?`
33
33
 
34
34
  ```ruby
35
- # .rb
36
35
  "homeowner".include?("house")
37
36
  # => false
38
37
  "homeowner".include?("meow")
39
38
  # => true
40
39
  ```
41
40
 
42
- ```ruby
41
+ ```rbs
43
42
  class String
44
43
  def include?: (String) -> bool
45
44
  end
@@ -53,7 +52,6 @@ boolean value
53
52
  **Example:** `String#end_with?`
54
53
 
55
54
  ```ruby
56
- # .rb
57
55
  "hello?".end_with?("!")
58
56
  # => false
59
57
  "hello?".end_with?("?")
@@ -64,8 +62,7 @@ boolean value
64
62
  # => false
65
63
  ```
66
64
 
67
- ```ruby
68
- # .rbs
65
+ ```rbs
69
66
  class String
70
67
  def end_with?: (*String) -> bool
71
68
  end
@@ -79,7 +76,6 @@ returns a boolean value.
79
76
  **Example:** `String#ljust`
80
77
 
81
78
  ```ruby
82
- # .rb
83
79
  "hello".ljust(4)
84
80
  #=> "hello"
85
81
  "hello".ljust(20)
@@ -88,8 +84,7 @@ returns a boolean value.
88
84
  #=> "hello123412341234123"
89
85
  ```
90
86
 
91
- ```ruby
92
- # .rbs
87
+ ```rbs
93
88
  class String
94
89
  def ljust: (Integer, ?String) -> String
95
90
  end
@@ -102,7 +97,6 @@ end
102
97
  **Example:** `Array#*`
103
98
 
104
99
  ```ruby
105
- # .rb
106
100
  [1, 2, 3] * ","
107
101
  # => "1,2,3"
108
102
  [1, 2, 3] * 2
@@ -112,8 +106,7 @@ end
112
106
  *Note:* Some of the signatures after this point include type variables (e.g. `Elem`, `T`).
113
107
  For now, it's safe to ignore them, but they're included for completeness.
114
108
 
115
- ```ruby
116
- # .rbs
109
+ ```rbs
117
110
  class Array[Elem]
118
111
  def *: (String) -> String
119
112
  | (Integer) -> Array[Elem]
@@ -128,7 +121,6 @@ end
128
121
  **Example:** `String#<<`
129
122
 
130
123
  ```ruby
131
- # .rb
132
124
  a = "hello "
133
125
  a << "world"
134
126
  #=> "hello world"
@@ -136,8 +128,7 @@ a << 33
136
128
  #=> "hello world!"
137
129
  ```
138
130
 
139
- ```ruby
140
- # .rbs
131
+ ```rbs
141
132
  class String
142
133
  def <<: (String | Integer) -> String
143
134
  end
@@ -148,7 +139,6 @@ end
148
139
  ### Nilable types
149
140
 
150
141
  ```ruby
151
- # .rb
152
142
  [1, 2, 3].first
153
143
  # => 1
154
144
  [].first
@@ -159,8 +149,7 @@ end
159
149
  # => []
160
150
  ```
161
151
 
162
- ```ruby
163
- # .rbs
152
+ ```rbs
164
153
  class Enumerable[Elem]
165
154
  def first: () -> Elem?
166
155
  | (Integer) -> Array[Elem]
@@ -183,7 +172,6 @@ The `?` syntax is a convenient shorthand for a union with nil. An equivalent uni
183
172
  **Example**: `String#lines`
184
173
 
185
174
  ```ruby
186
- # .rb
187
175
  "hello\nworld\n".lines
188
176
  # => ["hello\n", "world\n"]
189
177
  "hello world".lines(' ')
@@ -192,8 +180,7 @@ The `?` syntax is a convenient shorthand for a union with nil. An equivalent uni
192
180
  # => ["hello", "world"]
193
181
  ```
194
182
 
195
- ```ruby
196
- # .rbs
183
+ ```rbs
197
184
  class String
198
185
  def lines: (?String, ?chomp: bool) -> Array[String]
199
186
  end
@@ -209,12 +196,11 @@ Keyword arguments are declared similar to in ruby, with the keyword immediately
209
196
  **Example**: `Time.now`
210
197
 
211
198
  ```ruby
212
- # .rb
213
199
  Time.now
214
200
  # => 2009-06-24 12:39:54 +0900
215
201
  ```
216
202
 
217
- ```ruby
203
+ ```rbs
218
204
  class Time
219
205
  def self.now: () -> Time
220
206
  end
@@ -228,7 +214,6 @@ end
228
214
  **Example**: `Array#filter`
229
215
 
230
216
  ```ruby
231
- # .rb
232
217
  [1,2,3,4,5].filter {|num| num.even? }
233
218
  # => [2, 4]
234
219
  %w[ a b c d e f ].filter {|v| v =~ /[aeiou]/ }
@@ -236,8 +221,7 @@ end
236
221
  [1,2,3,4,5].filter
237
222
  ```
238
223
 
239
- ```ruby
240
- # .rbs
224
+ ```rbs
241
225
  class Array[Elem]
242
226
  def filter: () { (Elem) -> boolish } -> ::Array[Elem]
243
227
  | () -> ::Enumerator[Elem, ::Array[Elem]]
@@ -260,8 +244,7 @@ h.keys
260
244
  # => ["a", "b", "c", "d"]
261
245
  ```
262
246
 
263
- ```ruby
264
- # .rbs
247
+ ```rbs
265
248
  class Hash[K, V]
266
249
  def keys: () -> Array[K]
267
250
  end
@@ -273,7 +256,6 @@ Generic types in RBS are parameterized at declaration time. These type variables
273
256
 
274
257
 
275
258
  ```ruby
276
- # .rb
277
259
  a = [ "a", "b", "c", "d" ]
278
260
  a.collect {|x| x + "!"}
279
261
  # => ["a!", "b!", "c!", "d!"]
@@ -281,8 +263,7 @@ a.collect.with_index {|x, i| x * i}
281
263
  # => ["", "b", "cc", "ddd"]
282
264
  ```
283
265
 
284
- ```ruby
285
- # .rbs
266
+ ```rbs
286
267
  class Array[Elem]
287
268
  def collect: [U] () { (Elem) -> U } -> Array[U]
288
269
  | () -> Enumerator[Elem, Array[untyped]]
@@ -302,7 +283,7 @@ In this example, the method receives its signature from the inferred return type
302
283
  # => [[2, 4, 6], [1, 3, 5]]
303
284
  ```
304
285
 
305
- ```ruby
286
+ ```rbs
306
287
  class Enumerable[Elem]
307
288
  def partition: () { (Elem) -> boolish } -> [Array[Elem], Array[Elem]]
308
289
  | () -> ::Enumerator[Elem, [Array[Elem], Array[Elem] ]]
@@ -318,7 +299,7 @@ Tuples can be of any size, and they can have mixed types.
318
299
  # => {1=>1, 2=>4, 3=>9, 4=>16, 5=>25}
319
300
  ```
320
301
 
321
- ```ruby
302
+ ```rbs
322
303
  class Enumerable[Elem]
323
304
  def to_h: () -> ::Hash[untyped, untyped]
324
305
  | [T, U] () { (Elem) -> [T, U] } -> ::Hash[T, U]
data/docs/repo.md CHANGED
@@ -13,7 +13,7 @@ Assume there is a rubygem called `bug-free-doodle` and our application depends o
13
13
 
14
14
  One workaround is to add type definitions of the library in the application signatures.
15
15
 
16
- ```
16
+ ```rbs
17
17
  # sig/polyfill/bug-free-doodle.rbs
18
18
 
19
19
  module Bug
data/docs/sigs.md CHANGED
@@ -18,7 +18,7 @@ See [syntax guide](syntax.md).
18
18
  When you finish writing signature, you may want to test the signature.
19
19
  rbs provides a feature to test your signature.
20
20
 
21
- ```
21
+ ```console
22
22
  $ RBS_TEST_TARGET='Foo::*' bundle exec ruby -r rbs/test/setup test/foo_test.rb
23
23
  ```
24
24
 
@@ -74,7 +74,7 @@ The `rbs` test framework tries to the best error message for overloaded methods
74
74
 
75
75
  The error is reported when a method is defined multiple times, as RBS does not allow duplicate method definitions. When you need to overload a method, use the `...` syntax:
76
76
 
77
- ```ruby
77
+ ```rbs
78
78
  # First definition
79
79
  class C
80
80
  def foo: () -> untyped
@@ -99,14 +99,14 @@ The design of the signature testing aims to be non-intrusive. The setup is done
99
99
  You need to require `rbs/test/setup` for signature testing.
100
100
  You can do it using `-r` option through command line argument or the `RUBYOPT` environment variable.
101
101
 
102
- ```
102
+ ```console
103
103
  $ ruby -r rbs/test/setup run_tests.rb
104
104
  $ RUBYOPT='-rrbs/test/setup' rake test
105
105
  ```
106
106
 
107
107
  When you are using Bundler, you may need to require `bundler/setup` explicitly.
108
108
 
109
- ```
109
+ ```console
110
110
  $ RUBYOPT='-rbundler/setup -rrbs/test/setup' bundle exec rake test
111
111
  ```
112
112
 
@@ -130,7 +130,7 @@ You need to specify `RBS_TEST_TARGET` to run the test, and you can customize the
130
130
  You may need to specify `-r` or `-I` to load signatures.
131
131
  The default is `-I sig`.
132
132
 
133
- ```
133
+ ```shell
134
134
  RBS_TEST_OPT='-r pathname -I sig'
135
135
  ```
136
136
 
@@ -144,7 +144,7 @@ You can see the backtrace how the type error is caused and debug your program or
144
144
 
145
145
  So, a typical command line to start the test would look like the following:
146
146
 
147
- ```
147
+ ```console
148
148
  $ RBS_TEST_LOGLEVEL=error \
149
149
  RBS_TEST_TARGET='Kaigi::*' \
150
150
  RBS_TEST_SKIP='Kaigi::MonkeyPatch' \
@@ -160,7 +160,7 @@ $ RBS_TEST_LOGLEVEL=error \
160
160
 
161
161
  You can skip installing the instrumentation per-method basis using `rbs:test:skip` annotation.
162
162
 
163
- ```
163
+ ```rbs
164
164
  class String
165
165
  %a{rbs:test:skip} def =~: (Regexp) -> Integer?
166
166
  end
data/docs/stdlib.md CHANGED
@@ -10,7 +10,7 @@ We support writing tests for core/stdlib signatures.
10
10
 
11
11
  First, execute `generate:stdlib_test` rake task with a class name that you want to test.
12
12
 
13
- ```bash
13
+ ```console
14
14
  $ bundle exec rake 'generate:stdlib_test[String]'
15
15
  Created: test/stdlib/String_test.rb
16
16
  ```
@@ -47,7 +47,6 @@ end
47
47
  class StringTest < Test::Unit::TestCase
48
48
  include TypeAssertions
49
49
 
50
- # library "pathname", "set", "securerandom" # Declare library signatures to load
51
50
  testing "::String"
52
51
 
53
52
  def test_gsub
@@ -83,7 +82,7 @@ If the execution of the program escape from the class definition, the instrument
83
82
 
84
83
  You can run the test with:
85
84
 
86
- ```
85
+ ```console
87
86
  $ bundle exec rake stdlib_test # Run all tests
88
87
  $ bundle exec ruby test/stdlib/String_test.rb # Run specific tests
89
88
  ```