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,35 @@
1
+ interface _ToI
2
+ def to_i: -> Integer
3
+ end
4
+
5
+ interface _ToInt
6
+ def to_int: -> Integer
7
+ end
8
+
9
+ interface _ToS
10
+ def to_s: -> String
11
+ end
12
+
13
+ interface _ToStr
14
+ def to_str: () -> String
15
+ end
16
+
17
+ interface _ToHash[K, V]
18
+ def to_hash: () -> Hash[K, V]
19
+ end
20
+
21
+ interface _ToProc
22
+ def to_proc: () -> untyped
23
+ end
24
+
25
+ interface _Each[out A, out B]
26
+ def each: { (A) -> void } -> B
27
+ end
28
+
29
+ class BigDecimal
30
+ end
31
+
32
+ type int = Integer | _ToInt
33
+ type real = Integer | Float | Rational
34
+
35
+ type string = String | _ToStr
@@ -0,0 +1,145 @@
1
+ # Extends any Class to include *json_creatable?* method.
2
+ # Classes in Ruby are first-class objects---each is an instance of class Class.
3
+ #
4
+ # Typically, you create a new class by using:
5
+ #
6
+ # class Name
7
+ # # some code describing the class behavior
8
+ # end
9
+ #
10
+ # When a new class is created, an object of type Class is initialized and
11
+ # assigned to a global constant (Name in this case).
12
+ #
13
+ # When `Name.new` is called to create a new object, the #new method in Class is
14
+ # run by default. This can be demonstrated by overriding #new in Class:
15
+ #
16
+ # class Class
17
+ # alias old_new new
18
+ # def new(*args)
19
+ # print "Creating a new ", self.name, "\n"
20
+ # old_new(*args)
21
+ # end
22
+ # end
23
+ #
24
+ # class Name
25
+ # end
26
+ #
27
+ # n = Name.new
28
+ #
29
+ # *produces:*
30
+ #
31
+ # Creating a new Name
32
+ #
33
+ # Classes, modules, and objects are interrelated. In the diagram that follows,
34
+ # the vertical arrows represent inheritance, and the parentheses metaclasses.
35
+ # All metaclasses are instances of the class `Class'.
36
+ # +---------+ +-...
37
+ # | | |
38
+ # BasicObject-----|-->(BasicObject)-------|-...
39
+ # ^ | ^ |
40
+ # | | | |
41
+ # Object---------|----->(Object)---------|-...
42
+ # ^ | ^ |
43
+ # | | | |
44
+ # +-------+ | +--------+ |
45
+ # | | | | | |
46
+ # | Module-|---------|--->(Module)-|-...
47
+ # | ^ | | ^ |
48
+ # | | | | | |
49
+ # | Class-|---------|---->(Class)-|-...
50
+ # | ^ | | ^ |
51
+ # | +---+ | +----+
52
+ # | |
53
+ # obj--->OtherClass---------->(OtherClass)-----------...
54
+ #
55
+ class Class < Module
56
+ # Creates a new anonymous (unnamed) class with the given superclass (or Object
57
+ # if no parameter is given). You can give a class a name by assigning the class
58
+ # object to a constant.
59
+ #
60
+ # If a block is given, it is passed the class object, and the block is evaluated
61
+ # in the context of this class like #class_eval.
62
+ #
63
+ # fred = Class.new do
64
+ # def meth1
65
+ # "hello"
66
+ # end
67
+ # def meth2
68
+ # "bye"
69
+ # end
70
+ # end
71
+ #
72
+ # a = fred.new #=> #<#<Class:0x100381890>:0x100376b98>
73
+ # a.meth1 #=> "hello"
74
+ # a.meth2 #=> "bye"
75
+ #
76
+ # Assign the class to a constant (name starting uppercase) if you want to treat
77
+ # it like a regular class.
78
+ #
79
+ def initialize: (?Class superclass) ?{ (Class newclass) -> void } -> void
80
+
81
+ # Allocates space for a new object of *class*'s class and does not call
82
+ # initialize on the new instance. The returned object must be an instance of
83
+ # *class*.
84
+ #
85
+ # klass = Class.new do
86
+ # def initialize(*args)
87
+ # @initialized = true
88
+ # end
89
+ #
90
+ # def initialized?
91
+ # @initialized || false
92
+ # end
93
+ # end
94
+ #
95
+ # klass.allocate.initialized? #=> false
96
+ #
97
+ def allocate: () -> untyped
98
+
99
+ # Callback invoked whenever a subclass of the current class is created.
100
+ #
101
+ # Example:
102
+ #
103
+ # class Foo
104
+ # def self.inherited(subclass)
105
+ # puts "New subclass: #{subclass}"
106
+ # end
107
+ # end
108
+ #
109
+ # class Bar < Foo
110
+ # end
111
+ #
112
+ # class Baz < Bar
113
+ # end
114
+ #
115
+ # *produces:*
116
+ #
117
+ # New subclass: Bar
118
+ # New subclass: Baz
119
+ #
120
+ def inherited: (Class arg0) -> untyped
121
+
122
+ # Calls #allocate to create a new object of *class*'s class, then invokes that
123
+ # object's #initialize method, passing it *args*. This is the method that ends
124
+ # up getting called whenever an object is constructed using `.new`.
125
+ #
126
+ def new: () -> untyped
127
+
128
+ # Returns the superclass of *class*, or `nil`.
129
+ #
130
+ # File.superclass #=> IO
131
+ # IO.superclass #=> Object
132
+ # Object.superclass #=> BasicObject
133
+ # class Foo; end
134
+ # class Bar < Foo; end
135
+ # Bar.superclass #=> Foo
136
+ #
137
+ # Returns nil when the given class does not have a parent class:
138
+ #
139
+ # BasicObject.superclass #=> nil
140
+ #
141
+ # # arglists
142
+ # class.superclass -> a_super_class or nil
143
+ #
144
+ def `superclass`: () -> Class?
145
+ end
@@ -0,0 +1,116 @@
1
+ # The Comparable mixin is used by classes whose objects may be ordered. The
2
+ # class must define the `<=>` operator, which compares the receiver against
3
+ # another object, returning a value less than 0, returning 0, or returning a
4
+ # value greater than 0, depending on whether the receiver is less than, equal
5
+ # to, or greater than the other object. If the other object is not comparable
6
+ # then the `<=>` operator should return `nil`. Comparable uses `<=>` to
7
+ # implement the conventional comparison operators (`<`, `<=`, `==`, `>=`, and
8
+ # `>`) and the method `between?`.
9
+ #
10
+ # class SizeMatters
11
+ # include Comparable
12
+ # attr :str
13
+ # def <=>(other)
14
+ # str.size <=> other.str.size
15
+ # end
16
+ # def initialize(str)
17
+ # @str = str
18
+ # end
19
+ # def inspect
20
+ # @str
21
+ # end
22
+ # end
23
+ #
24
+ # s1 = SizeMatters.new("Z")
25
+ # s2 = SizeMatters.new("YY")
26
+ # s3 = SizeMatters.new("XXX")
27
+ # s4 = SizeMatters.new("WWWW")
28
+ # s5 = SizeMatters.new("VVVVV")
29
+ #
30
+ # s1 < s2 #=> true
31
+ # s4.between?(s1, s3) #=> false
32
+ # s4.between?(s3, s5) #=> true
33
+ # [ s3, s2, s5, s4, s1 ].sort #=> [Z, YY, XXX, WWWW, VVVVV]
34
+ #
35
+ module Comparable : _WithSpaceshipOperator
36
+ # Compares two objects based on the receiver's `<=>` method, returning true if
37
+ # it returns a value less than 0.
38
+ #
39
+ def <: (untyped other) -> bool
40
+
41
+ # Compares two objects based on the receiver's `<=>` method, returning true if
42
+ # it returns a value less than or equal to 0.
43
+ #
44
+ def <=: (untyped other) -> bool
45
+
46
+ # Compares two objects based on the receiver's `<=>` method, returning true if
47
+ # it returns 0. Also returns true if *obj* and *other* are the same object.
48
+ #
49
+ def ==: (untyped other) -> bool
50
+
51
+ # Compares two objects based on the receiver's `<=>` method, returning true if
52
+ # it returns a value greater than 0.
53
+ #
54
+ def >: (untyped other) -> bool
55
+
56
+ # Compares two objects based on the receiver's `<=>` method, returning true if
57
+ # it returns a value greater than or equal to 0.
58
+ #
59
+ def >=: (untyped other) -> bool
60
+
61
+ # Returns `false` if *obj* `<=>` *min* is less than zero or if *obj* `<=>` *max*
62
+ # is greater than zero, `true` otherwise.
63
+ #
64
+ # 3.between?(1, 5) #=> true
65
+ # 6.between?(1, 5) #=> false
66
+ # 'cat'.between?('ant', 'dog') #=> true
67
+ # 'gnu'.between?('ant', 'dog') #=> false
68
+ #
69
+ def between?: (untyped min, untyped max) -> bool
70
+
71
+ # In `(min, max)` form, returns *min* if *obj* `<=>` *min* is less than zero,
72
+ # *max* if *obj* `<=>` *max* is greater than zero, and *obj* otherwise.
73
+ #
74
+ # 12.clamp(0, 100) #=> 12
75
+ # 523.clamp(0, 100) #=> 100
76
+ # -3.123.clamp(0, 100) #=> 0
77
+ #
78
+ # 'd'.clamp('a', 'f') #=> 'd'
79
+ # 'z'.clamp('a', 'f') #=> 'f'
80
+ #
81
+ # In `(range)` form, returns *range.begin* if *obj* `<=>` *range.begin* is less
82
+ # than zero, *range.end* if *obj* `<=>` *range.end* is greater than zero, and
83
+ # *obj* otherwise.
84
+ #
85
+ # 12.clamp(0..100) #=> 12
86
+ # 523.clamp(0..100) #=> 100
87
+ # -3.123.clamp(0..100) #=> 0
88
+ #
89
+ # 'd'.clamp('a'..'f') #=> 'd'
90
+ # 'z'.clamp('a'..'f') #=> 'f'
91
+ #
92
+ # If *range.begin* is `nil`, it is considered smaller than *obj*, and if
93
+ # *range.end* is `nil`, it is considered greater than *obj*.
94
+ #
95
+ # -20.clamp(0..) #=> 0
96
+ # 523.clamp(..100) #=> 100
97
+ #
98
+ # When *range.end* is excluded and not `nil`, an exception is raised.
99
+ #
100
+ # 100.clamp(0...100) # ArgumentError
101
+ #
102
+ def clamp: [A, B] (A min, B max) -> (self | A | B)
103
+ | [A] (Range[A]) -> (self | A)
104
+ end
105
+
106
+ # This interface defines the condition for Comparable mixin.
107
+ #
108
+ interface Comparable::_WithSpaceshipOperator
109
+ # `<=>` operator must return Integer or `nil`.
110
+ # If `other` is greater than `self`, it returns a positive Integer.
111
+ # If `other` equals to `self`, it returns zero.
112
+ # If `other` is less than `self`, it returns a positive Integer.
113
+ # If no comparison is defined with `other` and `self`, it returns `nil`.
114
+ #
115
+ def <=>: (untyped other) -> Integer?
116
+ end
@@ -0,0 +1,400 @@
1
+ # A complex number can be represented as a paired real number with imaginary
2
+ # unit; a+bi. Where a is real part, b is imaginary part and i is imaginary
3
+ # unit. Real a equals complex a+0i mathematically.
4
+ #
5
+ # Complex object can be created as literal, and also by using Kernel#Complex,
6
+ # Complex::rect, Complex::polar or to_c method.
7
+ #
8
+ # 2+1i #=> (2+1i)
9
+ # Complex(1) #=> (1+0i)
10
+ # Complex(2, 3) #=> (2+3i)
11
+ # Complex.polar(2, 3) #=> (-1.9799849932008908+0.2822400161197344i)
12
+ # 3.to_c #=> (3+0i)
13
+ #
14
+ # You can also create complex object from floating-point numbers or strings.
15
+ #
16
+ # Complex(0.3) #=> (0.3+0i)
17
+ # Complex('0.3-0.5i') #=> (0.3-0.5i)
18
+ # Complex('2/3+3/4i') #=> ((2/3)+(3/4)*i)
19
+ # Complex('1@2') #=> (-0.4161468365471424+0.9092974268256817i)
20
+ #
21
+ # 0.3.to_c #=> (0.3+0i)
22
+ # '0.3-0.5i'.to_c #=> (0.3-0.5i)
23
+ # '2/3+3/4i'.to_c #=> ((2/3)+(3/4)*i)
24
+ # '1@2'.to_c #=> (-0.4161468365471424+0.9092974268256817i)
25
+ #
26
+ # A complex object is either an exact or an inexact number.
27
+ #
28
+ # Complex(1, 1) / 2 #=> ((1/2)+(1/2)*i)
29
+ # Complex(1, 1) / 2.0 #=> (0.5+0.5i)
30
+ #
31
+ class Complex < Numeric
32
+ # Returns a complex object which denotes the given polar form.
33
+ #
34
+ # Complex.polar(3, 0) #=> (3.0+0.0i)
35
+ # Complex.polar(3, Math::PI/2) #=> (1.836909530733566e-16+3.0i)
36
+ # Complex.polar(3, Math::PI) #=> (-3.0+3.673819061467132e-16i)
37
+ # Complex.polar(3, -Math::PI/2) #=> (1.836909530733566e-16-3.0i)
38
+ #
39
+ def self.polar: (Numeric, ?Numeric) -> Complex
40
+
41
+ # Returns a complex object which denotes the given rectangular form.
42
+ #
43
+ # Complex.rectangular(1, 2) #=> (1+2i)
44
+ #
45
+ def self.rect: (Numeric, ?Numeric) -> Complex
46
+
47
+ # Returns a complex object which denotes the given rectangular form.
48
+ #
49
+ # Complex.rectangular(1, 2) #=> (1+2i)
50
+ #
51
+ alias self.rectangular self.rect
52
+
53
+ public
54
+
55
+ # Performs multiplication.
56
+ #
57
+ # Complex(2, 3) * Complex(2, 3) #=> (-5+12i)
58
+ # Complex(900) * Complex(1) #=> (900+0i)
59
+ # Complex(-2, 9) * Complex(-9, 2) #=> (0-85i)
60
+ # Complex(9, 8) * 4 #=> (36+32i)
61
+ # Complex(20, 9) * 9.8 #=> (196.0+88.2i)
62
+ #
63
+ def *: (Numeric) -> Complex
64
+
65
+ # Performs exponentiation.
66
+ #
67
+ # Complex('i') ** 2 #=> (-1+0i)
68
+ # Complex(-8) ** Rational(1, 3) #=> (1.0000000000000002+1.7320508075688772i)
69
+ #
70
+ def **: (Numeric) -> Complex
71
+
72
+ # Performs addition.
73
+ #
74
+ # Complex(2, 3) + Complex(2, 3) #=> (4+6i)
75
+ # Complex(900) + Complex(1) #=> (901+0i)
76
+ # Complex(-2, 9) + Complex(-9, 2) #=> (-11+11i)
77
+ # Complex(9, 8) + 4 #=> (13+8i)
78
+ # Complex(20, 9) + 9.8 #=> (29.8+9i)
79
+ #
80
+ def +: (Numeric) -> Complex
81
+
82
+ def +@: () -> Complex
83
+
84
+ # Performs subtraction.
85
+ #
86
+ # Complex(2, 3) - Complex(2, 3) #=> (0+0i)
87
+ # Complex(900) - Complex(1) #=> (899+0i)
88
+ # Complex(-2, 9) - Complex(-9, 2) #=> (7+7i)
89
+ # Complex(9, 8) - 4 #=> (5+8i)
90
+ # Complex(20, 9) - 9.8 #=> (10.2+9i)
91
+ #
92
+ def -: (Numeric) -> Complex
93
+
94
+ # Returns negation of the value.
95
+ #
96
+ # -Complex(1, 2) #=> (-1-2i)
97
+ #
98
+ def -@: () -> Complex
99
+
100
+ # Performs division.
101
+ #
102
+ # Complex(2, 3) / Complex(2, 3) #=> ((1/1)+(0/1)*i)
103
+ # Complex(900) / Complex(1) #=> ((900/1)+(0/1)*i)
104
+ # Complex(-2, 9) / Complex(-9, 2) #=> ((36/85)-(77/85)*i)
105
+ # Complex(9, 8) / 4 #=> ((9/4)+(2/1)*i)
106
+ # Complex(20, 9) / 9.8 #=> (2.0408163265306123+0.9183673469387754i)
107
+ #
108
+ def /: (Numeric) -> Complex
109
+
110
+ def <: (Numeric) -> bot
111
+
112
+ def <=: (Numeric) -> bot
113
+
114
+ # If `cmp`'s imaginary part is zero, and `object` is also a real number (or a
115
+ # Complex number where the imaginary part is zero), compare the real part of
116
+ # `cmp` to object. Otherwise, return nil.
117
+ #
118
+ # Complex(2, 3) <=> Complex(2, 3) #=> nil
119
+ # Complex(2, 3) <=> 1 #=> nil
120
+ # Complex(2) <=> 1 #=> 1
121
+ # Complex(2) <=> 2 #=> 0
122
+ # Complex(2) <=> 3 #=> -1
123
+ #
124
+ def <=>: (Numeric) -> Integer?
125
+
126
+ # Returns true if cmp equals object numerically.
127
+ #
128
+ # Complex(2, 3) == Complex(2, 3) #=> true
129
+ # Complex(5) == 5 #=> true
130
+ # Complex(0) == 0.0 #=> true
131
+ # Complex('1/3') == 0.33 #=> false
132
+ # Complex('1/2') == '1/2' #=> false
133
+ #
134
+ def ==: (untyped) -> bool
135
+
136
+ def >: (Numeric) -> bot
137
+
138
+ def >=: (Numeric) -> bot
139
+
140
+ # Returns the absolute part of its polar form.
141
+ #
142
+ # Complex(-1).abs #=> 1
143
+ # Complex(3.0, -4.0).abs #=> 5.0
144
+ #
145
+ def abs: () -> Numeric
146
+
147
+ # Returns square of the absolute value.
148
+ #
149
+ # Complex(-1).abs2 #=> 1
150
+ # Complex(3.0, -4.0).abs2 #=> 25.0
151
+ #
152
+ def abs2: () -> Numeric
153
+
154
+ # Returns the angle part of its polar form.
155
+ #
156
+ # Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966
157
+ #
158
+ def angle: () -> Float
159
+
160
+ # Returns the angle part of its polar form.
161
+ #
162
+ # Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966
163
+ #
164
+ alias arg angle
165
+
166
+ def ceil: (*untyped) -> bot
167
+
168
+ def clone: (?freeze: bool) -> self
169
+
170
+ def coerce: (Numeric) -> [ Complex, Complex ]
171
+
172
+ # Returns the complex conjugate.
173
+ #
174
+ # Complex(1, 2).conjugate #=> (1-2i)
175
+ #
176
+ def conj: () -> Complex
177
+
178
+ # Returns the complex conjugate.
179
+ #
180
+ # Complex(1, 2).conjugate #=> (1-2i)
181
+ #
182
+ def conjugate: () -> Complex
183
+
184
+ # Returns the denominator (lcm of both denominator - real and imag).
185
+ #
186
+ # See numerator.
187
+ #
188
+ def denominator: () -> Integer
189
+
190
+ def div: (Numeric) -> bot
191
+
192
+ def divmod: (Numeric) -> bot
193
+
194
+ def dup: () -> self
195
+
196
+ def eql?: (untyped) -> bool
197
+
198
+ # Performs division as each part is a float, never returns a float.
199
+ #
200
+ # Complex(11, 22).fdiv(3) #=> (3.6666666666666665+7.333333333333333i)
201
+ #
202
+ def fdiv: (Numeric) -> Complex
203
+
204
+ # Returns `true` if `cmp`'s real and imaginary parts are both finite numbers,
205
+ # otherwise returns `false`.
206
+ #
207
+ def finite?: () -> bool
208
+
209
+ def floor: (?Integer) -> bot
210
+
211
+ def hash: () -> Integer
212
+
213
+ def i: () -> bot
214
+
215
+ # Returns the imaginary part.
216
+ #
217
+ # Complex(7).imaginary #=> 0
218
+ # Complex(9, -4).imaginary #=> -4
219
+ #
220
+ def imag: () -> Numeric
221
+
222
+ # Returns the imaginary part.
223
+ #
224
+ # Complex(7).imaginary #=> 0
225
+ # Complex(9, -4).imaginary #=> -4
226
+ #
227
+ def imaginary: () -> Numeric
228
+
229
+ # Returns `1` if `cmp`'s real or imaginary part is an infinite number, otherwise
230
+ # returns `nil`.
231
+ #
232
+ # For example:
233
+ #
234
+ # (1+1i).infinite? #=> nil
235
+ # (Float::INFINITY + 1i).infinite? #=> 1
236
+ #
237
+ def infinite?: () -> Integer?
238
+
239
+ # Returns the value as a string for inspection.
240
+ #
241
+ # Complex(2).inspect #=> "(2+0i)"
242
+ # Complex('-8/6').inspect #=> "((-4/3)+0i)"
243
+ # Complex('1/2i').inspect #=> "(0+(1/2)*i)"
244
+ # Complex(0, Float::INFINITY).inspect #=> "(0+Infinity*i)"
245
+ # Complex(Float::NAN, Float::NAN).inspect #=> "(NaN+NaN*i)"
246
+ #
247
+ def inspect: () -> String
248
+
249
+ def integer?: () -> bool
250
+
251
+ # Returns the absolute part of its polar form.
252
+ #
253
+ # Complex(-1).abs #=> 1
254
+ # Complex(3.0, -4.0).abs #=> 5.0
255
+ #
256
+ alias magnitude abs
257
+
258
+ def modulo: (Numeric) -> bot
259
+
260
+ def negative?: () -> bot
261
+
262
+ def nonzero?: () -> self?
263
+
264
+ # Returns the numerator.
265
+ #
266
+ # 1 2 3+4i <- numerator
267
+ # - + -i -> ----
268
+ # 2 3 6 <- denominator
269
+ #
270
+ # c = Complex('1/2+2/3i') #=> ((1/2)+(2/3)*i)
271
+ # n = c.numerator #=> (3+4i)
272
+ # d = c.denominator #=> 6
273
+ # n / d #=> ((1/2)+(2/3)*i)
274
+ # Complex(Rational(n.real, d), Rational(n.imag, d))
275
+ # #=> ((1/2)+(2/3)*i)
276
+ #
277
+ # See denominator.
278
+ #
279
+ def numerator: () -> Complex
280
+
281
+ # Returns the angle part of its polar form.
282
+ #
283
+ # Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966
284
+ #
285
+ alias phase angle
286
+
287
+ # Returns an array; [cmp.abs, cmp.arg].
288
+ #
289
+ # Complex(1, 2).polar #=> [2.23606797749979, 1.1071487177940904]
290
+ #
291
+ def polar: () -> [Numeric, Float]
292
+
293
+ def positive?: () -> bot
294
+
295
+ # Performs division.
296
+ #
297
+ # Complex(2, 3) / Complex(2, 3) #=> ((1/1)+(0/1)*i)
298
+ # Complex(900) / Complex(1) #=> ((900/1)+(0/1)*i)
299
+ # Complex(-2, 9) / Complex(-9, 2) #=> ((36/85)-(77/85)*i)
300
+ # Complex(9, 8) / 4 #=> ((9/4)+(2/1)*i)
301
+ # Complex(20, 9) / 9.8 #=> (2.0408163265306123+0.9183673469387754i)
302
+ #
303
+ def quo: (Numeric) -> Complex
304
+
305
+ # Returns the value as a rational if possible (the imaginary part should be
306
+ # exactly zero).
307
+ #
308
+ # Complex(1.0/3, 0).rationalize #=> (1/3)
309
+ # Complex(1, 0.0).rationalize # RangeError
310
+ # Complex(1, 2).rationalize # RangeError
311
+ #
312
+ # See to_r.
313
+ #
314
+ def rationalize: (?Numeric eps) -> Rational
315
+
316
+ # Returns the real part.
317
+ #
318
+ # Complex(7).real #=> 7
319
+ # Complex(9, -4).real #=> 9
320
+ #
321
+ def real: () -> Numeric
322
+
323
+ # Returns false, even if the complex number has no imaginary part.
324
+ #
325
+ def real?: () -> false
326
+
327
+ # Returns an array; [cmp.real, cmp.imag].
328
+ #
329
+ # Complex(1, 2).rectangular #=> [1, 2]
330
+ #
331
+ def rect: () -> [Numeric, Numeric]
332
+
333
+ # Returns an array; [cmp.real, cmp.imag].
334
+ #
335
+ # Complex(1, 2).rectangular #=> [1, 2]
336
+ #
337
+ alias rectangular rect
338
+
339
+ def reminder: (Numeric) -> bot
340
+
341
+ def round: (*untyped) -> bot
342
+
343
+ def step: (*untyped) ?{ (*untyped) -> untyped } -> bot
344
+
345
+ # Returns self.
346
+ #
347
+ # Complex(2).to_c #=> (2+0i)
348
+ # Complex(-8, 6).to_c #=> (-8+6i)
349
+ #
350
+ def to_c: () -> Complex
351
+
352
+ # Returns the value as a float if possible (the imaginary part should be exactly
353
+ # zero).
354
+ #
355
+ # Complex(1, 0).to_f #=> 1.0
356
+ # Complex(1, 0.0).to_f # RangeError
357
+ # Complex(1, 2).to_f # RangeError
358
+ #
359
+ def to_f: () -> Float
360
+
361
+ # Returns the value as an integer if possible (the imaginary part should be
362
+ # exactly zero).
363
+ #
364
+ # Complex(1, 0).to_i #=> 1
365
+ # Complex(1, 0.0).to_i # RangeError
366
+ # Complex(1, 2).to_i # RangeError
367
+ #
368
+ def to_i: () -> Integer
369
+
370
+ alias to_int to_i
371
+
372
+ # Returns the value as a rational if possible (the imaginary part should be
373
+ # exactly zero).
374
+ #
375
+ # Complex(1, 0).to_r #=> (1/1)
376
+ # Complex(1, 0.0).to_r # RangeError
377
+ # Complex(1, 2).to_r # RangeError
378
+ #
379
+ # See rationalize.
380
+ #
381
+ def to_r: () -> Rational
382
+
383
+ # Returns the value as a string.
384
+ #
385
+ # Complex(2).to_s #=> "2+0i"
386
+ # Complex('-8/6').to_s #=> "-4/3+0i"
387
+ # Complex('1/2i').to_s #=> "0+1/2i"
388
+ # Complex(0, Float::INFINITY).to_s #=> "0+Infinity*i"
389
+ # Complex(Float::NAN, Float::NAN).to_s #=> "NaN+NaN*i"
390
+ #
391
+ def to_s: () -> String
392
+
393
+ def truncate: (?Integer) -> bot
394
+
395
+ def zero?: () -> bool
396
+ end
397
+
398
+ # The imaginary unit.
399
+ #
400
+ Complex::I: Complex