rbs 0.13.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.gitignore +0 -1
  4. data/CHANGELOG.md +7 -2
  5. data/Gemfile +3 -0
  6. data/README.md +8 -2
  7. data/Steepfile +1 -0
  8. data/bin/annotate-with-rdoc +1 -1
  9. data/bin/setup +0 -2
  10. data/docs/CONTRIBUTING.md +1 -0
  11. data/goodcheck.yml +22 -5
  12. data/lib/rbs/ast/comment.rb +1 -1
  13. data/lib/rbs/definition_builder.rb +4 -5
  14. data/lib/rbs/environment.rb +1 -1
  15. data/lib/rbs/namespace.rb +1 -1
  16. data/lib/rbs/parser.rb +3146 -0
  17. data/lib/rbs/parser.y +7 -2
  18. data/lib/rbs/test/setup_helper.rb +4 -4
  19. data/lib/rbs/test/type_check.rb +2 -2
  20. data/lib/rbs/type_name.rb +1 -1
  21. data/lib/rbs/variance_calculator.rb +1 -1
  22. data/lib/rbs/version.rb +1 -1
  23. data/lib/rbs/writer.rb +1 -1
  24. data/sig/constant.rbs +2 -2
  25. data/sig/constant_table.rbs +10 -10
  26. data/sig/declarations.rbs +1 -1
  27. data/sig/definition.rbs +1 -1
  28. data/sig/namespace.rbs +3 -3
  29. data/sig/parser.rbs +25 -0
  30. data/sig/substitution.rbs +3 -3
  31. data/sig/typename.rbs +1 -1
  32. data/sig/types.rbs +1 -1
  33. data/sig/writer.rbs +15 -15
  34. data/stdlib/benchmark/benchmark.rbs +2 -2
  35. data/stdlib/builtin/basic_object.rbs +54 -54
  36. data/stdlib/builtin/binding.rbs +42 -42
  37. data/stdlib/builtin/class.rbs +33 -33
  38. data/stdlib/builtin/complex.rbs +90 -90
  39. data/stdlib/builtin/encoding.rbs +33 -33
  40. data/stdlib/builtin/enumerable.rbs +32 -32
  41. data/stdlib/builtin/enumerator.rbs +35 -35
  42. data/stdlib/builtin/errors.rbs +1 -1
  43. data/stdlib/builtin/exception.rbs +50 -50
  44. data/stdlib/builtin/false_class.rbs +6 -6
  45. data/stdlib/builtin/fiber.rbs +14 -14
  46. data/stdlib/builtin/fiber_error.rbs +1 -1
  47. data/stdlib/builtin/float.rbs +161 -161
  48. data/stdlib/builtin/gc.rbs +1 -1
  49. data/stdlib/builtin/io.rbs +83 -83
  50. data/stdlib/builtin/kernel.rbs +69 -69
  51. data/stdlib/builtin/match_data.rbs +1 -1
  52. data/stdlib/builtin/method.rbs +19 -19
  53. data/stdlib/builtin/nil_class.rbs +20 -20
  54. data/stdlib/builtin/numeric.rbs +101 -101
  55. data/stdlib/builtin/object.rbs +172 -172
  56. data/stdlib/builtin/proc.rbs +91 -91
  57. data/stdlib/builtin/range.rbs +2 -4
  58. data/stdlib/builtin/rational.rbs +83 -83
  59. data/stdlib/builtin/signal.rbs +7 -7
  60. data/stdlib/builtin/string.rbs +4 -4
  61. data/stdlib/builtin/string_io.rbs +1 -1
  62. data/stdlib/builtin/thread.rbs +185 -185
  63. data/stdlib/builtin/thread_group.rbs +2 -2
  64. data/stdlib/builtin/true_class.rbs +9 -9
  65. data/stdlib/builtin/warning.rbs +1 -1
  66. data/stdlib/date/date.rbs +2 -2
  67. data/stdlib/find/find.rbs +10 -10
  68. data/stdlib/pathname/pathname.rbs +1 -1
  69. data/stdlib/tmpdir/tmpdir.rbs +12 -12
  70. metadata +3 -2
@@ -4,10 +4,10 @@
4
4
  # in this context are all retained. Binding objects can be created using
5
5
  # Kernel#binding, and are made available to the callback of
6
6
  # Kernel#set_trace_func and instances of TracePoint.
7
- #
7
+ #
8
8
  # These binding objects can be passed as the second argument of the Kernel#eval
9
9
  # method, establishing an environment for the evaluation.
10
- #
10
+ #
11
11
  # class Demo
12
12
  # def initialize(n)
13
13
  # @secret = n
@@ -16,39 +16,39 @@
16
16
  # binding
17
17
  # end
18
18
  # end
19
- #
19
+ #
20
20
  # k1 = Demo.new(99)
21
21
  # b1 = k1.get_binding
22
22
  # k2 = Demo.new(-3)
23
23
  # b2 = k2.get_binding
24
- #
24
+ #
25
25
  # eval("@secret", b1) #=> 99
26
26
  # eval("@secret", b2) #=> -3
27
27
  # eval("@secret") #=> nil
28
- #
28
+ #
29
29
  # Binding objects have no class-specific methods.
30
- #
30
+ #
31
31
  class Binding
32
32
  public
33
33
 
34
34
  # Evaluates the Ruby expression(s) in *string*, in the *binding*'s context. If
35
35
  # the optional *filename* and *lineno* parameters are present, they will be used
36
36
  # when reporting syntax errors.
37
- #
37
+ #
38
38
  # def get_binding(param)
39
39
  # binding
40
40
  # end
41
41
  # b = get_binding("hello")
42
42
  # b.eval("param") #=> "hello"
43
- #
43
+ #
44
44
  def eval: (String arg0, ?String filename, ?Integer lineno) -> untyped
45
45
 
46
46
  # Opens an IRB session where `binding.irb` is called which allows for
47
47
  # interactive debugging. You can call any methods or variables available in the
48
48
  # current scope, and mutate state if you need to.
49
- #
49
+ #
50
50
  # Given a Ruby file called `potato.rb` containing the following code:
51
- #
51
+ #
52
52
  # class Potato
53
53
  # def initialize
54
54
  # @cooked = false
@@ -56,16 +56,16 @@ class Binding
56
56
  # puts "Cooked potato: #{@cooked}"
57
57
  # end
58
58
  # end
59
- #
59
+ #
60
60
  # Potato.new
61
- #
61
+ #
62
62
  # Running `ruby potato.rb` will open an IRB session where `binding.irb` is
63
63
  # called, and you will see the following:
64
- #
64
+ #
65
65
  # $ ruby potato.rb
66
- #
66
+ #
67
67
  # From: potato.rb @ line 4 :
68
- #
68
+ #
69
69
  # 1: class Potato
70
70
  # 2: def initialize
71
71
  # 3: @cooked = false
@@ -75,12 +75,12 @@ class Binding
75
75
  # 7: end
76
76
  # 8:
77
77
  # 9: Potato.new
78
- #
78
+ #
79
79
  # irb(#<Potato:0x00007feea1916670>):001:0>
80
- #
80
+ #
81
81
  # You can type any valid Ruby code and it will be evaluated in the current
82
82
  # context. This allows you to debug without having to run your code repeatedly:
83
- #
83
+ #
84
84
  # irb(#<Potato:0x00007feea1916670>):001:0> @cooked
85
85
  # => false
86
86
  # irb(#<Potato:0x00007feea1916670>):002:0> self.class
@@ -89,89 +89,89 @@ class Binding
89
89
  # => ".../2.5.1/lib/ruby/2.5.0/irb/workspace.rb:85:in `eval'"
90
90
  # irb(#<Potato:0x00007feea1916670>):004:0> @cooked = true
91
91
  # => true
92
- #
92
+ #
93
93
  # You can exit the IRB session with the `exit` command. Note that exiting will
94
94
  # resume execution where `binding.irb` had paused it, as you can see from the
95
95
  # output printed to standard output in this example:
96
- #
96
+ #
97
97
  # irb(#<Potato:0x00007feea1916670>):005:0> exit
98
98
  # Cooked potato: true
99
- #
99
+ #
100
100
  # See IRB@IRB+Usage for more information.
101
- #
101
+ #
102
102
  def irb: () -> void
103
103
 
104
104
  # Returns `true` if a local variable `symbol` exists.
105
- #
105
+ #
106
106
  # def foo
107
107
  # a = 1
108
108
  # binding.local_variable_defined?(:a) #=> true
109
109
  # binding.local_variable_defined?(:b) #=> false
110
110
  # end
111
- #
111
+ #
112
112
  # This method is the short version of the following code:
113
- #
113
+ #
114
114
  # binding.eval("defined?(#{symbol}) == 'local-variable'")
115
- #
115
+ #
116
116
  def local_variable_defined?: (String | Symbol symbol) -> bool
117
117
 
118
118
  # Returns the value of the local variable `symbol`.
119
- #
119
+ #
120
120
  # def foo
121
121
  # a = 1
122
122
  # binding.local_variable_get(:a) #=> 1
123
123
  # binding.local_variable_get(:b) #=> NameError
124
124
  # end
125
- #
125
+ #
126
126
  # This method is the short version of the following code:
127
- #
127
+ #
128
128
  # binding.eval("#{symbol}")
129
- #
129
+ #
130
130
  def local_variable_get: (String | Symbol symbol) -> untyped
131
131
 
132
132
  # Set local variable named `symbol` as `obj`.
133
- #
133
+ #
134
134
  # def foo
135
135
  # a = 1
136
136
  # bind = binding
137
137
  # bind.local_variable_set(:a, 2) # set existing local variable `a'
138
138
  # bind.local_variable_set(:b, 3) # create new local variable `b'
139
139
  # # `b' exists only in binding
140
- #
140
+ #
141
141
  # p bind.local_variable_get(:a) #=> 2
142
142
  # p bind.local_variable_get(:b) #=> 3
143
143
  # p a #=> 2
144
144
  # p b #=> NameError
145
145
  # end
146
- #
146
+ #
147
147
  # This method behaves similarly to the following code:
148
- #
148
+ #
149
149
  # binding.eval("#{symbol} = #{obj}")
150
- #
150
+ #
151
151
  # if `obj` can be dumped in Ruby code.
152
- #
152
+ #
153
153
  def local_variable_set: [U] (String | Symbol symbol, U obj) -> U
154
154
 
155
155
  # Returns the names of the binding's local variables as symbols.
156
- #
156
+ #
157
157
  # def foo
158
158
  # a = 1
159
159
  # 2.times do |n|
160
160
  # binding.local_variables #=> [:a, :n]
161
161
  # end
162
162
  # end
163
- #
163
+ #
164
164
  # This method is the short version of the following code:
165
- #
165
+ #
166
166
  # binding.eval("local_variables")
167
- #
167
+ #
168
168
  def local_variables: () -> Array[Symbol]
169
169
 
170
170
  # Returns the bound receiver of the binding object.
171
- #
171
+ #
172
172
  def receiver: () -> untyped
173
173
 
174
174
  # Returns the Ruby source filename and line number of the binding object.
175
- #
175
+ #
176
176
  def source_location: () -> [ String, Integer ]
177
177
  end
@@ -1,18 +1,18 @@
1
1
  # Extends any Class to include *json_creatable?* method.
2
2
  # Classes in Ruby are first-class objects---each is an instance of class Class.
3
- #
3
+ #
4
4
  # Typically, you create a new class by using:
5
- #
5
+ #
6
6
  # class Name
7
7
  # # some code describing the class behavior
8
8
  # end
9
- #
9
+ #
10
10
  # When a new class is created, an object of type Class is initialized and
11
11
  # assigned to a global constant (Name in this case).
12
- #
12
+ #
13
13
  # When `Name.new` is called to create a new object, the #new method in Class is
14
14
  # run by default. This can be demonstrated by overriding #new in Class:
15
- #
15
+ #
16
16
  # class Class
17
17
  # alias old_new new
18
18
  # def new(*args)
@@ -20,16 +20,16 @@
20
20
  # old_new(*args)
21
21
  # end
22
22
  # end
23
- #
23
+ #
24
24
  # class Name
25
25
  # end
26
- #
26
+ #
27
27
  # n = Name.new
28
- #
28
+ #
29
29
  # *produces:*
30
- #
30
+ #
31
31
  # Creating a new Name
32
- #
32
+ #
33
33
  # Classes, modules, and objects are interrelated. In the diagram that follows,
34
34
  # the vertical arrows represent inheritance, and the parentheses metaclasses.
35
35
  # All metaclasses are instances of the class `Class'.
@@ -51,15 +51,15 @@
51
51
  # | +---+ | +----+
52
52
  # | |
53
53
  # obj--->OtherClass---------->(OtherClass)-----------...
54
- #
54
+ #
55
55
  class Class < Module
56
56
  # Creates a new anonymous (unnamed) class with the given superclass (or Object
57
57
  # if no parameter is given). You can give a class a name by assigning the class
58
58
  # object to a constant.
59
- #
59
+ #
60
60
  # If a block is given, it is passed the class object, and the block is evaluated
61
61
  # in the context of this class like #class_eval.
62
- #
62
+ #
63
63
  # fred = Class.new do
64
64
  # def meth1
65
65
  # "hello"
@@ -68,78 +68,78 @@ class Class < Module
68
68
  # "bye"
69
69
  # end
70
70
  # end
71
- #
71
+ #
72
72
  # a = fred.new #=> #<#<Class:0x100381890>:0x100376b98>
73
73
  # a.meth1 #=> "hello"
74
74
  # a.meth2 #=> "bye"
75
- #
75
+ #
76
76
  # Assign the class to a constant (name starting uppercase) if you want to treat
77
77
  # it like a regular class.
78
- #
78
+ #
79
79
  def initialize: (?Class superclass) ?{ (Class newclass) -> void } -> void
80
80
 
81
81
  # Allocates space for a new object of *class*'s class and does not call
82
82
  # initialize on the new instance. The returned object must be an instance of
83
83
  # *class*.
84
- #
84
+ #
85
85
  # klass = Class.new do
86
86
  # def initialize(*args)
87
87
  # @initialized = true
88
88
  # end
89
- #
89
+ #
90
90
  # def initialized?
91
91
  # @initialized || false
92
92
  # end
93
93
  # end
94
- #
94
+ #
95
95
  # klass.allocate.initialized? #=> false
96
- #
96
+ #
97
97
  def allocate: () -> untyped
98
98
 
99
99
  # Callback invoked whenever a subclass of the current class is created.
100
- #
100
+ #
101
101
  # Example:
102
- #
102
+ #
103
103
  # class Foo
104
104
  # def self.inherited(subclass)
105
105
  # puts "New subclass: #{subclass}"
106
106
  # end
107
107
  # end
108
- #
108
+ #
109
109
  # class Bar < Foo
110
110
  # end
111
- #
111
+ #
112
112
  # class Baz < Bar
113
113
  # end
114
- #
114
+ #
115
115
  # *produces:*
116
- #
116
+ #
117
117
  # New subclass: Bar
118
118
  # New subclass: Baz
119
- #
119
+ #
120
120
  def inherited: (Class arg0) -> untyped
121
121
 
122
122
  # Calls #allocate to create a new object of *class*'s class, then invokes that
123
123
  # object's #initialize method, passing it *args*. This is the method that ends
124
124
  # up getting called whenever an object is constructed using `.new`.
125
- #
125
+ #
126
126
  def new: () -> untyped
127
127
 
128
128
  # Returns the superclass of *class*, or `nil`.
129
- #
129
+ #
130
130
  # File.superclass #=> IO
131
131
  # IO.superclass #=> Object
132
132
  # Object.superclass #=> BasicObject
133
133
  # class Foo; end
134
134
  # class Bar < Foo; end
135
135
  # Bar.superclass #=> Foo
136
- #
136
+ #
137
137
  # Returns nil when the given class does not have a parent class:
138
- #
138
+ #
139
139
  # BasicObject.superclass #=> nil
140
- #
140
+ #
141
141
  # # arglists
142
142
  # class.superclass -> a_super_class or nil
143
- #
143
+ #
144
144
  def `superclass`: () -> Class?
145
145
  end
@@ -1,110 +1,110 @@
1
1
  # A complex number can be represented as a paired real number with imaginary
2
2
  # unit; a+bi. Where a is real part, b is imaginary part and i is imaginary
3
3
  # unit. Real a equals complex a+0i mathematically.
4
- #
4
+ #
5
5
  # Complex object can be created as literal, and also by using Kernel#Complex,
6
6
  # Complex::rect, Complex::polar or to_c method.
7
- #
7
+ #
8
8
  # 2+1i #=> (2+1i)
9
9
  # Complex(1) #=> (1+0i)
10
10
  # Complex(2, 3) #=> (2+3i)
11
11
  # Complex.polar(2, 3) #=> (-1.9799849932008908+0.2822400161197344i)
12
12
  # 3.to_c #=> (3+0i)
13
- #
13
+ #
14
14
  # You can also create complex object from floating-point numbers or strings.
15
- #
15
+ #
16
16
  # Complex(0.3) #=> (0.3+0i)
17
17
  # Complex('0.3-0.5i') #=> (0.3-0.5i)
18
18
  # Complex('2/3+3/4i') #=> ((2/3)+(3/4)*i)
19
19
  # Complex('1@2') #=> (-0.4161468365471424+0.9092974268256817i)
20
- #
20
+ #
21
21
  # 0.3.to_c #=> (0.3+0i)
22
22
  # '0.3-0.5i'.to_c #=> (0.3-0.5i)
23
23
  # '2/3+3/4i'.to_c #=> ((2/3)+(3/4)*i)
24
24
  # '1@2'.to_c #=> (-0.4161468365471424+0.9092974268256817i)
25
- #
25
+ #
26
26
  # A complex object is either an exact or an inexact number.
27
- #
27
+ #
28
28
  # Complex(1, 1) / 2 #=> ((1/2)+(1/2)*i)
29
29
  # Complex(1, 1) / 2.0 #=> (0.5+0.5i)
30
- #
30
+ #
31
31
  class Complex < Numeric
32
32
  # Returns a complex object which denotes the given polar form.
33
- #
33
+ #
34
34
  # Complex.polar(3, 0) #=> (3.0+0.0i)
35
35
  # Complex.polar(3, Math::PI/2) #=> (1.836909530733566e-16+3.0i)
36
36
  # Complex.polar(3, Math::PI) #=> (-3.0+3.673819061467132e-16i)
37
37
  # Complex.polar(3, -Math::PI/2) #=> (1.836909530733566e-16-3.0i)
38
- #
38
+ #
39
39
  def self.polar: (Numeric, ?Numeric) -> Complex
40
40
 
41
41
  # Returns a complex object which denotes the given rectangular form.
42
- #
42
+ #
43
43
  # Complex.rectangular(1, 2) #=> (1+2i)
44
- #
44
+ #
45
45
  def self.rect: (Numeric, ?Numeric) -> Complex
46
46
 
47
47
  # Returns a complex object which denotes the given rectangular form.
48
- #
48
+ #
49
49
  # Complex.rectangular(1, 2) #=> (1+2i)
50
- #
50
+ #
51
51
  alias self.rectangular self.rect
52
52
 
53
53
  public
54
54
 
55
55
  # Performs multiplication.
56
- #
56
+ #
57
57
  # Complex(2, 3) * Complex(2, 3) #=> (-5+12i)
58
58
  # Complex(900) * Complex(1) #=> (900+0i)
59
59
  # Complex(-2, 9) * Complex(-9, 2) #=> (0-85i)
60
60
  # Complex(9, 8) * 4 #=> (36+32i)
61
61
  # Complex(20, 9) * 9.8 #=> (196.0+88.2i)
62
- #
62
+ #
63
63
  def *: (Numeric) -> Complex
64
64
 
65
65
  # Performs exponentiation.
66
- #
66
+ #
67
67
  # Complex('i') ** 2 #=> (-1+0i)
68
68
  # Complex(-8) ** Rational(1, 3) #=> (1.0000000000000002+1.7320508075688772i)
69
- #
69
+ #
70
70
  def **: (Numeric) -> Complex
71
71
 
72
72
  # Performs addition.
73
- #
73
+ #
74
74
  # Complex(2, 3) + Complex(2, 3) #=> (4+6i)
75
75
  # Complex(900) + Complex(1) #=> (901+0i)
76
76
  # Complex(-2, 9) + Complex(-9, 2) #=> (-11+11i)
77
77
  # Complex(9, 8) + 4 #=> (13+8i)
78
78
  # Complex(20, 9) + 9.8 #=> (29.8+9i)
79
- #
79
+ #
80
80
  def +: (Numeric) -> Complex
81
81
 
82
82
  def +@: () -> Complex
83
83
 
84
84
  # Performs subtraction.
85
- #
85
+ #
86
86
  # Complex(2, 3) - Complex(2, 3) #=> (0+0i)
87
87
  # Complex(900) - Complex(1) #=> (899+0i)
88
88
  # Complex(-2, 9) - Complex(-9, 2) #=> (7+7i)
89
89
  # Complex(9, 8) - 4 #=> (5+8i)
90
90
  # Complex(20, 9) - 9.8 #=> (10.2+9i)
91
- #
91
+ #
92
92
  def -: (Numeric) -> Complex
93
93
 
94
94
  # Returns negation of the value.
95
- #
95
+ #
96
96
  # -Complex(1, 2) #=> (-1-2i)
97
- #
97
+ #
98
98
  def -@: () -> Complex
99
99
 
100
100
  # Performs division.
101
- #
101
+ #
102
102
  # Complex(2, 3) / Complex(2, 3) #=> ((1/1)+(0/1)*i)
103
103
  # Complex(900) / Complex(1) #=> ((900/1)+(0/1)*i)
104
104
  # Complex(-2, 9) / Complex(-9, 2) #=> ((36/85)-(77/85)*i)
105
105
  # Complex(9, 8) / 4 #=> ((9/4)+(2/1)*i)
106
106
  # Complex(20, 9) / 9.8 #=> (2.0408163265306123+0.9183673469387754i)
107
- #
107
+ #
108
108
  def /: (Numeric) -> Complex
109
109
 
110
110
  def <: (Numeric) -> bot
@@ -114,23 +114,23 @@ class Complex < Numeric
114
114
  # If `cmp`'s imaginary part is zero, and `object` is also a real number (or a
115
115
  # Complex number where the imaginary part is zero), compare the real part of
116
116
  # `cmp` to object. Otherwise, return nil.
117
- #
117
+ #
118
118
  # Complex(2, 3) <=> Complex(2, 3) #=> nil
119
119
  # Complex(2, 3) <=> 1 #=> nil
120
120
  # Complex(2) <=> 1 #=> 1
121
121
  # Complex(2) <=> 2 #=> 0
122
122
  # Complex(2) <=> 3 #=> -1
123
- #
123
+ #
124
124
  def <=>: (Numeric) -> Integer?
125
125
 
126
126
  # Returns true if cmp equals object numerically.
127
- #
127
+ #
128
128
  # Complex(2, 3) == Complex(2, 3) #=> true
129
129
  # Complex(5) == 5 #=> true
130
130
  # Complex(0) == 0.0 #=> true
131
131
  # Complex('1/3') == 0.33 #=> false
132
132
  # Complex('1/2') == '1/2' #=> false
133
- #
133
+ #
134
134
  def ==: (untyped) -> bool
135
135
 
136
136
  def >: (Numeric) -> bot
@@ -138,29 +138,29 @@ class Complex < Numeric
138
138
  def >=: (Numeric) -> bot
139
139
 
140
140
  # Returns the absolute part of its polar form.
141
- #
141
+ #
142
142
  # Complex(-1).abs #=> 1
143
143
  # Complex(3.0, -4.0).abs #=> 5.0
144
- #
144
+ #
145
145
  def abs: () -> Numeric
146
146
 
147
147
  # Returns square of the absolute value.
148
- #
148
+ #
149
149
  # Complex(-1).abs2 #=> 1
150
150
  # Complex(3.0, -4.0).abs2 #=> 25.0
151
- #
151
+ #
152
152
  def abs2: () -> Numeric
153
153
 
154
154
  # Returns the angle part of its polar form.
155
- #
155
+ #
156
156
  # Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966
157
- #
157
+ #
158
158
  def angle: () -> Float
159
159
 
160
160
  # Returns the angle part of its polar form.
161
- #
161
+ #
162
162
  # Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966
163
- #
163
+ #
164
164
  alias arg angle
165
165
 
166
166
  def ceil: (*untyped) -> bot
@@ -170,21 +170,21 @@ class Complex < Numeric
170
170
  def coerce: (Numeric) -> [ Complex, Complex ]
171
171
 
172
172
  # Returns the complex conjugate.
173
- #
173
+ #
174
174
  # Complex(1, 2).conjugate #=> (1-2i)
175
- #
175
+ #
176
176
  def conj: () -> Complex
177
177
 
178
178
  # Returns the complex conjugate.
179
- #
179
+ #
180
180
  # Complex(1, 2).conjugate #=> (1-2i)
181
- #
181
+ #
182
182
  def conjugate: () -> Complex
183
183
 
184
184
  # Returns the denominator (lcm of both denominator - real and imag).
185
- #
185
+ #
186
186
  # See numerator.
187
- #
187
+ #
188
188
  def denominator: () -> Integer
189
189
 
190
190
  def div: (Numeric) -> bot
@@ -196,14 +196,14 @@ class Complex < Numeric
196
196
  def eql?: (untyped) -> bool
197
197
 
198
198
  # Performs division as each part is a float, never returns a float.
199
- #
199
+ #
200
200
  # Complex(11, 22).fdiv(3) #=> (3.6666666666666665+7.333333333333333i)
201
- #
201
+ #
202
202
  def fdiv: (Numeric) -> Complex
203
203
 
204
204
  # Returns `true` if `cmp`'s real and imaginary parts are both finite numbers,
205
205
  # otherwise returns `false`.
206
- #
206
+ #
207
207
  def finite?: () -> bool
208
208
 
209
209
  def floor: (?Integer) -> bot
@@ -213,46 +213,46 @@ class Complex < Numeric
213
213
  def i: () -> bot
214
214
 
215
215
  # Returns the imaginary part.
216
- #
216
+ #
217
217
  # Complex(7).imaginary #=> 0
218
218
  # Complex(9, -4).imaginary #=> -4
219
- #
219
+ #
220
220
  def imag: () -> Numeric
221
221
 
222
222
  # Returns the imaginary part.
223
- #
223
+ #
224
224
  # Complex(7).imaginary #=> 0
225
225
  # Complex(9, -4).imaginary #=> -4
226
- #
226
+ #
227
227
  def imaginary: () -> Numeric
228
228
 
229
229
  # Returns `1` if `cmp`'s real or imaginary part is an infinite number, otherwise
230
230
  # returns `nil`.
231
- #
231
+ #
232
232
  # For example:
233
- #
233
+ #
234
234
  # (1+1i).infinite? #=> nil
235
235
  # (Float::INFINITY + 1i).infinite? #=> 1
236
- #
236
+ #
237
237
  def infinite?: () -> Integer?
238
238
 
239
239
  # Returns the value as a string for inspection.
240
- #
240
+ #
241
241
  # Complex(2).inspect #=> "(2+0i)"
242
242
  # Complex('-8/6').inspect #=> "((-4/3)+0i)"
243
243
  # Complex('1/2i').inspect #=> "(0+(1/2)*i)"
244
244
  # Complex(0, Float::INFINITY).inspect #=> "(0+Infinity*i)"
245
245
  # Complex(Float::NAN, Float::NAN).inspect #=> "(NaN+NaN*i)"
246
- #
246
+ #
247
247
  def inspect: () -> String
248
248
 
249
249
  def integer?: () -> bool
250
250
 
251
251
  # Returns the absolute part of its polar form.
252
- #
252
+ #
253
253
  # Complex(-1).abs #=> 1
254
254
  # Complex(3.0, -4.0).abs #=> 5.0
255
- #
255
+ #
256
256
  alias magnitude abs
257
257
 
258
258
  def modulo: (Numeric) -> bot
@@ -262,78 +262,78 @@ class Complex < Numeric
262
262
  def nonzero?: () -> self?
263
263
 
264
264
  # Returns the numerator.
265
- #
265
+ #
266
266
  # 1 2 3+4i <- numerator
267
267
  # - + -i -> ----
268
268
  # 2 3 6 <- denominator
269
- #
269
+ #
270
270
  # c = Complex('1/2+2/3i') #=> ((1/2)+(2/3)*i)
271
271
  # n = c.numerator #=> (3+4i)
272
272
  # d = c.denominator #=> 6
273
273
  # n / d #=> ((1/2)+(2/3)*i)
274
274
  # Complex(Rational(n.real, d), Rational(n.imag, d))
275
275
  # #=> ((1/2)+(2/3)*i)
276
- #
276
+ #
277
277
  # See denominator.
278
- #
278
+ #
279
279
  def numerator: () -> Complex
280
280
 
281
281
  # Returns the angle part of its polar form.
282
- #
282
+ #
283
283
  # Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966
284
- #
284
+ #
285
285
  alias phase angle
286
286
 
287
287
  # Returns an array; [cmp.abs, cmp.arg].
288
- #
288
+ #
289
289
  # Complex(1, 2).polar #=> [2.23606797749979, 1.1071487177940904]
290
- #
290
+ #
291
291
  def polar: () -> [Numeric, Float]
292
292
 
293
293
  def positive?: () -> bot
294
294
 
295
295
  # Performs division.
296
- #
296
+ #
297
297
  # Complex(2, 3) / Complex(2, 3) #=> ((1/1)+(0/1)*i)
298
298
  # Complex(900) / Complex(1) #=> ((900/1)+(0/1)*i)
299
299
  # Complex(-2, 9) / Complex(-9, 2) #=> ((36/85)-(77/85)*i)
300
300
  # Complex(9, 8) / 4 #=> ((9/4)+(2/1)*i)
301
301
  # Complex(20, 9) / 9.8 #=> (2.0408163265306123+0.9183673469387754i)
302
- #
302
+ #
303
303
  def quo: (Numeric) -> Complex
304
304
 
305
305
  # Returns the value as a rational if possible (the imaginary part should be
306
306
  # exactly zero).
307
- #
307
+ #
308
308
  # Complex(1.0/3, 0).rationalize #=> (1/3)
309
309
  # Complex(1, 0.0).rationalize # RangeError
310
310
  # Complex(1, 2).rationalize # RangeError
311
- #
311
+ #
312
312
  # See to_r.
313
- #
313
+ #
314
314
  def rationalize: (?Numeric eps) -> Rational
315
315
 
316
316
  # Returns the real part.
317
- #
317
+ #
318
318
  # Complex(7).real #=> 7
319
319
  # Complex(9, -4).real #=> 9
320
- #
320
+ #
321
321
  def real: () -> Numeric
322
322
 
323
323
  # Returns false, even if the complex number has no imaginary part.
324
- #
324
+ #
325
325
  def real?: () -> false
326
326
 
327
327
  # Returns an array; [cmp.real, cmp.imag].
328
- #
328
+ #
329
329
  # Complex(1, 2).rectangular #=> [1, 2]
330
- #
330
+ #
331
331
  def rect: () -> [Numeric, Numeric]
332
332
 
333
333
  # Returns an array; [cmp.real, cmp.imag].
334
- #
334
+ #
335
335
  # Complex(1, 2).rectangular #=> [1, 2]
336
- #
336
+ #
337
337
  alias rectangular rect
338
338
 
339
339
  def reminder: (Numeric) -> bot
@@ -343,51 +343,51 @@ class Complex < Numeric
343
343
  def step: (*untyped) ?{ (*untyped) -> untyped } -> bot
344
344
 
345
345
  # Returns self.
346
- #
346
+ #
347
347
  # Complex(2).to_c #=> (2+0i)
348
348
  # Complex(-8, 6).to_c #=> (-8+6i)
349
- #
349
+ #
350
350
  def to_c: () -> Complex
351
351
 
352
352
  # Returns the value as a float if possible (the imaginary part should be exactly
353
353
  # zero).
354
- #
354
+ #
355
355
  # Complex(1, 0).to_f #=> 1.0
356
356
  # Complex(1, 0.0).to_f # RangeError
357
357
  # Complex(1, 2).to_f # RangeError
358
- #
358
+ #
359
359
  def to_f: () -> Float
360
360
 
361
361
  # Returns the value as an integer if possible (the imaginary part should be
362
362
  # exactly zero).
363
- #
363
+ #
364
364
  # Complex(1, 0).to_i #=> 1
365
365
  # Complex(1, 0.0).to_i # RangeError
366
366
  # Complex(1, 2).to_i # RangeError
367
- #
367
+ #
368
368
  def to_i: () -> Integer
369
369
 
370
370
  alias to_int to_i
371
371
 
372
372
  # Returns the value as a rational if possible (the imaginary part should be
373
373
  # exactly zero).
374
- #
374
+ #
375
375
  # Complex(1, 0).to_r #=> (1/1)
376
376
  # Complex(1, 0.0).to_r # RangeError
377
377
  # Complex(1, 2).to_r # RangeError
378
- #
378
+ #
379
379
  # See rationalize.
380
- #
380
+ #
381
381
  def to_r: () -> Rational
382
382
 
383
383
  # Returns the value as a string.
384
- #
384
+ #
385
385
  # Complex(2).to_s #=> "2+0i"
386
386
  # Complex('-8/6').to_s #=> "-4/3+0i"
387
387
  # Complex('1/2i').to_s #=> "0+1/2i"
388
388
  # Complex(0, Float::INFINITY).to_s #=> "0+Infinity*i"
389
389
  # Complex(Float::NAN, Float::NAN).to_s #=> "NaN+NaN*i"
390
- #
390
+ #
391
391
  def to_s: () -> String
392
392
 
393
393
  def truncate: (?Integer) -> bot
@@ -396,5 +396,5 @@ class Complex < Numeric
396
396
  end
397
397
 
398
398
  # The imaginary unit.
399
- #
399
+ #
400
400
  Complex::I: Complex