rbs 0.2.0

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