steep 0.13.0 → 0.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +28 -0
- data/Rakefile +0 -13
- data/bin/setup +0 -2
- data/bin/smoke_runner.rb +0 -1
- data/exe/steep +0 -1
- data/lib/steep.rb +33 -1
- data/lib/steep/annotation_parser.rb +4 -4
- data/lib/steep/ast/buffer.rb +11 -7
- data/lib/steep/ast/builtin.rb +8 -0
- data/lib/steep/ast/types/factory.rb +124 -89
- data/lib/steep/cli.rb +16 -1
- data/lib/steep/drivers/annotations.rb +1 -1
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/init.rb +5 -5
- data/lib/steep/drivers/langserver.rb +13 -287
- data/lib/steep/drivers/utils/driver_helper.rb +1 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/drivers/watch.rb +97 -85
- data/lib/steep/drivers/worker.rb +51 -0
- data/lib/steep/project.rb +9 -5
- data/lib/steep/project/completion_provider.rb +298 -0
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +54 -47
- data/lib/steep/project/hover_content.rb +17 -8
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +40 -24
- data/lib/steep/server/base_worker.rb +56 -0
- data/lib/steep/server/code_worker.rb +151 -0
- data/lib/steep/server/interaction_worker.rb +281 -0
- data/lib/steep/server/master.rb +196 -0
- data/lib/steep/server/signature_worker.rb +148 -0
- data/lib/steep/server/utils.rb +36 -0
- data/lib/steep/server/worker_process.rb +62 -0
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +13 -13
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +1004 -727
- data/lib/steep/type_inference/constant_env.rb +3 -11
- data/lib/steep/type_inference/context.rb +8 -3
- data/lib/steep/type_inference/context_array.rb +111 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
- data/lib/steep/type_inference/logic.rb +130 -0
- data/lib/steep/type_inference/type_env.rb +5 -69
- data/lib/steep/typing.rb +91 -23
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/alias/a.rb +1 -1
- data/smoke/and/Steepfile +1 -0
- data/smoke/array/Steepfile +1 -0
- data/smoke/array/b.rb +0 -2
- data/smoke/block/Steepfile +1 -0
- data/smoke/case/Steepfile +1 -0
- data/smoke/class/Steepfile +1 -0
- data/smoke/const/Steepfile +1 -0
- data/smoke/dstr/Steepfile +1 -0
- data/smoke/ensure/Steepfile +1 -0
- data/smoke/enumerator/Steepfile +1 -0
- data/smoke/extension/Steepfile +1 -0
- data/smoke/extension/c.rb +1 -0
- data/smoke/hash/Steepfile +1 -0
- data/smoke/hello/Steepfile +1 -0
- data/smoke/if/Steepfile +1 -0
- data/smoke/if/a.rb +1 -1
- data/smoke/implements/Steepfile +1 -0
- data/smoke/initialize/Steepfile +1 -0
- data/smoke/integer/Steepfile +1 -0
- data/smoke/interface/Steepfile +1 -0
- data/smoke/kwbegin/Steepfile +1 -0
- data/smoke/lambda/Steepfile +1 -0
- data/smoke/literal/Steepfile +1 -0
- data/smoke/map/Steepfile +1 -0
- data/smoke/method/Steepfile +1 -0
- data/smoke/module/Steepfile +1 -0
- data/smoke/regexp/Steepfile +1 -0
- data/smoke/regexp/b.rb +4 -4
- data/smoke/regression/Steepfile +1 -0
- data/smoke/rescue/Steepfile +1 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +1 -0
- data/smoke/skip/Steepfile +1 -0
- data/smoke/stdout/Steepfile +1 -0
- data/smoke/super/Steepfile +1 -0
- data/smoke/type_case/Steepfile +1 -0
- data/smoke/yield/Steepfile +1 -0
- data/steep.gemspec +8 -8
- metadata +38 -138
- data/exe/rbs +0 -3
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
- data/vendor/ruby-signature/.gitignore +0 -12
- data/vendor/ruby-signature/.rubocop.yml +0 -15
- data/vendor/ruby-signature/BSDL +0 -22
- data/vendor/ruby-signature/COPYING +0 -56
- data/vendor/ruby-signature/Gemfile +0 -6
- data/vendor/ruby-signature/README.md +0 -93
- data/vendor/ruby-signature/Rakefile +0 -66
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
- data/vendor/ruby-signature/bin/console +0 -14
- data/vendor/ruby-signature/bin/query-rdoc +0 -103
- data/vendor/ruby-signature/bin/setup +0 -10
- data/vendor/ruby-signature/bin/sort +0 -88
- data/vendor/ruby-signature/bin/test_runner.rb +0 -17
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
- data/vendor/ruby-signature/docs/sigs.md +0 -148
- data/vendor/ruby-signature/docs/stdlib.md +0 -152
- data/vendor/ruby-signature/docs/syntax.md +0 -528
- data/vendor/ruby-signature/exe/rbs +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
- data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
- data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,35 +0,0 @@
|
|
1
|
-
interface _ToI
|
2
|
-
def to_i: -> Integer
|
3
|
-
end
|
4
|
-
|
5
|
-
interface _ToInt
|
6
|
-
def to_int: -> Integer
|
7
|
-
end
|
8
|
-
|
9
|
-
interface _ToS
|
10
|
-
def to_s: -> String
|
11
|
-
end
|
12
|
-
|
13
|
-
interface _ToStr
|
14
|
-
def to_str: () -> String
|
15
|
-
end
|
16
|
-
|
17
|
-
interface _ToHash[K, V]
|
18
|
-
def to_hash: () -> Hash[K, V]
|
19
|
-
end
|
20
|
-
|
21
|
-
interface _ToProc
|
22
|
-
def to_proc: () -> untyped
|
23
|
-
end
|
24
|
-
|
25
|
-
interface _Each[out A, out B]
|
26
|
-
def each: { (A) -> void } -> B
|
27
|
-
end
|
28
|
-
|
29
|
-
class BigDecimal
|
30
|
-
end
|
31
|
-
|
32
|
-
type int = Integer | _ToInt
|
33
|
-
type real = Integer | Float | Rational
|
34
|
-
|
35
|
-
type string = String | _ToStr
|
@@ -1,145 +0,0 @@
|
|
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
|
@@ -1,116 +0,0 @@
|
|
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
|
@@ -1,400 +0,0 @@
|
|
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
|