steep 0.13.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +28 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep.rb +33 -1
  9. data/lib/steep/annotation_parser.rb +4 -4
  10. data/lib/steep/ast/buffer.rb +11 -7
  11. data/lib/steep/ast/builtin.rb +8 -0
  12. data/lib/steep/ast/types/factory.rb +124 -89
  13. data/lib/steep/cli.rb +16 -1
  14. data/lib/steep/drivers/annotations.rb +1 -1
  15. data/lib/steep/drivers/check.rb +20 -4
  16. data/lib/steep/drivers/init.rb +5 -5
  17. data/lib/steep/drivers/langserver.rb +13 -287
  18. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  19. data/lib/steep/drivers/vendor.rb +2 -2
  20. data/lib/steep/drivers/watch.rb +97 -85
  21. data/lib/steep/drivers/worker.rb +51 -0
  22. data/lib/steep/project.rb +9 -5
  23. data/lib/steep/project/completion_provider.rb +298 -0
  24. data/lib/steep/project/dsl.rb +14 -0
  25. data/lib/steep/project/file.rb +54 -47
  26. data/lib/steep/project/hover_content.rb +17 -8
  27. data/lib/steep/project/options.rb +25 -3
  28. data/lib/steep/project/target.rb +40 -24
  29. data/lib/steep/server/base_worker.rb +56 -0
  30. data/lib/steep/server/code_worker.rb +151 -0
  31. data/lib/steep/server/interaction_worker.rb +281 -0
  32. data/lib/steep/server/master.rb +196 -0
  33. data/lib/steep/server/signature_worker.rb +148 -0
  34. data/lib/steep/server/utils.rb +36 -0
  35. data/lib/steep/server/worker_process.rb +62 -0
  36. data/lib/steep/signature/errors.rb +1 -1
  37. data/lib/steep/signature/validator.rb +13 -13
  38. data/lib/steep/source.rb +1 -1
  39. data/lib/steep/type_construction.rb +1004 -727
  40. data/lib/steep/type_inference/constant_env.rb +3 -11
  41. data/lib/steep/type_inference/context.rb +8 -3
  42. data/lib/steep/type_inference/context_array.rb +111 -0
  43. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  44. data/lib/steep/type_inference/logic.rb +130 -0
  45. data/lib/steep/type_inference/type_env.rb +5 -69
  46. data/lib/steep/typing.rb +91 -23
  47. data/lib/steep/version.rb +1 -1
  48. data/smoke/alias/Steepfile +1 -0
  49. data/smoke/alias/a.rb +1 -1
  50. data/smoke/and/Steepfile +1 -0
  51. data/smoke/array/Steepfile +1 -0
  52. data/smoke/array/b.rb +0 -2
  53. data/smoke/block/Steepfile +1 -0
  54. data/smoke/case/Steepfile +1 -0
  55. data/smoke/class/Steepfile +1 -0
  56. data/smoke/const/Steepfile +1 -0
  57. data/smoke/dstr/Steepfile +1 -0
  58. data/smoke/ensure/Steepfile +1 -0
  59. data/smoke/enumerator/Steepfile +1 -0
  60. data/smoke/extension/Steepfile +1 -0
  61. data/smoke/extension/c.rb +1 -0
  62. data/smoke/hash/Steepfile +1 -0
  63. data/smoke/hello/Steepfile +1 -0
  64. data/smoke/if/Steepfile +1 -0
  65. data/smoke/if/a.rb +1 -1
  66. data/smoke/implements/Steepfile +1 -0
  67. data/smoke/initialize/Steepfile +1 -0
  68. data/smoke/integer/Steepfile +1 -0
  69. data/smoke/interface/Steepfile +1 -0
  70. data/smoke/kwbegin/Steepfile +1 -0
  71. data/smoke/lambda/Steepfile +1 -0
  72. data/smoke/literal/Steepfile +1 -0
  73. data/smoke/map/Steepfile +1 -0
  74. data/smoke/method/Steepfile +1 -0
  75. data/smoke/module/Steepfile +1 -0
  76. data/smoke/regexp/Steepfile +1 -0
  77. data/smoke/regexp/b.rb +4 -4
  78. data/smoke/regression/Steepfile +1 -0
  79. data/smoke/rescue/Steepfile +1 -0
  80. data/smoke/rescue/a.rb +1 -1
  81. data/smoke/self/Steepfile +1 -0
  82. data/smoke/skip/Steepfile +1 -0
  83. data/smoke/stdout/Steepfile +1 -0
  84. data/smoke/super/Steepfile +1 -0
  85. data/smoke/type_case/Steepfile +1 -0
  86. data/smoke/yield/Steepfile +1 -0
  87. data/steep.gemspec +8 -8
  88. metadata +38 -138
  89. data/exe/rbs +0 -3
  90. data/exe/ruby-signature +0 -3
  91. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  92. data/vendor/ruby-signature/.gitignore +0 -12
  93. data/vendor/ruby-signature/.rubocop.yml +0 -15
  94. data/vendor/ruby-signature/BSDL +0 -22
  95. data/vendor/ruby-signature/COPYING +0 -56
  96. data/vendor/ruby-signature/Gemfile +0 -6
  97. data/vendor/ruby-signature/README.md +0 -93
  98. data/vendor/ruby-signature/Rakefile +0 -66
  99. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
  100. data/vendor/ruby-signature/bin/console +0 -14
  101. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  102. data/vendor/ruby-signature/bin/setup +0 -10
  103. data/vendor/ruby-signature/bin/sort +0 -88
  104. data/vendor/ruby-signature/bin/test_runner.rb +0 -17
  105. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  106. data/vendor/ruby-signature/docs/sigs.md +0 -148
  107. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  108. data/vendor/ruby-signature/docs/syntax.md +0 -528
  109. data/vendor/ruby-signature/exe/rbs +0 -3
  110. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  111. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
  112. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  113. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  114. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  115. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  116. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  117. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  118. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
  119. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  120. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  121. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  122. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  123. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  124. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  125. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  126. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  127. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  128. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  129. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  130. data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
  131. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
  132. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  133. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  134. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  135. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  136. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  137. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  138. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
  139. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
  140. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  141. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  142. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  143. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  144. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  145. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  146. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  147. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
  148. data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
  149. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
  150. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
  151. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  152. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  153. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  154. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
  155. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  156. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  157. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  158. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  159. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  160. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  161. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
  162. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
  163. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  164. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  165. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  166. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  167. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
  168. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  169. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  170. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  171. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
  172. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  173. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  174. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
  175. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  176. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
  177. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  178. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
  179. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
  180. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
  181. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
  182. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
  183. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
  184. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  185. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  186. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  187. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
  188. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
  189. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
  190. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  191. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  192. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
  193. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
  194. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  195. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  196. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
  197. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
  198. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  199. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
  200. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
  201. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  202. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
  203. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
  204. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  205. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
  206. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  207. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
  208. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
  209. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
  210. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  211. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  212. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  213. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
  214. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,93 +0,0 @@
1
- # [Random](Random) provides an interface to Ruby's
2
- # pseudo-random number generator, or PRNG. The PRNG produces a
3
- # deterministic sequence of bits which approximate true randomness. The
4
- # sequence may be represented by integers, floats, or binary strings.
5
- #
6
- # The generator may be initialized with either a system-generated or
7
- # user-supplied seed value by using
8
- # [::srand](Random#method-c-srand).
9
- #
10
- # The class method [\#rand](Random#method-i-rand)
11
- # provides the base functionality of
12
- # [Kernel\#rand](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-rand)
13
- # along with better handling of floating point values. These are both
14
- # interfaces to Random::DEFAULT, the Ruby system PRNG.
15
- #
16
- # [::new](Random#method-c-new) will create a new PRNG
17
- # with a state independent of Random::DEFAULT, allowing multiple
18
- # generators with different seed values or sequence positions to exist
19
- # simultaneously. [Random](Random) objects can be
20
- # marshaled, allowing sequences to be saved and resumed.
21
- #
22
- # PRNGs are currently implemented as a modified Mersenne Twister with a
23
- # period of 2\*\*19937-1.
24
- class Random < Object
25
- include Random::Formatter
26
-
27
- def ==: (untyped arg0) -> bool
28
-
29
- def bytes: (Integer size) -> String
30
-
31
- def initialize: (?Integer seed) -> void
32
-
33
- def rand: () -> Float
34
- | (Integer | ::Range[Integer] max) -> Integer
35
- | (Float | ::Range[Float] max) -> Float
36
-
37
- # Returns the seed value used to initialize the generator. This may be
38
- # used to initialize another generator with the same state at a later
39
- # time, causing it to produce the same sequence of numbers.
40
- #
41
- # ```ruby
42
- # prng1 = Random.new(1234)
43
- # prng1.seed #=> 1234
44
- # prng1.rand(100) #=> 47
45
- #
46
- # prng2 = Random.new(prng1.seed)
47
- # prng2.rand(100) #=> 47
48
- # ```
49
- def seed: () -> Integer
50
-
51
- # Returns an arbitrary seed value. This is used by
52
- # [::new](Random.downloaded.ruby_doc#method-c-new) when no seed value is
53
- # specified as an argument.
54
- #
55
- # ```ruby
56
- # Random.new_seed #=> 115032730400174366788466674494640623225
57
- # ```
58
- def self.new_seed: () -> Integer
59
-
60
- def self.rand: (?Integer max) -> Numeric
61
-
62
- def self.srand: (?Integer number) -> Numeric
63
- end
64
-
65
- Random::DEFAULT: Random
66
-
67
- module Random::Formatter
68
- def base64: (?Integer? n) -> String
69
-
70
- def hex: (?Integer? n) -> String
71
-
72
- def rand: () -> Float
73
- | (?Float? n) -> Float
74
- | (?Integer? n) -> Integer
75
- | (?Numeric? n) -> Numeric
76
- | (?::Range[Float]? n) -> Float
77
- | (?::Range[Integer]? n) -> Integer
78
- | (?::Range[Numeric]? n) -> Numeric
79
-
80
- def random_bytes: (?Integer? n) -> String
81
-
82
- def random_number: () -> Float
83
- | (?Float? n) -> Float
84
- | (?Integer? n) -> Integer
85
- | (?Numeric? n) -> Numeric
86
- | (?::Range[Float]? n) -> Float
87
- | (?::Range[Integer]? n) -> Integer
88
- | (?::Range[Numeric]? n) -> Numeric
89
-
90
- def urlsafe_base64: (?Integer? n, ?bool padding) -> String
91
-
92
- def uuid: () -> String
93
- end
@@ -1,226 +0,0 @@
1
- # A `Range` represents an interval—a set of values with a beginning and an
2
- # end. Ranges may be constructed using the *s* `..` *e* and *s* `...` *e*
3
- # literals, or with [::new](Range#method-c-new).
4
- # Ranges constructed using `..` run from the beginning to the end
5
- # inclusively. Those created using `...` exclude the end value. When used
6
- # as an iterator, ranges return each value in the sequence.
7
- #
8
- # ```ruby
9
- # (-1..-5).to_a #=> []
10
- # (-5..-1).to_a #=> [-5, -4, -3, -2, -1]
11
- # ('a'..'e').to_a #=> ["a", "b", "c", "d", "e"]
12
- # ('a'...'e').to_a #=> ["a", "b", "c", "d"]
13
- # ```
14
- #
15
- #
16
- # An “endless range” represents a semi-infinite range. Literal notation
17
- # for an endless range is:
18
- #
19
- # (1..)
20
- # # or similarly
21
- # (1...)
22
- #
23
- # Which is equivalent to
24
- #
25
- # ```ruby
26
- # (1..nil) # or similarly (1...nil)
27
- # Range.new(1, nil) # or Range.new(1, nil, true)
28
- # ```
29
- #
30
- # Endless ranges are useful, for example, for idiomatic slicing of arrays:
31
- #
32
- # [1, 2, 3, 4, 5][2...] # => [3, 4, 5]
33
- #
34
- # Some implementation details:
35
- #
36
- # - `end` of endless range is `nil` ;
37
- #
38
- # - `each` of endless range enumerates infinite sequence (may be useful
39
- # in combination with
40
- # [Enumerable\#take\_while](https://ruby-doc.org/core-2.6.3/Enumerable.html#method-i-take_while)
41
- # or similar methods);
42
- #
43
- # - `(1..)` and `(1...)` are not equal, although technically
44
- # representing the same sequence.
45
- #
46
- #
47
- # Ranges can be constructed using any objects that can be compared using
48
- # the `<=>` operator. Methods that treat the range as a sequence (\#each
49
- # and methods inherited from
50
- # [Enumerable](https://ruby-doc.org/core-2.6.3/Enumerable.html) ) expect
51
- # the begin object to implement a `succ` method to return the next object
52
- # in sequence. The [step](Range#method-i-step) and
53
- # [include?](Range#method-i-include-3F) methods
54
- # require the begin object to implement `succ` or to be numeric.
55
- #
56
- # In the `Xs` class below both `<=>` and `succ` are implemented so `Xs`
57
- # can be used to construct ranges. Note that the
58
- # [Comparable](https://ruby-doc.org/core-2.6.3/Comparable.html) module is
59
- # included so the `==` method is defined in terms of `<=>` .
60
- #
61
- # ```ruby
62
- # class Xs # represent a string of 'x's
63
- # include Comparable
64
- # attr :length
65
- # def initialize(n)
66
- # @length = n
67
- # end
68
- # def succ
69
- # Xs.new(@length + 1)
70
- # end
71
- # def <=>(other)
72
- # @length <=> other.length
73
- # end
74
- # def to_s
75
- # sprintf "%2d #{inspect}", @length
76
- # end
77
- # def inspect
78
- # 'x' * @length
79
- # end
80
- # end
81
- # ```
82
- #
83
- # An example of using `Xs` to construct a range:
84
- #
85
- # ```ruby
86
- # r = Xs.new(3)..Xs.new(6) #=> xxx..xxxxxx
87
- # r.to_a #=> [xxx, xxxx, xxxxx, xxxxxx]
88
- # r.member?(Xs.new(5)) #=> true
89
- # ```
90
- class Range[Elem] < Object
91
- include Enumerable[Elem, Range[Elem]]
92
-
93
- def self.new: [U] (U from, U to, ?bool exclude_end) -> ::Range[U]
94
-
95
- def ==: (untyped obj) -> bool
96
-
97
- def ===: (untyped obj) -> bool
98
-
99
- # Returns the object that defines the beginning of the range.
100
- #
101
- # ```ruby
102
- # (1..10).begin #=> 1
103
- # ```
104
- def begin: () -> Elem
105
-
106
- def bsearch: [U] () { (Elem arg0) -> bool } -> U?
107
-
108
- def cover?: (untyped obj) -> bool
109
-
110
- def each: () { (Elem arg0) -> untyped } -> self
111
- | () -> ::Enumerator[Elem, self]
112
-
113
- # Returns the object that defines the end of the range.
114
- #
115
- # ```ruby
116
- # (1..10).end #=> 10
117
- # (1...10).end #=> 10
118
- # ```
119
- def `end`: () -> Elem
120
-
121
- # Returns `true` if the range excludes its end value.
122
- #
123
- # ```ruby
124
- # (1..5).exclude_end? #=> false
125
- # (1...5).exclude_end? #=> true
126
- # ```
127
- def `exclude_end?`: () -> bool
128
-
129
- # Returns the first object in the range, or an array of the first `n`
130
- # elements.
131
- #
132
- # ```ruby
133
- # (10..20).first #=> 10
134
- # (10..20).first(3) #=> [10, 11, 12]
135
- # ```
136
- def first: () -> Elem
137
- | (?Integer n) -> ::Array[Elem]
138
-
139
- # Compute a hash-code for this range. Two ranges with equal begin and end
140
- # points (using `eql?` ), and the same
141
- # [exclude\_end?](Range.downloaded.ruby_doc#method-i-exclude_end-3F) value
142
- # will generate the same hash-code.
143
- #
144
- # See also Object\#hash.
145
- def hash: () -> Integer
146
-
147
- def `include?`: (untyped obj) -> bool
148
-
149
- def initialize: (Elem _begin, Elem _end, ?bool exclude_end) -> void
150
-
151
- # Convert this range object to a printable form (using `inspect` to
152
- # convert the begin and end objects).
153
- def inspect: () -> String
154
-
155
- # Returns the last object in the range, or an array of the last `n`
156
- # elements.
157
- #
158
- # Note that with no arguments `last` will return the object that defines
159
- # the end of the range even if
160
- # [exclude\_end?](Range.downloaded.ruby_doc#method-i-exclude_end-3F) is
161
- # `true` .
162
- #
163
- # ```ruby
164
- # (10..20).last #=> 20
165
- # (10...20).last #=> 20
166
- # (10..20).last(3) #=> [18, 19, 20]
167
- # (10...20).last(3) #=> [17, 18, 19]
168
- # ```
169
- def last: () -> Elem
170
- | (?Integer n) -> ::Array[Elem]
171
-
172
- # Returns the maximum value in the range. Returns `nil` if the begin value
173
- # of the range larger than the end value. Returns `nil` if the begin value
174
- # of an exclusive range is equal to the end value.
175
- #
176
- # Can be given an optional block to override the default comparison method
177
- # `a <=> b` .
178
- #
179
- # ```ruby
180
- # (10..20).max #=> 20
181
- # ```
182
- def max: () -> Elem
183
- | () { (Elem arg0, Elem arg1) -> Integer } -> Elem
184
- | (?Integer n) -> ::Array[Elem]
185
- | (?Integer n) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
186
-
187
- # Returns the minimum value in the range. Returns `nil` if the begin value
188
- # of the range is larger than the end value. Returns `nil` if the begin
189
- # value of an exclusive range is equal to the end value.
190
- #
191
- # Can be given an optional block to override the default comparison method
192
- # `a <=> b` .
193
- #
194
- # ```ruby
195
- # (10..20).min #=> 10
196
- # ```
197
- def min: () -> Elem
198
- | () { (Elem arg0, Elem arg1) -> Integer } -> Elem
199
- | (?Integer n) -> ::Array[Elem]
200
- | (?Integer n) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
201
-
202
- # Returns the number of elements in the range. Both the begin and the end
203
- # of the [Range](Range.downloaded.ruby_doc) must be
204
- # [Numeric](https://ruby-doc.org/core-2.6.3/Numeric.html), otherwise nil
205
- # is returned.
206
- #
207
- # ```ruby
208
- # (10..20).size #=> 11
209
- # ('a'..'z').size #=> nil
210
- # (-Float::INFINITY..Float::INFINITY).size #=> Infinity
211
- # ```
212
- def size: () -> Integer?
213
- | () -> Float?
214
-
215
- def step: (?Integer n) { (Elem arg0) -> untyped } -> self
216
- | (?Integer n) -> ::Enumerator[Elem, void]
217
-
218
- # Convert this range object to a printable form (using
219
- # [to\_s](Range.downloaded.ruby_doc#method-i-to_s) to convert the begin
220
- # and end objects).
221
- def to_s: () -> String
222
-
223
- def eql?: (untyped obj) -> bool
224
-
225
- def member?: (untyped obj) -> bool
226
- end
@@ -1,424 +0,0 @@
1
- # A rational number can be represented as a pair of integer numbers: a/b (b>0),
2
- # where a is the numerator and b is the denominator. Integer a equals rational
3
- # a/1 mathematically.
4
- #
5
- # In Ruby, you can create rational objects with the Kernel#Rational, to_r, or
6
- # rationalize methods or by suffixing `r` to a literal. The return values will
7
- # be irreducible fractions.
8
- #
9
- # Rational(1) #=> (1/1)
10
- # Rational(2, 3) #=> (2/3)
11
- # Rational(4, -6) #=> (-2/3)
12
- # 3.to_r #=> (3/1)
13
- # 2/3r #=> (2/3)
14
- #
15
- # You can also create rational objects from floating-point numbers or strings.
16
- #
17
- # Rational(0.3) #=> (5404319552844595/18014398509481984)
18
- # Rational('0.3') #=> (3/10)
19
- # Rational('2/3') #=> (2/3)
20
- #
21
- # 0.3.to_r #=> (5404319552844595/18014398509481984)
22
- # '0.3'.to_r #=> (3/10)
23
- # '2/3'.to_r #=> (2/3)
24
- # 0.3.rationalize #=> (3/10)
25
- #
26
- # A rational object is an exact number, which helps you to write programs
27
- # without any rounding errors.
28
- #
29
- # 10.times.inject(0) {|t| t + 0.1 } #=> 0.9999999999999999
30
- # 10.times.inject(0) {|t| t + Rational('0.1') } #=> (1/1)
31
- #
32
- # However, when an expression includes an inexact component (numerical value or
33
- # operation), it will produce an inexact result.
34
- #
35
- # Rational(10) / 3 #=> (10/3)
36
- # Rational(10) / 3.0 #=> 3.3333333333333335
37
- #
38
- # Rational(-8) ** Rational(1, 3)
39
- # #=> (1.0000000000000002+1.7320508075688772i)
40
- #
41
- class Rational < Numeric
42
- public
43
-
44
- def %: (Integer) -> Rational
45
- | (Float) -> Float
46
- | (Rational) -> Rational
47
- | (Numeric) -> Numeric
48
-
49
- # Performs multiplication.
50
- #
51
- # Rational(2, 3) * Rational(2, 3) #=> (4/9)
52
- # Rational(900) * Rational(1) #=> (900/1)
53
- # Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
54
- # Rational(9, 8) * 4 #=> (9/2)
55
- # Rational(20, 9) * 9.8 #=> 21.77777777777778
56
- #
57
- def *: (Float) -> Float
58
- | (Complex) -> Complex
59
- | (Numeric) -> Numeric
60
-
61
- # Performs exponentiation.
62
- #
63
- # Rational(2) ** Rational(3) #=> (8/1)
64
- # Rational(10) ** -2 #=> (1/100)
65
- # Rational(10) ** -2.0 #=> 0.01
66
- # Rational(-4) ** Rational(1, 2) #=> (0.0+2.0i)
67
- # Rational(1, 2) ** 0 #=> (1/1)
68
- # Rational(1, 2) ** 0.0 #=> 1.0
69
- #
70
- def **: (Complex) -> Complex
71
- | (Numeric) -> Numeric
72
-
73
- # Performs addition.
74
- #
75
- # Rational(2, 3) + Rational(2, 3) #=> (4/3)
76
- # Rational(900) + Rational(1) #=> (901/1)
77
- # Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
78
- # Rational(9, 8) + 4 #=> (41/8)
79
- # Rational(20, 9) + 9.8 #=> 12.022222222222222
80
- #
81
- def +: (Float) -> Float
82
- | (Complex) -> Complex
83
- | (Numeric) -> Rational
84
-
85
- def +@: () -> Rational
86
-
87
- # Performs subtraction.
88
- #
89
- # Rational(2, 3) - Rational(2, 3) #=> (0/1)
90
- # Rational(900) - Rational(1) #=> (899/1)
91
- # Rational(-2, 9) - Rational(-9, 2) #=> (77/18)
92
- # Rational(9, 8) - 4 #=> (-23/8)
93
- # Rational(20, 9) - 9.8 #=> -7.577777777777778
94
- #
95
- def -: (Float) -> Float
96
- | (Complex) -> Complex
97
- | (Numeric) -> Rational
98
-
99
- # Negates `rat`.
100
- #
101
- def -@: () -> Rational
102
-
103
- # Performs division.
104
- #
105
- # Rational(2, 3) / Rational(2, 3) #=> (1/1)
106
- # Rational(900) / Rational(1) #=> (900/1)
107
- # Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
108
- # Rational(9, 8) / 4 #=> (9/32)
109
- # Rational(20, 9) / 9.8 #=> 0.22675736961451246
110
- #
111
- def /: (Float) -> Float
112
- | (Complex) -> Complex
113
- | (Numeric) -> Rational
114
-
115
- # Returns -1, 0, or +1 depending on whether `rational` is less than, equal to,
116
- # or greater than `numeric`.
117
- #
118
- # `nil` is returned if the two values are incomparable.
119
- #
120
- # Rational(2, 3) <=> Rational(2, 3) #=> 0
121
- # Rational(5) <=> 5 #=> 0
122
- # Rational(2, 3) <=> Rational(1, 3) #=> 1
123
- # Rational(1, 3) <=> 1 #=> -1
124
- # Rational(1, 3) <=> 0.3 #=> 1
125
- #
126
- # Rational(1, 3) <=> "0.3" #=> nil
127
- #
128
- def <=>: (Numeric) -> Integer?
129
-
130
- # Returns `true` if `rat` equals `object` numerically.
131
- #
132
- # Rational(2, 3) == Rational(2, 3) #=> true
133
- # Rational(5) == 5 #=> true
134
- # Rational(0) == 0.0 #=> true
135
- # Rational('1/3') == 0.33 #=> false
136
- # Rational('1/2') == '1/2' #=> false
137
- #
138
- def ==: (untyped) -> bool
139
-
140
- # Returns the absolute value of `rat`.
141
- #
142
- # (1/2r).abs #=> (1/2)
143
- # (-1/2r).abs #=> (1/2)
144
- #
145
- # Rational#magnitude is an alias for Rational#abs.
146
- #
147
- def abs: () -> Rational
148
-
149
- def abs2: () -> Rational
150
-
151
- def angle: () -> (Integer | Float)
152
-
153
- alias arg angle
154
-
155
- # Returns the smallest number greater than or equal to `rat` with a precision of
156
- # `ndigits` decimal digits (default: 0).
157
- #
158
- # When the precision is negative, the returned value is an integer with at least
159
- # `ndigits.abs` trailing zeros.
160
- #
161
- # Returns a rational when `ndigits` is positive, otherwise returns an integer.
162
- #
163
- # Rational(3).ceil #=> 3
164
- # Rational(2, 3).ceil #=> 1
165
- # Rational(-3, 2).ceil #=> -1
166
- #
167
- # # decimal - 1 2 3 . 4 5 6
168
- # # ^ ^ ^ ^ ^ ^
169
- # # precision -3 -2 -1 0 +1 +2
170
- #
171
- # Rational('-123.456').ceil(+1).to_f #=> -123.4
172
- # Rational('-123.456').ceil(-1) #=> -120
173
- #
174
- def ceil: () -> Integer
175
- | (Integer digits) -> (Integer | Rational)
176
-
177
- def clone: (?freeze: bool) -> self
178
-
179
- def coerce: (Numeric) -> [Numeric, Numeric]
180
-
181
- def conj: () -> Rational
182
-
183
- def conjugate: () -> Rational
184
-
185
- # Returns the denominator (always positive).
186
- #
187
- # Rational(7).denominator #=> 1
188
- # Rational(7, 1).denominator #=> 1
189
- # Rational(9, -4).denominator #=> 4
190
- # Rational(-2, -10).denominator #=> 5
191
- #
192
- def denominator: () -> Integer
193
-
194
- def div: (Numeric) -> Integer
195
-
196
- def divmod: (Numeric) -> [Numeric, Numeric]
197
-
198
- def dup: () -> self
199
-
200
- def eql?: (untyped) -> bool
201
-
202
- # Performs division and returns the value as a Float.
203
- #
204
- # Rational(2, 3).fdiv(1) #=> 0.6666666666666666
205
- # Rational(2, 3).fdiv(0.5) #=> 1.3333333333333333
206
- # Rational(2).fdiv(3) #=> 0.6666666666666666
207
- #
208
- def fdiv: (Numeric) -> Float
209
-
210
- def finite?: () -> bool
211
-
212
- # Returns the largest number less than or equal to `rat` with a precision of
213
- # `ndigits` decimal digits (default: 0).
214
- #
215
- # When the precision is negative, the returned value is an integer with at least
216
- # `ndigits.abs` trailing zeros.
217
- #
218
- # Returns a rational when `ndigits` is positive, otherwise returns an integer.
219
- #
220
- # Rational(3).floor #=> 3
221
- # Rational(2, 3).floor #=> 0
222
- # Rational(-3, 2).floor #=> -2
223
- #
224
- # # decimal - 1 2 3 . 4 5 6
225
- # # ^ ^ ^ ^ ^ ^
226
- # # precision -3 -2 -1 0 +1 +2
227
- #
228
- # Rational('-123.456').floor(+1).to_f #=> -123.5
229
- # Rational('-123.456').floor(-1) #=> -130
230
- #
231
- def floor: () -> Integer
232
- | (Integer digits) -> (Integer | Rational)
233
-
234
- def hash: () -> Integer
235
-
236
- def i: () -> Complex
237
-
238
- def imag: () -> Integer
239
-
240
- def imaginary: () -> Integer
241
-
242
- def infinite?: () -> Integer?
243
-
244
- # Returns the value as a string for inspection.
245
- #
246
- # Rational(2).inspect #=> "(2/1)"
247
- # Rational(-8, 6).inspect #=> "(-4/3)"
248
- # Rational('1/2').inspect #=> "(1/2)"
249
- #
250
- def inspect: () -> String
251
-
252
- def integer?: () -> bool
253
-
254
- # Returns the absolute value of `rat`.
255
- #
256
- # (1/2r).abs #=> (1/2)
257
- # (-1/2r).abs #=> (1/2)
258
- #
259
- # Rational#magnitude is an alias for Rational#abs.
260
- #
261
- alias magnitude abs
262
-
263
- def modulo: (Float) -> Float
264
- | (Numeric) -> Rational
265
-
266
- # Returns `true` if `rat` is less than 0.
267
- #
268
- def negative?: () -> bool
269
-
270
- def nonzero?: () -> self?
271
-
272
- # Returns the numerator.
273
- #
274
- # Rational(7).numerator #=> 7
275
- # Rational(7, 1).numerator #=> 7
276
- # Rational(9, -4).numerator #=> -9
277
- # Rational(-2, -10).numerator #=> 1
278
- #
279
- def numerator: () -> Integer
280
-
281
- alias phase angle
282
-
283
- def polar: () -> [ Rational, Integer | Float ]
284
-
285
- # Returns `true` if `rat` is greater than 0.
286
- #
287
- def positive?: () -> bool
288
-
289
- # Performs division.
290
- #
291
- # Rational(2, 3) / Rational(2, 3) #=> (1/1)
292
- # Rational(900) / Rational(1) #=> (900/1)
293
- # Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
294
- # Rational(9, 8) / 4 #=> (9/32)
295
- # Rational(20, 9) / 9.8 #=> 0.22675736961451246
296
- #
297
- def quo: (Float) -> Float
298
- | (Complex) -> Complex
299
- | (Numeric) -> Rational
300
-
301
- # Returns a simpler approximation of the value if the optional argument `eps` is
302
- # given (rat-|eps| <= result <= rat+|eps|), self otherwise.
303
- #
304
- # r = Rational(5033165, 16777216)
305
- # r.rationalize #=> (5033165/16777216)
306
- # r.rationalize(Rational('0.01')) #=> (3/10)
307
- # r.rationalize(Rational('0.1')) #=> (1/3)
308
- #
309
- def rationalize: (?Numeric eps) -> Rational
310
-
311
- def real: () -> Rational
312
-
313
- def real?: () -> true
314
-
315
- def rect: () -> [ Rational, Numeric ]
316
-
317
- alias rectangular rect
318
-
319
- def remainder: (Float) -> Float
320
- | (Numeric) -> Rational
321
-
322
- # Returns `rat` rounded to the nearest value with a precision of `ndigits`
323
- # decimal digits (default: 0).
324
- #
325
- # When the precision is negative, the returned value is an integer with at least
326
- # `ndigits.abs` trailing zeros.
327
- #
328
- # Returns a rational when `ndigits` is positive, otherwise returns an integer.
329
- #
330
- # Rational(3).round #=> 3
331
- # Rational(2, 3).round #=> 1
332
- # Rational(-3, 2).round #=> -2
333
- #
334
- # # decimal - 1 2 3 . 4 5 6
335
- # # ^ ^ ^ ^ ^ ^
336
- # # precision -3 -2 -1 0 +1 +2
337
- #
338
- # Rational('-123.456').round(+1).to_f #=> -123.5
339
- # Rational('-123.456').round(-1) #=> -120
340
- #
341
- # The optional `half` keyword argument is available similar to Float#round.
342
- #
343
- # Rational(25, 100).round(1, half: :up) #=> (3/10)
344
- # Rational(25, 100).round(1, half: :down) #=> (1/5)
345
- # Rational(25, 100).round(1, half: :even) #=> (1/5)
346
- # Rational(35, 100).round(1, half: :up) #=> (2/5)
347
- # Rational(35, 100).round(1, half: :down) #=> (3/10)
348
- # Rational(35, 100).round(1, half: :even) #=> (2/5)
349
- # Rational(-25, 100).round(1, half: :up) #=> (-3/10)
350
- # Rational(-25, 100).round(1, half: :down) #=> (-1/5)
351
- # Rational(-25, 100).round(1, half: :even) #=> (-1/5)
352
- #
353
- def round: (?half: :up | :down | :even) -> Integer
354
- | (Integer digits, ?half: :up | :down | :even) -> (Integer | Rational)
355
-
356
- def step: (?Numeric limit, ?Numeric step) { (Rational) -> void } -> self
357
- | (?Numeric limit, ?Numeric step) -> Enumerator[Rational, self]
358
- | (?by: Numeric, ?to: Numeric) { (Rational) -> void } -> self
359
- | (?by: Numeric, ?to: Numeric) -> Enumerator[Rational, self]
360
-
361
- def to_c: () -> Complex
362
-
363
- # Returns the value as a Float.
364
- #
365
- # Rational(2).to_f #=> 2.0
366
- # Rational(9, 4).to_f #=> 2.25
367
- # Rational(-3, 4).to_f #=> -0.75
368
- # Rational(20, 3).to_f #=> 6.666666666666667
369
- #
370
- def to_f: () -> Float
371
-
372
- # Returns the truncated value as an integer.
373
- #
374
- # Equivalent to Rational#truncate.
375
- #
376
- # Rational(2, 3).to_i #=> 0
377
- # Rational(3).to_i #=> 3
378
- # Rational(300.6).to_i #=> 300
379
- # Rational(98, 71).to_i #=> 1
380
- # Rational(-31, 2).to_i #=> -15
381
- #
382
- def to_i: () -> Integer
383
-
384
- alias to_int to_i
385
-
386
- # Returns self.
387
- #
388
- # Rational(2).to_r #=> (2/1)
389
- # Rational(-8, 6).to_r #=> (-4/3)
390
- #
391
- def to_r: () -> Rational
392
-
393
- # Returns the value as a string.
394
- #
395
- # Rational(2).to_s #=> "2/1"
396
- # Rational(-8, 6).to_s #=> "-4/3"
397
- # Rational('1/2').to_s #=> "1/2"
398
- #
399
- def to_s: () -> String
400
-
401
- # Returns `rat` truncated (toward zero) to a precision of `ndigits` decimal
402
- # digits (default: 0).
403
- #
404
- # When the precision is negative, the returned value is an integer with at least
405
- # `ndigits.abs` trailing zeros.
406
- #
407
- # Returns a rational when `ndigits` is positive, otherwise returns an integer.
408
- #
409
- # Rational(3).truncate #=> 3
410
- # Rational(2, 3).truncate #=> 0
411
- # Rational(-3, 2).truncate #=> -1
412
- #
413
- # # decimal - 1 2 3 . 4 5 6
414
- # # ^ ^ ^ ^ ^ ^
415
- # # precision -3 -2 -1 0 +1 +2
416
- #
417
- # Rational('-123.456').truncate(+1).to_f #=> -123.4
418
- # Rational('-123.456').truncate(-1) #=> -120
419
- #
420
- def truncate: () -> Integer
421
- | (Integer ndigits) -> (Integer | Rational)
422
-
423
- def zero?: () -> bool
424
- end