steep 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (299) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +27 -0
  3. data/.gitmodules +3 -0
  4. data/CHANGELOG.md +5 -0
  5. data/README.md +48 -90
  6. data/Rakefile +10 -6
  7. data/Steepfile +1 -0
  8. data/bin/setup +1 -0
  9. data/bin/smoke_runner.rb +9 -14
  10. data/exe/rbs +3 -0
  11. data/exe/ruby-signature +3 -0
  12. data/exe/steep +1 -0
  13. data/lib/steep.rb +32 -26
  14. data/lib/steep/annotation_parser.rb +167 -0
  15. data/lib/steep/ast/annotation/collection.rb +7 -7
  16. data/lib/steep/ast/types.rb +60 -0
  17. data/lib/steep/ast/types/any.rb +1 -1
  18. data/lib/steep/ast/types/factory.rb +535 -0
  19. data/lib/steep/ast/types/name.rb +3 -3
  20. data/lib/steep/ast/types/var.rb +1 -1
  21. data/lib/steep/cli.rb +56 -240
  22. data/lib/steep/drivers/annotations.rb +36 -19
  23. data/lib/steep/drivers/check.rb +55 -91
  24. data/lib/steep/drivers/init.rb +54 -0
  25. data/lib/steep/drivers/langserver.rb +241 -150
  26. data/lib/steep/drivers/print_project.rb +56 -0
  27. data/lib/steep/drivers/signature_error_printer.rb +25 -0
  28. data/lib/steep/drivers/trace_printer.rb +25 -0
  29. data/lib/steep/drivers/utils/driver_helper.rb +26 -0
  30. data/lib/steep/drivers/validate.rb +18 -38
  31. data/lib/steep/drivers/vendor.rb +46 -0
  32. data/lib/steep/drivers/watch.rb +78 -140
  33. data/lib/steep/errors.rb +22 -13
  34. data/lib/steep/interface/interface.rb +91 -0
  35. data/lib/steep/interface/method.rb +0 -4
  36. data/lib/steep/interface/method_type.rb +362 -2
  37. data/lib/steep/interface/substitution.rb +22 -0
  38. data/lib/steep/project.rb +25 -233
  39. data/lib/steep/project/dsl.rb +132 -0
  40. data/lib/steep/project/file.rb +93 -76
  41. data/lib/steep/project/file_loader.rb +63 -0
  42. data/lib/steep/project/options.rb +7 -0
  43. data/lib/steep/project/target.rb +190 -0
  44. data/lib/steep/signature/errors.rb +25 -77
  45. data/lib/steep/signature/validator.rb +122 -0
  46. data/lib/steep/source.rb +12 -7
  47. data/lib/steep/subtyping/check.rb +357 -633
  48. data/lib/steep/subtyping/constraints.rb +2 -2
  49. data/lib/steep/subtyping/trace.rb +23 -0
  50. data/lib/steep/type_construction.rb +509 -455
  51. data/lib/steep/type_inference/constant_env.rb +16 -24
  52. data/lib/steep/type_inference/type_env.rb +26 -18
  53. data/lib/steep/version.rb +1 -1
  54. data/sample/Steepfile +6 -0
  55. data/sample/lib/conference.rb +12 -0
  56. data/sample/sig/conference.rbs +6 -0
  57. data/smoke/alias/Steepfile +4 -0
  58. data/smoke/alias/a.rb +2 -2
  59. data/smoke/alias/{a.rbi → a.rbs} +1 -1
  60. data/smoke/and/Steepfile +4 -0
  61. data/smoke/array/Steepfile +4 -0
  62. data/smoke/array/a.rb +2 -2
  63. data/smoke/array/b.rb +4 -4
  64. data/smoke/array/c.rb +2 -2
  65. data/smoke/block/Steepfile +5 -0
  66. data/smoke/block/{a.rbi → a.rbs} +1 -1
  67. data/smoke/block/{c.rbi → c.rbs} +0 -0
  68. data/smoke/block/d.rb +6 -6
  69. data/smoke/case/Steepfile +4 -0
  70. data/smoke/case/a.rb +4 -3
  71. data/smoke/class/Steepfile +4 -0
  72. data/smoke/class/a.rb +1 -4
  73. data/smoke/class/a.rbs +24 -0
  74. data/smoke/class/h.rb +6 -2
  75. data/smoke/class/{h.rbi → h.rbs} +1 -2
  76. data/smoke/class/i.rb +1 -2
  77. data/smoke/class/i.rbs +9 -0
  78. data/smoke/const/Steepfile +4 -0
  79. data/smoke/dstr/Steepfile +4 -0
  80. data/smoke/ensure/Steepfile +4 -0
  81. data/smoke/ensure/a.rb +1 -1
  82. data/smoke/enumerator/Steepfile +4 -0
  83. data/smoke/enumerator/a.rb +7 -7
  84. data/smoke/enumerator/b.rb +6 -6
  85. data/smoke/extension/Steepfile +4 -0
  86. data/smoke/extension/{a.rbi → a.rbs} +2 -2
  87. data/smoke/extension/{e.rbi → e.rbs} +2 -2
  88. data/smoke/hash/Steepfile +4 -0
  89. data/smoke/hash/{a.rbi → a.rbs} +0 -0
  90. data/smoke/hash/b.rb +2 -2
  91. data/smoke/hash/c.rb +1 -1
  92. data/smoke/hash/e.rbs +3 -0
  93. data/smoke/hash/f.rb +1 -1
  94. data/smoke/hello/Steepfile +4 -0
  95. data/smoke/hello/hello.rbs +7 -0
  96. data/smoke/if/Steepfile +4 -0
  97. data/smoke/implements/Steepfile +4 -0
  98. data/smoke/implements/a.rbs +6 -0
  99. data/smoke/initialize/Steepfile +4 -0
  100. data/smoke/initialize/a.rbs +3 -0
  101. data/smoke/integer/Steepfile +4 -0
  102. data/smoke/integer/a.rb +5 -3
  103. data/smoke/interface/Steepfile +4 -0
  104. data/smoke/interface/{a.rbi → a.rbs} +0 -0
  105. data/smoke/kwbegin/Steepfile +4 -0
  106. data/smoke/lambda/Steepfile +4 -0
  107. data/smoke/lambda/a.rb +9 -2
  108. data/smoke/literal/Steepfile +4 -0
  109. data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
  110. data/smoke/map/Steepfile +4 -0
  111. data/smoke/map/a.rb +1 -1
  112. data/smoke/method/Steepfile +4 -0
  113. data/smoke/method/{a.rbi → a.rbs} +0 -0
  114. data/smoke/method/b.rb +1 -4
  115. data/smoke/method/d.rb +1 -0
  116. data/smoke/method/d.rbs +3 -0
  117. data/smoke/module/Steepfile +4 -0
  118. data/smoke/module/a.rb +1 -1
  119. data/smoke/module/a.rbs +16 -0
  120. data/smoke/module/c.rb +1 -1
  121. data/smoke/regexp/Steepfile +4 -0
  122. data/smoke/regexp/a.rb +2 -2
  123. data/smoke/regexp/b.rb +16 -16
  124. data/smoke/regression/Steepfile +5 -0
  125. data/smoke/regression/array.rb +2 -2
  126. data/smoke/regression/hash.rb +2 -2
  127. data/smoke/regression/poly_new.rb +2 -0
  128. data/smoke/regression/poly_new.rbs +4 -0
  129. data/smoke/regression/set_divide.rb +2 -2
  130. data/smoke/rescue/Steepfile +4 -0
  131. data/smoke/rescue/a.rb +1 -1
  132. data/smoke/self/Steepfile +4 -0
  133. data/smoke/self/a.rbs +4 -0
  134. data/smoke/skip/Steepfile +4 -0
  135. data/smoke/stdout/Steepfile +4 -0
  136. data/smoke/stdout/{a.rbi → a.rbs} +1 -1
  137. data/smoke/super/Steepfile +4 -0
  138. data/smoke/super/a.rbs +10 -0
  139. data/smoke/type_case/Steepfile +4 -0
  140. data/smoke/type_case/a.rb +1 -1
  141. data/smoke/yield/Steepfile +4 -0
  142. data/smoke/yield/a.rb +2 -2
  143. data/steep.gemspec +14 -7
  144. data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
  145. data/vendor/ruby-signature/.gitignore +12 -0
  146. data/vendor/ruby-signature/.rubocop.yml +15 -0
  147. data/vendor/ruby-signature/BSDL +22 -0
  148. data/vendor/ruby-signature/COPYING +56 -0
  149. data/vendor/ruby-signature/Gemfile +6 -0
  150. data/vendor/ruby-signature/README.md +93 -0
  151. data/vendor/ruby-signature/Rakefile +66 -0
  152. data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
  153. data/vendor/ruby-signature/bin/console +14 -0
  154. data/vendor/ruby-signature/bin/query-rdoc +103 -0
  155. data/vendor/ruby-signature/bin/setup +10 -0
  156. data/vendor/ruby-signature/bin/sort +88 -0
  157. data/vendor/ruby-signature/bin/test_runner.rb +17 -0
  158. data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
  159. data/vendor/ruby-signature/docs/sigs.md +148 -0
  160. data/vendor/ruby-signature/docs/stdlib.md +152 -0
  161. data/vendor/ruby-signature/docs/syntax.md +528 -0
  162. data/vendor/ruby-signature/exe/rbs +3 -0
  163. data/vendor/ruby-signature/exe/ruby-signature +7 -0
  164. data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
  165. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
  166. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
  167. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
  168. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
  169. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
  170. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
  171. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
  172. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
  173. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
  174. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
  175. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
  176. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
  177. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
  178. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
  179. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
  180. data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
  181. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
  182. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
  183. data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
  184. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
  185. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
  186. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
  187. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
  188. data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
  189. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
  190. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
  191. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
  192. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
  193. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
  194. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
  195. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
  196. data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
  197. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
  198. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
  199. data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
  200. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
  201. data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
  202. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
  203. data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
  204. data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
  205. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
  206. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
  207. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
  208. data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
  209. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
  210. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
  211. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
  212. data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
  213. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
  214. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
  215. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
  216. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
  217. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
  218. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
  219. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
  220. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
  221. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
  222. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
  223. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
  224. data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
  225. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
  226. data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
  227. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
  228. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
  229. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
  230. data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
  231. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
  232. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
  233. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
  234. data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
  235. data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
  236. data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
  237. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
  238. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
  239. data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
  240. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
  241. data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
  242. data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
  243. data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
  244. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
  245. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
  246. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
  247. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
  248. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
  249. data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
  250. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
  251. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
  252. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
  253. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
  254. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
  255. data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
  256. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
  257. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
  258. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
  259. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
  260. data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
  261. data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
  262. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
  263. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
  264. data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
  265. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
  266. data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
  267. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
  268. metadata +244 -54
  269. data/.travis.yml +0 -7
  270. data/lib/steep/ast/signature/alias.rb +0 -19
  271. data/lib/steep/ast/signature/class.rb +0 -33
  272. data/lib/steep/ast/signature/const.rb +0 -17
  273. data/lib/steep/ast/signature/env.rb +0 -138
  274. data/lib/steep/ast/signature/extension.rb +0 -21
  275. data/lib/steep/ast/signature/gvar.rb +0 -17
  276. data/lib/steep/ast/signature/interface.rb +0 -31
  277. data/lib/steep/ast/signature/members.rb +0 -115
  278. data/lib/steep/ast/signature/module.rb +0 -21
  279. data/lib/steep/drivers/print_interface.rb +0 -94
  280. data/lib/steep/drivers/scaffold.rb +0 -321
  281. data/lib/steep/drivers/utils/each_signature.rb +0 -31
  282. data/lib/steep/interface/abstract.rb +0 -68
  283. data/lib/steep/interface/builder.rb +0 -637
  284. data/lib/steep/interface/instantiated.rb +0 -163
  285. data/lib/steep/interface/ivar_chain.rb +0 -26
  286. data/lib/steep/parser.y +0 -1278
  287. data/lib/steep/project/listener.rb +0 -53
  288. data/smoke/class/a.rbi +0 -24
  289. data/smoke/class/d.rb +0 -9
  290. data/smoke/class/e.rb +0 -12
  291. data/smoke/class/i.rbi +0 -9
  292. data/smoke/hash/e.rbi +0 -3
  293. data/smoke/hello/hello.rbi +0 -7
  294. data/smoke/implements/a.rbi +0 -6
  295. data/smoke/initialize/a.rbi +0 -3
  296. data/smoke/module/a.rbi +0 -16
  297. data/smoke/self/a.rbi +0 -4
  298. data/smoke/super/a.rbi +0 -10
  299. data/stdlib/builtin.rbi +0 -787
@@ -0,0 +1,248 @@
1
+ # A `Module` is a collection of methods and constants. The methods in a
2
+ # module may be instance methods or module methods. Instance methods
3
+ # appear as methods in a class when the module is included, module methods
4
+ # do not. Conversely, module methods may be called without creating an
5
+ # encapsulating object, while instance methods may not. (See
6
+ # `Module#module_function` .)
7
+ #
8
+ # In the descriptions that follow, the parameter *sym* refers to a symbol,
9
+ # which is either a quoted string or a `Symbol` (such as `:name` ).
10
+ #
11
+ # ```ruby
12
+ # module Mod
13
+ # include Math
14
+ # CONST = 1
15
+ # def meth
16
+ # # ...
17
+ # end
18
+ # end
19
+ # Mod.class #=> Module
20
+ # Mod.constants #=> [:CONST, :PI, :E]
21
+ # Mod.instance_methods #=> [:meth]
22
+ # ```
23
+ class Module < Object
24
+ # In the first form, returns an array of the names of all constants
25
+ # accessible from the point of call. This list includes the names of all
26
+ # modules and classes defined in the global scope.
27
+ #
28
+ # ```ruby
29
+ # Module.constants.first(4)
30
+ # # => [:ARGF, :ARGV, :ArgumentError, :Array]
31
+ #
32
+ # Module.constants.include?(:SEEK_SET) # => false
33
+ #
34
+ # class IO
35
+ # Module.constants.include?(:SEEK_SET) # => true
36
+ # end
37
+ # ```
38
+ #
39
+ # The second form calls the instance method `constants` .
40
+ def self.constants: () -> ::Array[Integer]
41
+
42
+ # Returns the list of `Modules` nested at the point of call.
43
+ #
44
+ # ```ruby
45
+ # module M1
46
+ # module M2
47
+ # $a = Module.nesting
48
+ # end
49
+ # end
50
+ # $a #=> [M1::M2, M1]
51
+ # $a[0].name #=> "M1::M2"
52
+ # ```
53
+ def self.nesting: () -> ::Array[Module]
54
+
55
+ def self.used_modules: () -> ::Array[Module]
56
+
57
+ def <: (Module other) -> bool?
58
+
59
+ def <=: (Module other) -> bool?
60
+
61
+ def <=>: (Module other) -> Integer?
62
+
63
+ def ==: (untyped other) -> bool
64
+
65
+ def ===: (untyped other) -> bool
66
+
67
+ def >: (Module other) -> bool?
68
+
69
+ def >=: (Module other) -> bool?
70
+
71
+ def alias_method: (Symbol new_name, Symbol old_name) -> self
72
+
73
+ # Returns a list of modules included/prepended in *mod* (including *mod*
74
+ # itself).
75
+ #
76
+ # ```ruby
77
+ # module Mod
78
+ # include Math
79
+ # include Comparable
80
+ # prepend Enumerable
81
+ # end
82
+ #
83
+ # Mod.ancestors #=> [Enumerable, Mod, Comparable, Math]
84
+ # Math.ancestors #=> [Math]
85
+ # Enumerable.ancestors #=> [Enumerable]
86
+ # ```
87
+ def ancestors: () -> ::Array[Module]
88
+
89
+ def append_features: (Module arg0) -> self
90
+
91
+ def `attr_accessor`: (*Symbol | String arg0) -> NilClass
92
+
93
+ def `attr_reader`: (*Symbol | String arg0) -> NilClass
94
+
95
+ def `attr_writer`: (*Symbol | String arg0) -> NilClass
96
+
97
+ def autoload: (Symbol _module, String filename) -> NilClass
98
+
99
+ def autoload?: (Symbol name) -> String?
100
+
101
+ def class_eval: (String arg0, ?String filename, ?Integer lineno) -> untyped
102
+ | [U] (untyped arg0) { (untyped m) -> U } -> U
103
+
104
+ def class_exec: (*untyped args) { () -> untyped } -> untyped
105
+
106
+ def class_variable_defined?: (Symbol | String arg0) -> bool
107
+
108
+ def class_variable_get: (Symbol | String arg0) -> untyped
109
+
110
+ def class_variable_set: (Symbol | String arg0, untyped arg1) -> untyped
111
+
112
+ def class_variables: (?bool inherit) -> ::Array[Symbol]
113
+
114
+ def const_defined?: (Symbol | String arg0, ?bool inherit) -> bool
115
+
116
+ def const_get: (Symbol | String arg0, ?bool inherit) -> untyped
117
+
118
+ def const_missing: (Symbol arg0) -> untyped
119
+
120
+ def const_set: (Symbol | String arg0, untyped arg1) -> untyped
121
+
122
+ def constants: (?bool inherit) -> ::Array[Symbol]
123
+
124
+ def define_method: (Symbol | String arg0, ?Proc | Method | UnboundMethod arg1) -> Symbol
125
+ | (Symbol | String arg0) { () -> untyped } -> Symbol
126
+
127
+ def eql?: (untyped other) -> bool
128
+
129
+ def equal?: (untyped other) -> bool
130
+
131
+ def extend_object: (untyped arg0) -> untyped
132
+
133
+ def extended: (Module othermod) -> untyped
134
+
135
+ # Prevents further modifications to *mod* .
136
+ #
137
+ # This method returns self.
138
+ def freeze: () -> self
139
+
140
+ def `include`: (*Module arg0) -> self
141
+
142
+ def `include?`: (Module arg0) -> bool
143
+
144
+ def included: (Module othermod) -> untyped
145
+
146
+ # Returns the list of modules included in *mod* .
147
+ #
148
+ # ```ruby
149
+ # module Mixin
150
+ # end
151
+ #
152
+ # module Outer
153
+ # include Mixin
154
+ # end
155
+ #
156
+ # Mixin.included_modules #=> []
157
+ # Outer.included_modules #=> [Mixin]
158
+ # ```
159
+ def included_modules: () -> ::Array[Module]
160
+
161
+ def initialize: () -> Object
162
+ | () { (Module arg0) -> untyped } -> void
163
+
164
+ def instance_method: (Symbol arg0) -> UnboundMethod
165
+
166
+ def instance_methods: (?bool include_super) -> ::Array[Symbol]
167
+
168
+ def method_added: (Symbol meth) -> untyped
169
+
170
+ def method_defined?: (Symbol | String arg0) -> bool
171
+
172
+ def method_removed: (Symbol method_name) -> untyped
173
+
174
+ def module_eval: (String arg0, ?String filename, ?Integer lineno) -> untyped
175
+ | [U] (untyped arg0) { (untyped m) -> U } -> U
176
+
177
+ def module_exec: (*untyped args) { () -> untyped } -> untyped
178
+
179
+ def module_function: (*Symbol | String arg0) -> self
180
+
181
+ # Returns the name of the module *mod* . Returns nil for anonymous
182
+ # modules.
183
+ def name: () -> String?
184
+
185
+ def `prepend`: (*Module arg0) -> self
186
+
187
+ def prepend_features: (Module arg0) -> self
188
+
189
+ def prepended: (Module othermod) -> untyped
190
+
191
+ def `private`: (*Symbol | String arg0) -> self
192
+
193
+ def private_class_method: (*Symbol | String arg0) -> self
194
+
195
+ def private_constant: (*Symbol arg0) -> self
196
+
197
+ def private_instance_methods: (?bool include_super) -> ::Array[Symbol]
198
+
199
+ def private_method_defined?: (Symbol | String arg0) -> bool
200
+
201
+ def protected: (*Symbol | String arg0) -> self
202
+
203
+ def protected_instance_methods: (?bool include_super) -> ::Array[Symbol]
204
+
205
+ def protected_method_defined?: (Symbol | String arg0) -> bool
206
+
207
+ def `public`: (*Symbol | String arg0) -> self
208
+
209
+ def public_class_method: (*Symbol | String arg0) -> self
210
+
211
+ def public_constant: (*Symbol arg0) -> self
212
+
213
+ def public_instance_method: (Symbol arg0) -> UnboundMethod
214
+
215
+ def public_instance_methods: (?bool include_super) -> ::Array[Symbol]
216
+
217
+ def public_method_defined?: (Symbol | String arg0) -> bool
218
+
219
+ def refine: (Class arg0) { (untyped arg0) -> untyped } -> self
220
+
221
+ def remove_class_variable: (Symbol arg0) -> untyped
222
+
223
+ def remove_const: (Symbol arg0) -> untyped
224
+
225
+ def remove_method: (Symbol | String arg0) -> self
226
+
227
+ # Returns `true` if *mod* is a singleton class or `false` if it is an
228
+ # ordinary class or module.
229
+ #
230
+ # ```ruby
231
+ # class C
232
+ # end
233
+ # C.singleton_class? #=> false
234
+ # C.singleton_class.singleton_class? #=> true
235
+ # ```
236
+ def `singleton_class?`: () -> bool
237
+
238
+ def to_s: () -> String
239
+
240
+ def undefMethod: (Symbol | String arg0) -> self
241
+
242
+ def using: (Module arg0) -> self
243
+
244
+ # Alias for: [to\_s](Module.downloaded.ruby_doc#method-i-to_s)
245
+ def inspect: () -> String
246
+
247
+ def attr: (*Symbol | String arg0) -> NilClass
248
+ end
@@ -0,0 +1,82 @@
1
+ # The class of the singleton object `nil`.
2
+ #
3
+ class NilClass
4
+ public
5
+
6
+ # And---Returns `false`. *obj* is always evaluated as it is the argument to a
7
+ # method call---there is no short-circuit evaluation in this case.
8
+ #
9
+ def &: (untyped obj) -> bool
10
+
11
+ # Case Equality -- For class Object, effectively the same as calling `#==`, but
12
+ # typically overridden by descendants to provide meaningful semantics in `case`
13
+ # statements.
14
+ #
15
+ def ===: (nil) -> true
16
+ | (untyped obj) -> bool
17
+
18
+ # Dummy pattern matching -- always returns nil.
19
+ #
20
+ def =~: (untyped obj) -> nil
21
+
22
+ # Exclusive Or---If *obj* is `nil` or `false`, returns `false`; otherwise,
23
+ # returns `true`.
24
+ #
25
+ def ^: (nil) -> false
26
+ | (false) -> false
27
+ | (untyped obj) -> bool
28
+
29
+ # Always returns the string "nil".
30
+ #
31
+ def inspect: () -> "nil"
32
+
33
+ # Only the object *nil* responds `true` to `nil?`.
34
+ #
35
+ def nil?: () -> bool
36
+
37
+ # Returns zero as a rational. The optional argument `eps` is always ignored.
38
+ #
39
+ def rationalize: (?untyped eps) -> Rational
40
+
41
+ # Always returns an empty array.
42
+ #
43
+ # nil.to_a #=> []
44
+ #
45
+ def to_a: () -> [ ]
46
+
47
+ # Returns zero as a complex.
48
+ #
49
+ def to_c: () -> Complex
50
+
51
+ # Always returns zero.
52
+ #
53
+ # nil.to_f #=> 0.0
54
+ #
55
+ def to_f: () -> Float
56
+
57
+ # Always returns an empty hash.
58
+ #
59
+ # nil.to_h #=> {}
60
+ #
61
+ def to_h: () -> ::Hash[untyped, untyped]
62
+
63
+ # Always returns zero.
64
+ #
65
+ # nil.to_i #=> 0
66
+ #
67
+ def to_i: () -> 0
68
+
69
+ # Returns zero as a rational.
70
+ #
71
+ def to_r: () -> Rational
72
+
73
+ # Always returns the empty string.
74
+ #
75
+ def to_s: () -> ""
76
+
77
+ # Or---Returns `false` if *obj* is `nil` or `false`; `true` otherwise.
78
+ #
79
+ def |: (nil) -> false
80
+ | (false) -> false
81
+ | (untyped obj) -> bool
82
+ end
@@ -0,0 +1,409 @@
1
+ # Numeric is the class from which all higher-level numeric classes should
2
+ # inherit.
3
+ #
4
+ # Numeric allows instantiation of heap-allocated objects. Other core numeric
5
+ # classes such as Integer are implemented as immediates, which means that each
6
+ # Integer is a single immutable object which is always passed by value.
7
+ #
8
+ # a = 1
9
+ # 1.object_id == a.object_id #=> true
10
+ #
11
+ # There can only ever be one instance of the integer `1`, for example. Ruby
12
+ # ensures this by preventing instantiation. If duplication is attempted, the
13
+ # same instance is returned.
14
+ #
15
+ # Integer.new(1) #=> NoMethodError: undefined method `new' for Integer:Class
16
+ # 1.dup #=> 1
17
+ # 1.object_id == 1.dup.object_id #=> true
18
+ #
19
+ # For this reason, Numeric should be used when defining other numeric classes.
20
+ #
21
+ # Classes which inherit from Numeric must implement `coerce`, which returns a
22
+ # two-member Array containing an object that has been coerced into an instance
23
+ # of the new class and `self` (see #coerce).
24
+ #
25
+ # Inheriting classes should also implement arithmetic operator methods (`+`,
26
+ # `-`, `*` and `/`) and the `<=>` operator (see Comparable). These methods may
27
+ # rely on `coerce` to ensure interoperability with instances of other numeric
28
+ # classes.
29
+ #
30
+ # class Tally < Numeric
31
+ # def initialize(string)
32
+ # @string = string
33
+ # end
34
+ #
35
+ # def to_s
36
+ # @string
37
+ # end
38
+ #
39
+ # def to_i
40
+ # @string.size
41
+ # end
42
+ #
43
+ # def coerce(other)
44
+ # [self.class.new('|' * other.to_i), self]
45
+ # end
46
+ #
47
+ # def <=>(other)
48
+ # to_i <=> other.to_i
49
+ # end
50
+ #
51
+ # def +(other)
52
+ # self.class.new('|' * (to_i + other.to_i))
53
+ # end
54
+ #
55
+ # def -(other)
56
+ # self.class.new('|' * (to_i - other.to_i))
57
+ # end
58
+ #
59
+ # def *(other)
60
+ # self.class.new('|' * (to_i * other.to_i))
61
+ # end
62
+ #
63
+ # def /(other)
64
+ # self.class.new('|' * (to_i / other.to_i))
65
+ # end
66
+ # end
67
+ #
68
+ # tally = Tally.new('||')
69
+ # puts tally * 2 #=> "||||"
70
+ # puts tally > 1 #=> true
71
+ #
72
+ class Numeric
73
+ include Comparable
74
+
75
+ public
76
+
77
+ # `x.modulo(y)` means `x-y*(x/y).floor`.
78
+ #
79
+ # Equivalent to `num.divmod(numeric)[1]`.
80
+ #
81
+ # See Numeric#divmod.
82
+ #
83
+ def %: (Numeric) -> Numeric
84
+
85
+ # Unary Plus---Returns the receiver.
86
+ #
87
+ def +@: () -> Numeric
88
+
89
+ # Unary Minus---Returns the receiver, negated.
90
+ #
91
+ def -@: () -> Numeric
92
+
93
+ # Returns zero if `number` equals `other`, otherwise returns `nil`.
94
+ #
95
+ def <=>: (Numeric other) -> Integer
96
+
97
+ # Returns the absolute value of `num`.
98
+ #
99
+ # 12.abs #=> 12
100
+ # (-34.56).abs #=> 34.56
101
+ # -34.56.abs #=> 34.56
102
+ #
103
+ # Numeric#magnitude is an alias for Numeric#abs.
104
+ #
105
+ def abs: () -> Numeric
106
+
107
+ # Returns square of self.
108
+ #
109
+ def abs2: () -> Numeric
110
+
111
+ # Returns 0 if the value is positive, pi otherwise.
112
+ #
113
+ def angle: () -> Numeric
114
+
115
+ # Returns 0 if the value is positive, pi otherwise.
116
+ #
117
+ alias arg angle
118
+
119
+ # Returns the smallest number greater than or equal to `num` with a precision of
120
+ # `ndigits` decimal digits (default: 0).
121
+ #
122
+ # Numeric implements this by converting its value to a Float and invoking
123
+ # Float#ceil.
124
+ #
125
+ def ceil: () -> Integer
126
+ | (Integer digits) -> (Integer | Numeric)
127
+
128
+ # If `numeric` is the same type as `num`, returns an array `[numeric, num]`.
129
+ # Otherwise, returns an array with both `numeric` and `num` represented as Float
130
+ # objects.
131
+ #
132
+ # This coercion mechanism is used by Ruby to handle mixed-type numeric
133
+ # operations: it is intended to find a compatible common type between the two
134
+ # operands of the operator.
135
+ #
136
+ # 1.coerce(2.5) #=> [2.5, 1.0]
137
+ # 1.2.coerce(3) #=> [3.0, 1.2]
138
+ # 1.coerce(2) #=> [2, 1]
139
+ #
140
+ def coerce: (Numeric) -> [ Numeric, Numeric ]
141
+
142
+ # Returns self.
143
+ #
144
+ def conj: () -> Numeric
145
+
146
+ # Returns self.
147
+ #
148
+ def conjugate: () -> Numeric
149
+
150
+ # Returns the denominator (always positive).
151
+ #
152
+ def denominator: () -> Integer
153
+
154
+ # Uses `/` to perform division, then converts the result to an integer. Numeric
155
+ # does not define the `/` operator; this is left to subclasses.
156
+ #
157
+ # Equivalent to `num.divmod(numeric)[0]`.
158
+ #
159
+ # See Numeric#divmod.
160
+ #
161
+ def div: (Numeric) -> Integer
162
+
163
+ # Returns an array containing the quotient and modulus obtained by dividing
164
+ # `num` by `numeric`.
165
+ #
166
+ # If `q, r = x.divmod(y)`, then
167
+ #
168
+ # q = floor(x/y)
169
+ # x = q*y + r
170
+ #
171
+ # The quotient is rounded toward negative infinity, as shown in the following
172
+ # table:
173
+ #
174
+ # a | b | a.divmod(b) | a/b | a.modulo(b) | a.remainder(b)
175
+ # ------+-----+---------------+---------+-------------+---------------
176
+ # 13 | 4 | 3, 1 | 3 | 1 | 1
177
+ # ------+-----+---------------+---------+-------------+---------------
178
+ # 13 | -4 | -4, -3 | -4 | -3 | 1
179
+ # ------+-----+---------------+---------+-------------+---------------
180
+ # -13 | 4 | -4, 3 | -4 | 3 | -1
181
+ # ------+-----+---------------+---------+-------------+---------------
182
+ # -13 | -4 | 3, -1 | 3 | -1 | -1
183
+ # ------+-----+---------------+---------+-------------+---------------
184
+ # 11.5 | 4 | 2, 3.5 | 2.875 | 3.5 | 3.5
185
+ # ------+-----+---------------+---------+-------------+---------------
186
+ # 11.5 | -4 | -3, -0.5 | -2.875 | -0.5 | 3.5
187
+ # ------+-----+---------------+---------+-------------+---------------
188
+ # -11.5 | 4 | -3, 0.5 | -2.875 | 0.5 | -3.5
189
+ # ------+-----+---------------+---------+-------------+---------------
190
+ # -11.5 | -4 | 2, -3.5 | 2.875 | -3.5 | -3.5
191
+ #
192
+ # Examples
193
+ #
194
+ # 11.divmod(3) #=> [3, 2]
195
+ # 11.divmod(-3) #=> [-4, -1]
196
+ # 11.divmod(3.5) #=> [3, 0.5]
197
+ # (-11).divmod(3.5) #=> [-4, 3.0]
198
+ # 11.5.divmod(3.5) #=> [3, 1.0]
199
+ #
200
+ def divmod: (Numeric) -> [ Numeric, Numeric ]
201
+
202
+ # Returns `true` if `num` and `numeric` are the same type and have equal values.
203
+ # Contrast this with Numeric#==, which performs type conversions.
204
+ #
205
+ # 1 == 1.0 #=> true
206
+ # 1.eql?(1.0) #=> false
207
+ # 1.0.eql?(1.0) #=> true
208
+ #
209
+ def eql?: (untyped) -> bool
210
+
211
+ # Returns float division.
212
+ #
213
+ def fdiv: (Numeric) -> Numeric
214
+
215
+ # Returns `true` if `num` is a finite number, otherwise returns `false`.
216
+ #
217
+ def finite?: () -> bool
218
+
219
+ # Returns the largest number less than or equal to `num` with a precision of
220
+ # `ndigits` decimal digits (default: 0).
221
+ #
222
+ # Numeric implements this by converting its value to a Float and invoking
223
+ # Float#floor.
224
+ #
225
+ def floor: () -> Integer
226
+ | (Integer digits) -> Numeric
227
+
228
+ # Returns the corresponding imaginary number. Not available for complex numbers.
229
+ #
230
+ # -42.i #=> (0-42i)
231
+ # 2.0.i #=> (0+2.0i)
232
+ #
233
+ def i: () -> Complex
234
+
235
+ # Returns zero.
236
+ #
237
+ def imag: () -> Numeric
238
+
239
+ # Returns zero.
240
+ #
241
+ def imaginary: () -> Numeric
242
+
243
+ # Returns `nil`, -1, or 1 depending on whether the value is finite, `-Infinity`,
244
+ # or `+Infinity`.
245
+ #
246
+ def infinite?: () -> Integer?
247
+
248
+ # Returns `true` if `num` is an Integer.
249
+ #
250
+ # 1.0.integer? #=> false
251
+ # 1.integer? #=> true
252
+ #
253
+ def integer?: () -> bool
254
+
255
+ # Returns the absolute value of `num`.
256
+ #
257
+ # 12.abs #=> 12
258
+ # (-34.56).abs #=> 34.56
259
+ # -34.56.abs #=> 34.56
260
+ #
261
+ # Numeric#magnitude is an alias for Numeric#abs.
262
+ #
263
+ alias magnitude abs
264
+
265
+ # `x.modulo(y)` means `x-y*(x/y).floor`.
266
+ #
267
+ # Equivalent to `num.divmod(numeric)[1]`.
268
+ #
269
+ # See Numeric#divmod.
270
+ #
271
+ def modulo: (Numeric) -> Numeric
272
+
273
+ # Returns `true` if `num` is less than 0.
274
+ #
275
+ def negative?: () -> bool
276
+
277
+ # Returns `self` if `num` is not zero, `nil` otherwise.
278
+ #
279
+ # This behavior is useful when chaining comparisons:
280
+ #
281
+ # a = %w( z Bb bB bb BB a aA Aa AA A )
282
+ # b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
283
+ # b #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
284
+ #
285
+ def nonzero?: () -> self?
286
+
287
+ # Returns the numerator.
288
+ #
289
+ def numerator: () -> Numeric
290
+
291
+ # Returns 0 if the value is positive, pi otherwise.
292
+ #
293
+ alias phase angle
294
+
295
+ # Returns an array; [num.abs, num.arg].
296
+ #
297
+ def polar: () -> [ Numeric, Numeric ]
298
+
299
+ # Returns `true` if `num` is greater than 0.
300
+ #
301
+ def positive?: () -> bool
302
+
303
+ # Returns the most exact division (rational for integers, float for floats).
304
+ #
305
+ def quo: (Numeric) -> Numeric
306
+
307
+ # Returns self.
308
+ #
309
+ def real: () -> Numeric
310
+
311
+ # Returns `true` if `num` is a real number (i.e. not Complex).
312
+ #
313
+ def real?: () -> bool
314
+
315
+ # Returns an array; [num, 0].
316
+ #
317
+ def rect: () -> [ Numeric, Numeric ]
318
+
319
+ # Returns an array; [num, 0].
320
+ #
321
+ alias rectangular rect
322
+
323
+ # `x.remainder(y)` means `x-y*(x/y).truncate`.
324
+ #
325
+ # See Numeric#divmod.
326
+ #
327
+ def remainder: (Numeric) -> Numeric
328
+
329
+ # Returns `num` rounded to the nearest value with a precision of `ndigits`
330
+ # decimal digits (default: 0).
331
+ #
332
+ # Numeric implements this by converting its value to a Float and invoking
333
+ # Float#round.
334
+ #
335
+ def round: () -> Integer
336
+ | (Integer digits) -> Numeric
337
+
338
+ # Invokes the given block with the sequence of numbers starting at `num`,
339
+ # incremented by `step` (defaulted to `1`) on each call.
340
+ #
341
+ # The loop finishes when the value to be passed to the block is greater than
342
+ # `limit` (if `step` is positive) or less than `limit` (if `step` is negative),
343
+ # where `limit` is defaulted to infinity.
344
+ #
345
+ # In the recommended keyword argument style, either or both of `step` and
346
+ # `limit` (default infinity) can be omitted. In the fixed position argument
347
+ # style, zero as a step (i.e. `num.step(limit, 0)`) is not allowed for
348
+ # historical compatibility reasons.
349
+ #
350
+ # If all the arguments are integers, the loop operates using an integer counter.
351
+ #
352
+ # If any of the arguments are floating point numbers, all are converted to
353
+ # floats, and the loop is executed *floor(n + n*Float::EPSILON) + 1* times,
354
+ # where *n = (limit - num)/step*.
355
+ #
356
+ # Otherwise, the loop starts at `num`, uses either the less-than (`<`) or
357
+ # greater-than (`>`) operator to compare the counter against `limit`, and
358
+ # increments itself using the `+` operator.
359
+ #
360
+ # If no block is given, an Enumerator is returned instead. Especially, the
361
+ # enumerator is an Enumerator::ArithmeticSequence if both `limit` and `step` are
362
+ # kind of Numeric or `nil`.
363
+ #
364
+ # For example:
365
+ #
366
+ # p 1.step.take(4)
367
+ # p 10.step(by: -1).take(4)
368
+ # 3.step(to: 5) {|i| print i, " " }
369
+ # 1.step(10, 2) {|i| print i, " " }
370
+ # Math::E.step(to: Math::PI, by: 0.2) {|f| print f, " " }
371
+ #
372
+ # Will produce:
373
+ #
374
+ # [1, 2, 3, 4]
375
+ # [10, 9, 8, 7]
376
+ # 3 4 5
377
+ # 1 3 5 7 9
378
+ # 2.718281828459045 2.9182818284590453 3.118281828459045
379
+ #
380
+ def step: (?Numeric limit, ?Numeric step) { (Numeric) -> void } -> self
381
+ | (?Numeric limit, ?Numeric step) -> Enumerator[Numeric, self]
382
+ | (?by: Numeric, ?to: Numeric) { (Numeric) -> void } -> self
383
+ | (?by: Numeric, ?to: Numeric) -> Enumerator[Numeric, self]
384
+
385
+ # Returns the value as a complex.
386
+ #
387
+ def to_c: () -> Complex
388
+
389
+ # Invokes the child class's `to_i` method to convert `num` to an integer.
390
+ #
391
+ # 1.0.class #=> Float
392
+ # 1.0.to_int.class #=> Integer
393
+ # 1.0.to_i.class #=> Integer
394
+ #
395
+ def to_int: () -> Integer
396
+
397
+ # Returns `num` truncated (toward zero) to a precision of `ndigits` decimal
398
+ # digits (default: 0).
399
+ #
400
+ # Numeric implements this by converting its value to a Float and invoking
401
+ # Float#truncate.
402
+ #
403
+ def truncate: () -> Integer
404
+ | (Integer ndigits) -> (Integer | Numeric)
405
+
406
+ # Returns `true` if `num` has a zero value.
407
+ #
408
+ def zero?: () -> bool
409
+ end