rbs 0.12.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.gitignore +0 -1
  4. data/CHANGELOG.md +31 -0
  5. data/Gemfile +3 -0
  6. data/README.md +8 -2
  7. data/Rakefile +2 -2
  8. data/Steepfile +1 -0
  9. data/bin/annotate-with-rdoc +1 -1
  10. data/bin/setup +0 -2
  11. data/docs/CONTRIBUTING.md +1 -0
  12. data/docs/syntax.md +50 -6
  13. data/goodcheck.yml +22 -5
  14. data/lib/rbs/ast/comment.rb +1 -1
  15. data/lib/rbs/cli.rb +12 -4
  16. data/lib/rbs/constant.rb +1 -1
  17. data/lib/rbs/constant_table.rb +9 -8
  18. data/lib/rbs/definition_builder.rb +6 -7
  19. data/lib/rbs/environment.rb +5 -1
  20. data/lib/rbs/environment_loader.rb +12 -12
  21. data/lib/rbs/namespace.rb +1 -1
  22. data/lib/rbs/parser.rb +3148 -0
  23. data/lib/rbs/parser.y +10 -3
  24. data/lib/rbs/prototype/rb.rb +38 -6
  25. data/lib/rbs/prototype/runtime.rb +17 -7
  26. data/lib/rbs/test/hook.rb +2 -0
  27. data/lib/rbs/test/setup_helper.rb +4 -4
  28. data/lib/rbs/test/tester.rb +4 -1
  29. data/lib/rbs/test/type_check.rb +12 -6
  30. data/lib/rbs/type_name.rb +1 -1
  31. data/lib/rbs/variance_calculator.rb +2 -2
  32. data/lib/rbs/version.rb +1 -1
  33. data/lib/rbs/writer.rb +25 -15
  34. data/sig/constant.rbs +21 -0
  35. data/sig/constant_table.rbs +30 -0
  36. data/sig/declarations.rbs +2 -2
  37. data/sig/definition.rbs +2 -2
  38. data/sig/definition_builder.rbs +4 -5
  39. data/sig/environment_loader.rbs +54 -0
  40. data/sig/members.rbs +2 -2
  41. data/sig/method_types.rbs +1 -1
  42. data/sig/namespace.rbs +4 -4
  43. data/sig/parser.rbs +25 -0
  44. data/sig/substitution.rbs +3 -3
  45. data/sig/typename.rbs +1 -1
  46. data/sig/types.rbs +1 -1
  47. data/sig/version.rbs +3 -0
  48. data/sig/writer.rbs +40 -0
  49. data/stdlib/base64/base64.rbs +1 -1
  50. data/stdlib/benchmark/benchmark.rbs +2 -2
  51. data/stdlib/builtin/array.rbs +124 -120
  52. data/stdlib/builtin/basic_object.rbs +54 -54
  53. data/stdlib/builtin/binding.rbs +42 -42
  54. data/stdlib/builtin/builtin.rbs +28 -0
  55. data/stdlib/builtin/class.rbs +33 -33
  56. data/stdlib/builtin/complex.rbs +90 -90
  57. data/stdlib/builtin/encoding.rbs +33 -33
  58. data/stdlib/builtin/enumerable.rbs +58 -52
  59. data/stdlib/builtin/enumerator.rbs +35 -35
  60. data/stdlib/builtin/errors.rbs +2 -2
  61. data/stdlib/builtin/exception.rbs +50 -50
  62. data/stdlib/builtin/false_class.rbs +6 -6
  63. data/stdlib/builtin/fiber.rbs +14 -14
  64. data/stdlib/builtin/fiber_error.rbs +1 -1
  65. data/stdlib/builtin/float.rbs +161 -161
  66. data/stdlib/builtin/gc.rbs +3 -3
  67. data/stdlib/builtin/hash.rbs +7 -7
  68. data/stdlib/builtin/io.rbs +88 -88
  69. data/stdlib/builtin/kernel.rbs +71 -153
  70. data/stdlib/builtin/match_data.rbs +1 -1
  71. data/stdlib/builtin/method.rbs +19 -19
  72. data/stdlib/builtin/module.rbs +13 -13
  73. data/stdlib/builtin/nil_class.rbs +20 -20
  74. data/stdlib/builtin/numeric.rbs +101 -101
  75. data/stdlib/builtin/object.rbs +173 -173
  76. data/stdlib/builtin/proc.rbs +91 -91
  77. data/stdlib/builtin/random.rbs +1 -1
  78. data/stdlib/builtin/range.rbs +3 -5
  79. data/stdlib/builtin/rational.rbs +83 -83
  80. data/stdlib/builtin/signal.rbs +7 -7
  81. data/stdlib/builtin/string.rbs +10 -10
  82. data/stdlib/builtin/string_io.rbs +8 -8
  83. data/stdlib/builtin/struct.rbs +1 -1
  84. data/stdlib/builtin/symbol.rbs +1 -1
  85. data/stdlib/builtin/thread.rbs +189 -189
  86. data/stdlib/builtin/thread_group.rbs +2 -2
  87. data/stdlib/builtin/true_class.rbs +10 -10
  88. data/stdlib/builtin/warning.rbs +1 -1
  89. data/stdlib/coverage/coverage.rbs +2 -2
  90. data/stdlib/csv/csv.rbs +1 -1
  91. data/stdlib/date/date.rbs +4 -4
  92. data/stdlib/date/date_time.rbs +1 -1
  93. data/stdlib/find/find.rbs +12 -12
  94. data/stdlib/logger/log_device.rbs +1 -1
  95. data/stdlib/logger/logger.rbs +1 -1
  96. data/stdlib/pathname/pathname.rbs +41 -39
  97. data/stdlib/pstore/pstore.rbs +287 -0
  98. data/stdlib/pty/pty.rbs +5 -29
  99. data/stdlib/tmpdir/tmpdir.rbs +12 -12
  100. data/stdlib/uri/generic.rbs +2 -2
  101. data/stdlib/uri/http.rbs +158 -0
  102. data/stdlib/uri/https.rbs +108 -0
  103. data/stdlib/uri/ldap.rbs +224 -0
  104. data/stdlib/uri/ldaps.rbs +108 -0
  105. data/steep/Gemfile.lock +13 -17
  106. metadata +13 -3
@@ -95,7 +95,7 @@ class MatchData
95
95
  # f3 #=> "113"
96
96
  # f4 #=> "8"
97
97
  #
98
- def captures: () -> ::Array[String?]
98
+ def captures: () -> ::Array[String?]
99
99
 
100
100
  # Returns the offset of the character immediately following the end of the *n*th
101
101
  # element of the match array in the string. *n* can be a string or symbol to
@@ -4,7 +4,7 @@ class Method < Object
4
4
 
5
5
  # Invokes the *meth* with the specified arguments, returning the method’s
6
6
  # return value.
7
- #
7
+ #
8
8
  # ```ruby
9
9
  # m = 12.method("+")
10
10
  # m.call(3) #=> 15
@@ -15,12 +15,12 @@ class Method < Object
15
15
  # Returns a proc that is the composition of this method and the given *g*
16
16
  # . The returned proc takes a variable number of arguments, calls *g* with
17
17
  # them then calls this method with the result.
18
- #
18
+ #
19
19
  # ```ruby
20
20
  # def f(x)
21
21
  # x * x
22
22
  # end
23
- #
23
+ #
24
24
  # f = self.method(:f)
25
25
  # g = proc {|x| x + x }
26
26
  # p (f << g).call(2) #=> 16
@@ -30,10 +30,10 @@ class Method < Object
30
30
  # Invokes the method with `obj` as the parameter like
31
31
  # [call](Method.downloaded.ruby_doc#method-i-call). This allows a method
32
32
  # object to be the target of a `when` clause in a case statement.
33
- #
33
+ #
34
34
  # ```ruby
35
35
  # require 'prime'
36
- #
36
+ #
37
37
  # case 1373
38
38
  # when Prime.method(:prime?)
39
39
  # # ...
@@ -44,12 +44,12 @@ class Method < Object
44
44
  # Returns a proc that is the composition of this method and the given *g*
45
45
  # . The returned proc takes a variable number of arguments, calls *g* with
46
46
  # them then calls this method with the result.
47
- #
47
+ #
48
48
  # ```ruby
49
49
  # def f(x)
50
50
  # x * x
51
51
  # end
52
- #
52
+ #
53
53
  # f = self.method(:f)
54
54
  # g = proc {|x| x + x }
55
55
  # p (f >> g).call(2) #=> 8
@@ -58,7 +58,7 @@ class Method < Object
58
58
 
59
59
  # Invokes the *meth* with the specified arguments, returning the method’s
60
60
  # return value.
61
- #
61
+ #
62
62
  # ```ruby
63
63
  # m = 12.method("+")
64
64
  # m.call(3) #=> 15
@@ -74,7 +74,7 @@ class Method < Object
74
74
  # argument being mandatory if any keyword argument is mandatory. For
75
75
  # methods written in C, returns -1 if the call takes a variable number of
76
76
  # arguments.
77
- #
77
+ #
78
78
  # class C
79
79
  # def one; end
80
80
  # def two(a); end
@@ -98,7 +98,7 @@ class Method < Object
98
98
  # c.method(:eight).arity #=> 1
99
99
  # c.method(:nine).arity #=> 1
100
100
  # c.method(:ten).arity #=> -2
101
- #
101
+ #
102
102
  # "cat".method(:size).arity #=> 0
103
103
  # "cat".method(:replace).arity #=> 1
104
104
  # "cat".method(:squeeze).arity #=> -1
@@ -106,14 +106,14 @@ class Method < Object
106
106
  def arity: () -> Integer
107
107
 
108
108
  # Returns a clone of this method.
109
- #
109
+ #
110
110
  # ```ruby
111
111
  # class A
112
112
  # def foo
113
113
  # return "bar"
114
114
  # end
115
115
  # end
116
- #
116
+ #
117
117
  # m = A.new.method(:foo)
118
118
  # m.call # => "bar"
119
119
  # n = m.clone.call # => "bar"
@@ -126,7 +126,7 @@ class Method < Object
126
126
  def name: () -> Symbol
127
127
 
128
128
  # Returns the original name of the method.
129
- #
129
+ #
130
130
  # ```ruby
131
131
  # class C
132
132
  # def foo; end
@@ -137,24 +137,24 @@ class Method < Object
137
137
  def original_name: () -> Symbol
138
138
 
139
139
  # Returns the class or module that defines the method. See also receiver.
140
- #
140
+ #
141
141
  # ```ruby
142
142
  # (1..3).method(:map).owner #=> Enumerable
143
143
  # ```
144
144
  def owner: () -> (Class | Module)
145
145
 
146
146
  # Returns the parameter information of this method.
147
- #
147
+ #
148
148
  # ```ruby
149
149
  # def foo(bar); end
150
150
  # method(:foo).parameters #=> [[:req, :bar]]
151
- #
151
+ #
152
152
  # def foo(bar, baz, bat, &blk); end
153
153
  # method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:req, :bat], [:block, :blk]]
154
- #
154
+ #
155
155
  # def foo(bar, *args); end
156
156
  # method(:foo).parameters #=> [[:req, :bar], [:rest, :args]]
157
- #
157
+ #
158
158
  # def foo(bar, baz, *args, &blk); end
159
159
  # method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:rest, :args], [:block, :blk]]
160
160
  # ```
@@ -164,7 +164,7 @@ class Method < Object
164
164
  ]
165
165
 
166
166
  # Returns the bound receiver of the method object.
167
- #
167
+ #
168
168
  # ```ruby
169
169
  # (1..3).method(:map).receiver # => 1..3
170
170
  # ```
@@ -237,7 +237,7 @@ class Module < Object
237
237
  # B.autoload?(:CONST) #=> "const.rb", found in A (ancestor)
238
238
  # B.autoload?(:CONST, false) #=> nil, not found in B itself
239
239
  #
240
- def autoload?: (Symbol name, ?bool inherit) -> String?
240
+ def autoload?: (Symbol name, ?boolish inherit) -> String?
241
241
 
242
242
  # Evaluates the string or block in the context of *mod*, except that when a
243
243
  # block is given, constant/class variable lookup is not affected. This can be
@@ -329,7 +329,7 @@ class Module < Object
329
329
  # Two.class_variables #=> [:@@var2, :@@var1]
330
330
  # Two.class_variables(false) #=> [:@@var2]
331
331
  #
332
- def class_variables: (?bool inherit) -> ::Array[Symbol]
332
+ def class_variables: (?boolish inherit) -> ::Array[Symbol]
333
333
 
334
334
  # Says whether *mod* or its ancestors have a constant with the given name:
335
335
  #
@@ -364,7 +364,7 @@ class Module < Object
364
364
  #
365
365
  # Hash.const_defined? 'foobar' #=> NameError: wrong constant name foobar
366
366
  #
367
- def const_defined?: (Symbol | String arg0, ?bool inherit) -> bool
367
+ def const_defined?: (Symbol | String name, ?boolish inherit) -> bool
368
368
 
369
369
  # Checks for a constant with the given name in *mod*. If `inherit` is set, the
370
370
  # lookup will also search the ancestors (and `Object` if *mod* is a `Module`).
@@ -398,7 +398,7 @@ class Module < Object
398
398
  #
399
399
  # Object.const_get 'foobar' #=> NameError: wrong constant name foobar
400
400
  #
401
- def const_get: (Symbol | String arg0, ?bool inherit) -> untyped
401
+ def const_get: (Symbol | String name, ?boolish inherit) -> untyped
402
402
 
403
403
  # Invoked when a reference is made to an undefined constant in *mod*. It is
404
404
  # passed a symbol for the undefined constant, and returns a value to be used for
@@ -455,7 +455,7 @@ class Module < Object
455
455
  #
456
456
  # Also see Module#const_defined?.
457
457
  #
458
- def constants: (?bool inherit) -> ::Array[Symbol]
458
+ def constants: (?boolish inherit) -> ::Array[Symbol]
459
459
 
460
460
  # Defines an instance method in the receiver. The *method* parameter can be a
461
461
  # `Proc`, a `Method` or an `UnboundMethod` object. If a block is specified, it
@@ -662,7 +662,7 @@ class Module < Object
662
662
  # C.instance_methods(false) #=> [:method3]
663
663
  # C.instance_methods.include?(:method2) #=> true
664
664
  #
665
- def instance_methods: (?bool include_super) -> ::Array[Symbol]
665
+ def instance_methods: (?boolish include_super) -> ::Array[Symbol]
666
666
 
667
667
  # Invoked as a callback whenever an instance method is added to the receiver.
668
668
  #
@@ -709,7 +709,7 @@ class Module < Object
709
709
  # C.method_defined? "method4" #=> false
710
710
  # C.method_defined? "private_method2" #=> false
711
711
  #
712
- def method_defined?: (Symbol | String arg0, ?bool inherit) -> bool
712
+ def method_defined?: (Symbol | String name, ?boolish inherit) -> bool
713
713
 
714
714
  # Invoked as a callback whenever an instance method is removed from the
715
715
  # receiver.
@@ -881,7 +881,7 @@ class Module < Object
881
881
  # Mod.instance_methods #=> [:method2]
882
882
  # Mod.private_instance_methods #=> [:method1]
883
883
  #
884
- def private_instance_methods: (?bool include_super) -> ::Array[Symbol]
884
+ def private_instance_methods: (?boolish include_super) -> ::Array[Symbol]
885
885
 
886
886
  # Returns `true` if the named private method is defined by *mod*. If *inherit*
887
887
  # is set, the lookup will also search *mod*'s ancestors. String arguments are
@@ -906,7 +906,7 @@ class Module < Object
906
906
  # C.private_method_defined? "method2", false #=> false
907
907
  # C.method_defined? "method2" #=> false
908
908
  #
909
- def private_method_defined?: (Symbol | String arg0, ?bool inherit) -> bool
909
+ def private_method_defined?: (Symbol | String name, ?boolish inherit) -> bool
910
910
 
911
911
  # With no arguments, sets the default visibility for subsequently defined
912
912
  # methods to protected. With arguments, sets the named methods to have protected
@@ -926,7 +926,7 @@ class Module < Object
926
926
  # Returns a list of the protected instance methods defined in *mod*. If the
927
927
  # optional parameter is `false`, the methods of any ancestors are not included.
928
928
  #
929
- def protected_instance_methods: (?bool include_super) -> ::Array[Symbol]
929
+ def protected_instance_methods: (?boolish include_super) -> ::Array[Symbol]
930
930
 
931
931
  # Returns `true` if the named protected method is defined *mod*. If *inherit*
932
932
  # is set, the lookup will also search *mod*'s ancestors. String arguments are
@@ -951,7 +951,7 @@ class Module < Object
951
951
  # C.protected_method_defined? "method2", false #=> false
952
952
  # C.method_defined? "method2" #=> true
953
953
  #
954
- def protected_method_defined?: (Symbol | String arg0, ?bool inherit) -> bool
954
+ def protected_method_defined?: (Symbol | String name, ?boolish inherit) -> bool
955
955
 
956
956
  # With no arguments, sets the default visibility for subsequently defined
957
957
  # methods to public. With arguments, sets the named methods to have public
@@ -976,7 +976,7 @@ class Module < Object
976
976
  # Returns a list of the public instance methods defined in *mod*. If the
977
977
  # optional parameter is `false`, the methods of any ancestors are not included.
978
978
  #
979
- def public_instance_methods: (?bool include_super) -> ::Array[Symbol]
979
+ def public_instance_methods: (?boolish include_super) -> ::Array[Symbol]
980
980
 
981
981
  # Returns `true` if the named public method is defined by *mod*. If *inherit*
982
982
  # is set, the lookup will also search *mod*'s ancestors. String arguments are
@@ -1001,7 +1001,7 @@ class Module < Object
1001
1001
  # C.public_method_defined? "method2" #=> false
1002
1002
  # C.method_defined? "method2" #=> true
1003
1003
  #
1004
- def public_method_defined?: (Symbol | String arg0, ?bool inherit) -> bool
1004
+ def public_method_defined?: (Symbol | String name, ?boolish inherit) -> bool
1005
1005
 
1006
1006
  # Refine *mod* in the receiver.
1007
1007
  #
@@ -1,81 +1,81 @@
1
1
  # The class of the singleton object `nil`.
2
- #
2
+ #
3
3
  class NilClass
4
4
  public
5
5
 
6
6
  # And---Returns `false`. *obj* is always evaluated as it is the argument to a
7
7
  # method call---there is no short-circuit evaluation in this case.
8
- #
8
+ #
9
9
  def &: (untyped obj) -> bool
10
10
 
11
11
  # Case Equality -- For class Object, effectively the same as calling `#==`, but
12
12
  # typically overridden by descendants to provide meaningful semantics in `case`
13
13
  # statements.
14
- #
14
+ #
15
15
  def ===: (nil) -> true
16
16
  | (untyped obj) -> bool
17
17
 
18
18
  # Dummy pattern matching -- always returns nil.
19
- #
19
+ #
20
20
  def =~: (untyped obj) -> nil
21
21
 
22
22
  # Exclusive Or---If *obj* is `nil` or `false`, returns `false`; otherwise,
23
23
  # returns `true`.
24
- #
24
+ #
25
25
  def ^: (nil) -> false
26
26
  | (false) -> false
27
27
  | (untyped obj) -> bool
28
28
 
29
29
  # Always returns the string "nil".
30
- #
30
+ #
31
31
  def inspect: () -> "nil"
32
32
 
33
33
  # Only the object *nil* responds `true` to `nil?`.
34
- #
34
+ #
35
35
  def nil?: () -> bool
36
36
 
37
37
  # Returns zero as a rational. The optional argument `eps` is always ignored.
38
- #
38
+ #
39
39
  def rationalize: (?untyped eps) -> Rational
40
40
 
41
41
  # Always returns an empty array.
42
- #
42
+ #
43
43
  # nil.to_a #=> []
44
- #
44
+ #
45
45
  def to_a: () -> [ ]
46
46
 
47
47
  # Returns zero as a complex.
48
- #
48
+ #
49
49
  def to_c: () -> Complex
50
50
 
51
51
  # Always returns zero.
52
- #
52
+ #
53
53
  # nil.to_f #=> 0.0
54
- #
54
+ #
55
55
  def to_f: () -> Float
56
56
 
57
57
  # Always returns an empty hash.
58
- #
58
+ #
59
59
  # nil.to_h #=> {}
60
- #
60
+ #
61
61
  def to_h: () -> ::Hash[untyped, untyped]
62
62
 
63
63
  # Always returns zero.
64
- #
64
+ #
65
65
  # nil.to_i #=> 0
66
- #
66
+ #
67
67
  def to_i: () -> 0
68
68
 
69
69
  # Returns zero as a rational.
70
- #
70
+ #
71
71
  def to_r: () -> Rational
72
72
 
73
73
  # Always returns the empty string.
74
- #
74
+ #
75
75
  def to_s: () -> ""
76
76
 
77
77
  # Or---Returns `false` if *obj* is `nil` or `false`; `true` otherwise.
78
- #
78
+ #
79
79
  def |: (nil) -> false
80
80
  | (false) -> false
81
81
  | (untyped obj) -> bool
@@ -1,176 +1,176 @@
1
1
  # Numeric is the class from which all higher-level numeric classes should
2
2
  # inherit.
3
- #
3
+ #
4
4
  # Numeric allows instantiation of heap-allocated objects. Other core numeric
5
5
  # classes such as Integer are implemented as immediates, which means that each
6
6
  # Integer is a single immutable object which is always passed by value.
7
- #
7
+ #
8
8
  # a = 1
9
9
  # 1.object_id == a.object_id #=> true
10
- #
10
+ #
11
11
  # There can only ever be one instance of the integer `1`, for example. Ruby
12
12
  # ensures this by preventing instantiation. If duplication is attempted, the
13
13
  # same instance is returned.
14
- #
14
+ #
15
15
  # Integer.new(1) #=> NoMethodError: undefined method `new' for Integer:Class
16
16
  # 1.dup #=> 1
17
17
  # 1.object_id == 1.dup.object_id #=> true
18
- #
18
+ #
19
19
  # For this reason, Numeric should be used when defining other numeric classes.
20
- #
20
+ #
21
21
  # Classes which inherit from Numeric must implement `coerce`, which returns a
22
22
  # two-member Array containing an object that has been coerced into an instance
23
23
  # of the new class and `self` (see #coerce).
24
- #
24
+ #
25
25
  # Inheriting classes should also implement arithmetic operator methods (`+`,
26
26
  # `-`, `*` and `/`) and the `<=>` operator (see Comparable). These methods may
27
27
  # rely on `coerce` to ensure interoperability with instances of other numeric
28
28
  # classes.
29
- #
29
+ #
30
30
  # class Tally < Numeric
31
31
  # def initialize(string)
32
32
  # @string = string
33
33
  # end
34
- #
34
+ #
35
35
  # def to_s
36
36
  # @string
37
37
  # end
38
- #
38
+ #
39
39
  # def to_i
40
40
  # @string.size
41
41
  # end
42
- #
42
+ #
43
43
  # def coerce(other)
44
44
  # [self.class.new('|' * other.to_i), self]
45
45
  # end
46
- #
46
+ #
47
47
  # def <=>(other)
48
48
  # to_i <=> other.to_i
49
49
  # end
50
- #
50
+ #
51
51
  # def +(other)
52
52
  # self.class.new('|' * (to_i + other.to_i))
53
53
  # end
54
- #
54
+ #
55
55
  # def -(other)
56
56
  # self.class.new('|' * (to_i - other.to_i))
57
57
  # end
58
- #
58
+ #
59
59
  # def *(other)
60
60
  # self.class.new('|' * (to_i * other.to_i))
61
61
  # end
62
- #
62
+ #
63
63
  # def /(other)
64
64
  # self.class.new('|' * (to_i / other.to_i))
65
65
  # end
66
66
  # end
67
- #
67
+ #
68
68
  # tally = Tally.new('||')
69
69
  # puts tally * 2 #=> "||||"
70
70
  # puts tally > 1 #=> true
71
- #
71
+ #
72
72
  class Numeric
73
73
  include Comparable
74
74
 
75
75
  public
76
76
 
77
77
  # `x.modulo(y)` means `x-y*(x/y).floor`.
78
- #
78
+ #
79
79
  # Equivalent to `num.divmod(numeric)[1]`.
80
- #
80
+ #
81
81
  # See Numeric#divmod.
82
- #
82
+ #
83
83
  def %: (Numeric) -> Numeric
84
84
 
85
85
  # Unary Plus---Returns the receiver.
86
- #
86
+ #
87
87
  def +@: () -> Numeric
88
88
 
89
89
  # Unary Minus---Returns the receiver, negated.
90
- #
90
+ #
91
91
  def -@: () -> Numeric
92
92
 
93
93
  # Returns zero if `number` equals `other`, otherwise returns `nil`.
94
- #
94
+ #
95
95
  def <=>: (Numeric other) -> Integer
96
96
 
97
97
  # Returns the absolute value of `num`.
98
- #
98
+ #
99
99
  # 12.abs #=> 12
100
100
  # (-34.56).abs #=> 34.56
101
101
  # -34.56.abs #=> 34.56
102
- #
102
+ #
103
103
  # Numeric#magnitude is an alias for Numeric#abs.
104
- #
104
+ #
105
105
  def abs: () -> Numeric
106
106
 
107
107
  # Returns square of self.
108
- #
108
+ #
109
109
  def abs2: () -> Numeric
110
110
 
111
111
  # Returns 0 if the value is positive, pi otherwise.
112
- #
112
+ #
113
113
  def angle: () -> Numeric
114
114
 
115
115
  # Returns 0 if the value is positive, pi otherwise.
116
- #
116
+ #
117
117
  alias arg angle
118
118
 
119
119
  # Returns the smallest number greater than or equal to `num` with a precision of
120
120
  # `ndigits` decimal digits (default: 0).
121
- #
121
+ #
122
122
  # Numeric implements this by converting its value to a Float and invoking
123
123
  # Float#ceil.
124
- #
124
+ #
125
125
  def ceil: () -> Integer
126
126
  | (Integer digits) -> (Integer | Numeric)
127
127
 
128
128
  # If `numeric` is the same type as `num`, returns an array `[numeric, num]`.
129
129
  # Otherwise, returns an array with both `numeric` and `num` represented as Float
130
130
  # objects.
131
- #
131
+ #
132
132
  # This coercion mechanism is used by Ruby to handle mixed-type numeric
133
133
  # operations: it is intended to find a compatible common type between the two
134
134
  # operands of the operator.
135
- #
135
+ #
136
136
  # 1.coerce(2.5) #=> [2.5, 1.0]
137
137
  # 1.2.coerce(3) #=> [3.0, 1.2]
138
138
  # 1.coerce(2) #=> [2, 1]
139
- #
139
+ #
140
140
  def coerce: (Numeric) -> [ Numeric, Numeric ]
141
141
 
142
142
  # Returns self.
143
- #
143
+ #
144
144
  def conj: () -> Numeric
145
145
 
146
146
  # Returns self.
147
- #
147
+ #
148
148
  def conjugate: () -> Numeric
149
149
 
150
150
  # Returns the denominator (always positive).
151
- #
151
+ #
152
152
  def denominator: () -> Integer
153
153
 
154
154
  # Uses `/` to perform division, then converts the result to an integer. Numeric
155
155
  # does not define the `/` operator; this is left to subclasses.
156
- #
156
+ #
157
157
  # Equivalent to `num.divmod(numeric)[0]`.
158
- #
158
+ #
159
159
  # See Numeric#divmod.
160
- #
160
+ #
161
161
  def div: (Numeric) -> Integer
162
162
 
163
163
  # Returns an array containing the quotient and modulus obtained by dividing
164
164
  # `num` by `numeric`.
165
- #
165
+ #
166
166
  # If `q, r = x.divmod(y)`, then
167
- #
167
+ #
168
168
  # q = floor(x/y)
169
169
  # x = q*y + r
170
- #
170
+ #
171
171
  # The quotient is rounded toward negative infinity, as shown in the following
172
172
  # table:
173
- #
173
+ #
174
174
  # a | b | a.divmod(b) | a/b | a.modulo(b) | a.remainder(b)
175
175
  # ------+-----+---------------+---------+-------------+---------------
176
176
  # 13 | 4 | 3, 1 | 3 | 1 | 1
@@ -188,222 +188,222 @@ class Numeric
188
188
  # -11.5 | 4 | -3, 0.5 | -2.875 | 0.5 | -3.5
189
189
  # ------+-----+---------------+---------+-------------+---------------
190
190
  # -11.5 | -4 | 2, -3.5 | 2.875 | -3.5 | -3.5
191
- #
191
+ #
192
192
  # Examples
193
- #
193
+ #
194
194
  # 11.divmod(3) #=> [3, 2]
195
195
  # 11.divmod(-3) #=> [-4, -1]
196
196
  # 11.divmod(3.5) #=> [3, 0.5]
197
197
  # (-11).divmod(3.5) #=> [-4, 3.0]
198
198
  # 11.5.divmod(3.5) #=> [3, 1.0]
199
- #
199
+ #
200
200
  def divmod: (Numeric) -> [ Numeric, Numeric ]
201
201
 
202
202
  # Returns `true` if `num` and `numeric` are the same type and have equal values.
203
203
  # Contrast this with Numeric#==, which performs type conversions.
204
- #
204
+ #
205
205
  # 1 == 1.0 #=> true
206
206
  # 1.eql?(1.0) #=> false
207
207
  # 1.0.eql?(1.0) #=> true
208
- #
208
+ #
209
209
  def eql?: (untyped) -> bool
210
210
 
211
211
  # Returns float division.
212
- #
212
+ #
213
213
  def fdiv: (Numeric) -> Numeric
214
214
 
215
215
  # Returns `true` if `num` is a finite number, otherwise returns `false`.
216
- #
216
+ #
217
217
  def finite?: () -> bool
218
218
 
219
219
  # Returns the largest number less than or equal to `num` with a precision of
220
220
  # `ndigits` decimal digits (default: 0).
221
- #
221
+ #
222
222
  # Numeric implements this by converting its value to a Float and invoking
223
223
  # Float#floor.
224
- #
224
+ #
225
225
  def floor: () -> Integer
226
226
  | (Integer digits) -> Numeric
227
227
 
228
228
  # Returns the corresponding imaginary number. Not available for complex numbers.
229
- #
229
+ #
230
230
  # -42.i #=> (0-42i)
231
231
  # 2.0.i #=> (0+2.0i)
232
- #
232
+ #
233
233
  def i: () -> Complex
234
234
 
235
235
  # Returns zero.
236
- #
236
+ #
237
237
  def imag: () -> Numeric
238
238
 
239
239
  # Returns zero.
240
- #
240
+ #
241
241
  def imaginary: () -> Numeric
242
242
 
243
243
  # Returns `nil`, -1, or 1 depending on whether the value is finite, `-Infinity`,
244
244
  # or `+Infinity`.
245
- #
245
+ #
246
246
  def infinite?: () -> Integer?
247
247
 
248
248
  # Returns `true` if `num` is an Integer.
249
- #
249
+ #
250
250
  # 1.0.integer? #=> false
251
251
  # 1.integer? #=> true
252
- #
252
+ #
253
253
  def integer?: () -> bool
254
254
 
255
255
  # Returns the absolute value of `num`.
256
- #
256
+ #
257
257
  # 12.abs #=> 12
258
258
  # (-34.56).abs #=> 34.56
259
259
  # -34.56.abs #=> 34.56
260
- #
260
+ #
261
261
  # Numeric#magnitude is an alias for Numeric#abs.
262
- #
262
+ #
263
263
  alias magnitude abs
264
264
 
265
265
  # `x.modulo(y)` means `x-y*(x/y).floor`.
266
- #
266
+ #
267
267
  # Equivalent to `num.divmod(numeric)[1]`.
268
- #
268
+ #
269
269
  # See Numeric#divmod.
270
- #
270
+ #
271
271
  def modulo: (Numeric) -> Numeric
272
272
 
273
273
  # Returns `true` if `num` is less than 0.
274
- #
274
+ #
275
275
  def negative?: () -> bool
276
276
 
277
277
  # Returns `self` if `num` is not zero, `nil` otherwise.
278
- #
278
+ #
279
279
  # This behavior is useful when chaining comparisons:
280
- #
280
+ #
281
281
  # a = %w( z Bb bB bb BB a aA Aa AA A )
282
282
  # b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
283
283
  # b #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
284
- #
284
+ #
285
285
  def nonzero?: () -> self?
286
286
 
287
287
  # Returns the numerator.
288
- #
288
+ #
289
289
  def numerator: () -> Numeric
290
290
 
291
291
  # Returns 0 if the value is positive, pi otherwise.
292
- #
292
+ #
293
293
  alias phase angle
294
294
 
295
295
  # Returns an array; [num.abs, num.arg].
296
- #
296
+ #
297
297
  def polar: () -> [ Numeric, Numeric ]
298
298
 
299
299
  # Returns `true` if `num` is greater than 0.
300
- #
300
+ #
301
301
  def positive?: () -> bool
302
302
 
303
303
  # Returns the most exact division (rational for integers, float for floats).
304
- #
304
+ #
305
305
  def quo: (Numeric) -> Numeric
306
306
 
307
307
  # Returns self.
308
- #
308
+ #
309
309
  def real: () -> Numeric
310
310
 
311
311
  # Returns `true` if `num` is a real number (i.e. not Complex).
312
- #
312
+ #
313
313
  def real?: () -> bool
314
314
 
315
315
  # Returns an array; [num, 0].
316
- #
316
+ #
317
317
  def rect: () -> [ Numeric, Numeric ]
318
318
 
319
319
  # Returns an array; [num, 0].
320
- #
320
+ #
321
321
  alias rectangular rect
322
322
 
323
323
  # `x.remainder(y)` means `x-y*(x/y).truncate`.
324
- #
324
+ #
325
325
  # See Numeric#divmod.
326
- #
326
+ #
327
327
  def remainder: (Numeric) -> Numeric
328
328
 
329
329
  # Returns `num` rounded to the nearest value with a precision of `ndigits`
330
330
  # decimal digits (default: 0).
331
- #
331
+ #
332
332
  # Numeric implements this by converting its value to a Float and invoking
333
333
  # Float#round.
334
- #
334
+ #
335
335
  def round: () -> Integer
336
336
  | (Integer digits) -> Numeric
337
337
 
338
338
  # Invokes the given block with the sequence of numbers starting at `num`,
339
339
  # incremented by `step` (defaulted to `1`) on each call.
340
- #
340
+ #
341
341
  # The loop finishes when the value to be passed to the block is greater than
342
342
  # `limit` (if `step` is positive) or less than `limit` (if `step` is negative),
343
343
  # where `limit` is defaulted to infinity.
344
- #
344
+ #
345
345
  # In the recommended keyword argument style, either or both of `step` and
346
346
  # `limit` (default infinity) can be omitted. In the fixed position argument
347
347
  # style, zero as a step (i.e. `num.step(limit, 0)`) is not allowed for
348
348
  # historical compatibility reasons.
349
- #
349
+ #
350
350
  # If all the arguments are integers, the loop operates using an integer counter.
351
- #
351
+ #
352
352
  # If any of the arguments are floating point numbers, all are converted to
353
353
  # floats, and the loop is executed *floor(n + n*Float::EPSILON) + 1* times,
354
354
  # where *n = (limit - num)/step*.
355
- #
355
+ #
356
356
  # Otherwise, the loop starts at `num`, uses either the less-than (`<`) or
357
357
  # greater-than (`>`) operator to compare the counter against `limit`, and
358
358
  # increments itself using the `+` operator.
359
- #
359
+ #
360
360
  # If no block is given, an Enumerator is returned instead. Especially, the
361
361
  # enumerator is an Enumerator::ArithmeticSequence if both `limit` and `step` are
362
362
  # kind of Numeric or `nil`.
363
- #
363
+ #
364
364
  # For example:
365
- #
365
+ #
366
366
  # p 1.step.take(4)
367
367
  # p 10.step(by: -1).take(4)
368
368
  # 3.step(to: 5) {|i| print i, " " }
369
369
  # 1.step(10, 2) {|i| print i, " " }
370
370
  # Math::E.step(to: Math::PI, by: 0.2) {|f| print f, " " }
371
- #
371
+ #
372
372
  # Will produce:
373
- #
373
+ #
374
374
  # [1, 2, 3, 4]
375
375
  # [10, 9, 8, 7]
376
376
  # 3 4 5
377
377
  # 1 3 5 7 9
378
378
  # 2.718281828459045 2.9182818284590453 3.118281828459045
379
- #
379
+ #
380
380
  def step: (?Numeric limit, ?Numeric step) { (Numeric) -> void } -> self
381
381
  | (?Numeric limit, ?Numeric step) -> Enumerator[Numeric, self]
382
382
  | (?by: Numeric, ?to: Numeric) { (Numeric) -> void } -> self
383
383
  | (?by: Numeric, ?to: Numeric) -> Enumerator[Numeric, self]
384
384
 
385
385
  # Returns the value as a complex.
386
- #
386
+ #
387
387
  def to_c: () -> Complex
388
388
 
389
389
  # Invokes the child class's `to_i` method to convert `num` to an integer.
390
- #
390
+ #
391
391
  # 1.0.class #=> Float
392
392
  # 1.0.to_int.class #=> Integer
393
393
  # 1.0.to_i.class #=> Integer
394
- #
394
+ #
395
395
  def to_int: () -> Integer
396
396
 
397
397
  # Returns `num` truncated (toward zero) to a precision of `ndigits` decimal
398
398
  # digits (default: 0).
399
- #
399
+ #
400
400
  # Numeric implements this by converting its value to a Float and invoking
401
401
  # Float#truncate.
402
- #
402
+ #
403
403
  def truncate: () -> Integer
404
404
  | (Integer ndigits) -> (Integer | Numeric)
405
405
 
406
406
  # Returns `true` if `num` has a zero value.
407
- #
407
+ #
408
408
  def zero?: () -> bool
409
409
  end