steep 0.15.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +25 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep.rb +12 -1
  9. data/lib/steep/cli.rb +16 -1
  10. data/lib/steep/drivers/annotations.rb +1 -1
  11. data/lib/steep/drivers/check.rb +1 -12
  12. data/lib/steep/drivers/langserver.rb +13 -462
  13. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  14. data/lib/steep/drivers/watch.rb +97 -85
  15. data/lib/steep/drivers/worker.rb +51 -0
  16. data/lib/steep/project.rb +9 -5
  17. data/lib/steep/project/completion_provider.rb +4 -2
  18. data/lib/steep/project/file.rb +2 -1
  19. data/lib/steep/project/hover_content.rb +6 -3
  20. data/lib/steep/project/options.rb +15 -0
  21. data/lib/steep/project/target.rb +30 -20
  22. data/lib/steep/server/base_worker.rb +56 -0
  23. data/lib/steep/server/code_worker.rb +151 -0
  24. data/lib/steep/server/interaction_worker.rb +281 -0
  25. data/lib/steep/server/master.rb +196 -0
  26. data/lib/steep/server/signature_worker.rb +148 -0
  27. data/lib/steep/server/utils.rb +36 -0
  28. data/lib/steep/server/worker_process.rb +62 -0
  29. data/lib/steep/signature/validator.rb +5 -5
  30. data/lib/steep/type_construction.rb +13 -19
  31. data/lib/steep/type_inference/constant_env.rb +2 -10
  32. data/lib/steep/type_inference/context.rb +1 -0
  33. data/lib/steep/version.rb +1 -1
  34. data/steep.gemspec +7 -8
  35. metadata +22 -142
  36. data/exe/rbs +0 -3
  37. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  38. data/vendor/ruby-signature/.gitignore +0 -12
  39. data/vendor/ruby-signature/.rubocop.yml +0 -15
  40. data/vendor/ruby-signature/BSDL +0 -22
  41. data/vendor/ruby-signature/COPYING +0 -56
  42. data/vendor/ruby-signature/Gemfile +0 -6
  43. data/vendor/ruby-signature/README.md +0 -93
  44. data/vendor/ruby-signature/Rakefile +0 -67
  45. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
  46. data/vendor/ruby-signature/bin/console +0 -14
  47. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  48. data/vendor/ruby-signature/bin/setup +0 -10
  49. data/vendor/ruby-signature/bin/sort +0 -89
  50. data/vendor/ruby-signature/bin/test_runner.rb +0 -16
  51. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  52. data/vendor/ruby-signature/docs/sigs.md +0 -148
  53. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  54. data/vendor/ruby-signature/docs/syntax.md +0 -528
  55. data/vendor/ruby-signature/exe/rbs +0 -7
  56. data/vendor/ruby-signature/lib/rbs.rb +0 -64
  57. data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
  58. data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
  59. data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
  60. data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
  61. data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
  62. data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
  63. data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
  64. data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
  65. data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
  66. data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
  67. data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
  68. data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
  69. data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
  70. data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
  71. data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
  72. data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
  73. data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
  74. data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
  75. data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
  76. data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
  77. data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
  78. data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
  79. data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
  80. data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
  81. data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
  82. data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
  83. data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
  84. data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
  85. data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
  86. data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
  87. data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
  88. data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
  89. data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
  90. data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
  91. data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
  92. data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
  93. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
  94. data/vendor/ruby-signature/rbs.gemspec +0 -45
  95. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
  96. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
  97. data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
  98. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  99. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  100. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  101. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -44
  102. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  103. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  104. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  105. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  106. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  107. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  108. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -413
  109. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
  110. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  111. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  112. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  113. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  114. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -194
  115. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  116. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  117. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  118. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -1076
  119. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  120. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  121. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -243
  122. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  123. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
  124. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  125. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
  126. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
  127. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
  128. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
  129. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
  130. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
  131. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  132. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  133. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  134. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -429
  135. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
  136. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
  137. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  138. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  139. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -57
  140. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
  141. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  142. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  143. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1901
  144. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
  145. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  146. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
  147. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
  148. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  149. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
  150. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
  151. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  152. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
  153. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  154. data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
  155. data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
  156. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
  157. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
  158. data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
  159. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
  160. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  161. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  162. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  163. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -301
  164. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,161 +0,0 @@
1
- # The marshaling library converts collections of Ruby objects into a byte
2
- # stream, allowing them to be stored outside the currently active script. This
3
- # data may subsequently be read and the original objects reconstituted.
4
- #
5
- # Marshaled data has major and minor version numbers stored along with the
6
- # object information. In normal use, marshaling can only load data written with
7
- # the same major version number and an equal or lower minor version number. If
8
- # Ruby's ``verbose'' flag is set (normally using -d, -v, -w, or --verbose) the
9
- # major and minor numbers must match exactly. Marshal versioning is independent
10
- # of Ruby's version numbers. You can extract the version by reading the first
11
- # two bytes of marshaled data.
12
- #
13
- # str = Marshal.dump("thing")
14
- # RUBY_VERSION #=> "1.9.0"
15
- # str[0].ord #=> 4
16
- # str[1].ord #=> 8
17
- #
18
- # Some objects cannot be dumped: if the objects to be dumped include bindings,
19
- # procedure or method objects, instances of class IO, or singleton objects, a
20
- # TypeError will be raised.
21
- #
22
- # If your class has special serialization needs (for example, if you want to
23
- # serialize in some specific format), or if it contains objects that would
24
- # otherwise not be serializable, you can implement your own serialization
25
- # strategy.
26
- #
27
- # There are two methods of doing this, your object can define either
28
- # marshal_dump and marshal_load or _dump and _load. marshal_dump will take
29
- # precedence over _dump if both are defined. marshal_dump may result in smaller
30
- # Marshal strings.
31
- #
32
- # ## Security considerations
33
- #
34
- # By design, Marshal.load can deserialize almost any class loaded into the Ruby
35
- # process. In many cases this can lead to remote code execution if the Marshal
36
- # data is loaded from an untrusted source.
37
- #
38
- # As a result, Marshal.load is not suitable as a general purpose serialization
39
- # format and you should never unmarshal user supplied input or other untrusted
40
- # data.
41
- #
42
- # If you need to deserialize untrusted data, use JSON or another serialization
43
- # format that is only able to load simple, 'primitive' types such as String,
44
- # Array, Hash, etc. Never allow user input to specify arbitrary types to
45
- # deserialize into.
46
- #
47
- # ## marshal_dump and marshal_load
48
- #
49
- # When dumping an object the method marshal_dump will be called. marshal_dump
50
- # must return a result containing the information necessary for marshal_load to
51
- # reconstitute the object. The result can be any object.
52
- #
53
- # When loading an object dumped using marshal_dump the object is first allocated
54
- # then marshal_load is called with the result from marshal_dump. marshal_load
55
- # must recreate the object from the information in the result.
56
- #
57
- # Example:
58
- #
59
- # class MyObj
60
- # def initialize name, version, data
61
- # @name = name
62
- # @version = version
63
- # @data = data
64
- # end
65
- #
66
- # def marshal_dump
67
- # [@name, @version]
68
- # end
69
- #
70
- # def marshal_load array
71
- # @name, @version = array
72
- # end
73
- # end
74
- #
75
- # ## _dump and _load
76
- #
77
- # Use _dump and _load when you need to allocate the object you're restoring
78
- # yourself.
79
- #
80
- # When dumping an object the instance method _dump is called with an Integer
81
- # which indicates the maximum depth of objects to dump (a value of -1 implies
82
- # that you should disable depth checking). _dump must return a String
83
- # containing the information necessary to reconstitute the object.
84
- #
85
- # The class method _load should take a String and use it to return an object of
86
- # the same class.
87
- #
88
- # Example:
89
- #
90
- # class MyObj
91
- # def initialize name, version, data
92
- # @name = name
93
- # @version = version
94
- # @data = data
95
- # end
96
- #
97
- # def _dump level
98
- # [@name, @version].join ':'
99
- # end
100
- #
101
- # def self._load args
102
- # new(*args.split(':'))
103
- # end
104
- # end
105
- #
106
- # Since Marshal.dump outputs a string you can have _dump return a Marshal string
107
- # which is Marshal.loaded in _load for complex objects.
108
- #
109
- module Marshal
110
- # Serializes obj and all descendant objects. If anIO is specified, the
111
- # serialized data will be written to it, otherwise the data will be returned as
112
- # a String. If limit is specified, the traversal of subobjects will be limited
113
- # to that depth. If limit is negative, no checking of depth will be performed.
114
- #
115
- # class Klass
116
- # def initialize(str)
117
- # @str = str
118
- # end
119
- # def say_hello
120
- # @str
121
- # end
122
- # end
123
- #
124
- # (produces no output)
125
- #
126
- # o = Klass.new("hello\n")
127
- # data = Marshal.dump(o)
128
- # obj = Marshal.load(data)
129
- # obj.say_hello #=> "hello\n"
130
- #
131
- # Marshal can't dump following objects:
132
- # * anonymous Class/Module.
133
- # * objects which are related to system (ex: Dir, File::Stat, IO, File, Socket
134
- # and so on)
135
- # * an instance of MatchData, Data, Method, UnboundMethod, Proc, Thread,
136
- # ThreadGroup, Continuation
137
- # * objects which define singleton methods
138
- #
139
- def self.dump: (Object arg0, ?IO arg1, ?Integer arg2) -> Object
140
- | (Object arg0, ?Integer arg1) -> Object
141
-
142
- # Returns the result of converting the serialized data in source into a Ruby
143
- # object (possibly with associated subordinate objects). source may be either an
144
- # instance of IO or an object that responds to to_str. If proc is specified,
145
- # each object will be passed to the proc, as the object is being deserialized.
146
- #
147
- # Never pass untrusted data (including user supplied input) to this method.
148
- # Please see the overview for further details.
149
- #
150
- def self.load: (String arg0, ?Proc arg1) -> Object
151
-
152
- alias self.restore self.load
153
- end
154
-
155
- # major version
156
- #
157
- Marshal::MAJOR_VERSION: Integer
158
-
159
- # minor version
160
- #
161
- Marshal::MINOR_VERSION: Integer
@@ -1,271 +0,0 @@
1
- # MatchData encapsulates the result of matching a Regexp against string. It is
2
- # returned by Regexp#match and String#match, and also stored in a global
3
- # variable returned by Regexp.last_match.
4
- #
5
- # Usage:
6
- #
7
- # url = 'https://docs.ruby-lang.org/en/2.5.0/MatchData.html'
8
- # m = url.match(/(\d\.?)+/) # => #<MatchData "2.5.0" 1:"0">
9
- # m.string # => "https://docs.ruby-lang.org/en/2.5.0/MatchData.html"
10
- # m.regexp # => /(\d\.?)+/
11
- # # entire matched substring:
12
- # m[0] # => "2.5.0"
13
- #
14
- # # Working with unnamed captures
15
- # m = url.match(%r{([^/]+)/([^/]+)\.html$})
16
- # m.captures # => ["2.5.0", "MatchData"]
17
- # m[1] # => "2.5.0"
18
- # m.values_at(1, 2) # => ["2.5.0", "MatchData"]
19
- #
20
- # # Working with named captures
21
- # m = url.match(%r{(?<version>[^/]+)/(?<module>[^/]+)\.html$})
22
- # m.captures # => ["2.5.0", "MatchData"]
23
- # m.named_captures # => {"version"=>"2.5.0", "module"=>"MatchData"}
24
- # m[:version] # => "2.5.0"
25
- # m.values_at(:version, :module)
26
- # # => ["2.5.0", "MatchData"]
27
- # # Numerical indexes are working, too
28
- # m[1] # => "2.5.0"
29
- # m.values_at(1, 2) # => ["2.5.0", "MatchData"]
30
- #
31
- # ## Global variables equivalence
32
- #
33
- # Parts of last MatchData (returned by Regexp.last_match) are also aliased as
34
- # global variables:
35
- #
36
- # * `$~` is Regexp.last_match;
37
- # * `$&` is [Regexp.last_match](0);
38
- # * `$1`, `$2`, and so on are [Regexp.last_match](i) (captures by number);
39
- # * `$`` is Regexp.last_match`.pre_match`;
40
- # * `$'` is Regexp.last_match`.post_match`;
41
- # * `$+` is [Regexp.last_match](-1) (the last capture).
42
- #
43
- #
44
- # See also "Special global variables" section in Regexp documentation.
45
- #
46
- class MatchData
47
- public
48
-
49
- # Equality---Two matchdata are equal if their target strings, patterns, and
50
- # matched positions are identical.
51
- #
52
- def ==: (untyped other) -> bool
53
-
54
- # Match Reference -- MatchData acts as an array, and may be accessed using the
55
- # normal array indexing techniques. `mtch[0]` is equivalent to the special
56
- # variable `$&`, and returns the entire matched string. `mtch[1]`, `mtch[2]`,
57
- # and so on return the values of the matched backreferences (portions of the
58
- # pattern between parentheses).
59
- #
60
- # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
61
- # m #=> #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
62
- # m[0] #=> "HX1138"
63
- # m[1, 2] #=> ["H", "X"]
64
- # m[1..3] #=> ["H", "X", "113"]
65
- # m[-3, 2] #=> ["X", "113"]
66
- #
67
- # m = /(?<foo>a+)b/.match("ccaaab")
68
- # m #=> #<MatchData "aaab" foo:"aaa">
69
- # m["foo"] #=> "aaa"
70
- # m[:foo] #=> "aaa"
71
- #
72
- def []: (Integer idx) -> String?
73
- | (Integer start, Integer length) -> ::Array[String?]
74
- | (::Range[Integer] range) -> ::Array[String?]
75
- | (String | Symbol name) -> String?
76
-
77
- # Returns the offset of the start of the *n*th element of the match array in the
78
- # string. *n* can be a string or symbol to reference a named capture.
79
- #
80
- # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
81
- # m.begin(0) #=> 1
82
- # m.begin(2) #=> 2
83
- #
84
- # m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
85
- # p m.begin(:foo) #=> 0
86
- # p m.begin(:bar) #=> 2
87
- #
88
- def begin: (Integer | String | Symbol n_or_name) -> Integer?
89
-
90
- # Returns the array of captures; equivalent to `mtch.to_a[1..-1]`.
91
- #
92
- # f1,f2,f3,f4 = /(.)(.)(\d+)(\d)/.match("THX1138.").captures
93
- # f1 #=> "H"
94
- # f2 #=> "X"
95
- # f3 #=> "113"
96
- # f4 #=> "8"
97
- #
98
- def captures: () -> ::Array[String?]
99
-
100
- # Returns the offset of the character immediately following the end of the *n*th
101
- # element of the match array in the string. *n* can be a string or symbol to
102
- # reference a named capture.
103
- #
104
- # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
105
- # m.end(0) #=> 7
106
- # m.end(2) #=> 3
107
- #
108
- # m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
109
- # p m.end(:foo) #=> 1
110
- # p m.end(:bar) #=> 3
111
- #
112
- def `end`: (Integer | String | Symbol n_or_name) -> Integer?
113
-
114
- # Equality---Two matchdata are equal if their target strings, patterns, and
115
- # matched positions are identical.
116
- #
117
- def eql?: (untyped other) -> bool
118
-
119
- # Produce a hash based on the target string, regexp and matched positions of
120
- # this matchdata.
121
- #
122
- # See also Object#hash.
123
- #
124
- def hash: () -> Integer
125
-
126
- # Returns a printable version of *mtch*.
127
- #
128
- # puts /.$/.match("foo").inspect
129
- # #=> #<MatchData "o">
130
- #
131
- # puts /(.)(.)(.)/.match("foo").inspect
132
- # #=> #<MatchData "foo" 1:"f" 2:"o" 3:"o">
133
- #
134
- # puts /(.)(.)?(.)/.match("fo").inspect
135
- # #=> #<MatchData "fo" 1:"f" 2:nil 3:"o">
136
- #
137
- # puts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").inspect
138
- # #=> #<MatchData "hog" foo:"h" bar:"o" baz:"g">
139
- #
140
- def inspect: () -> String
141
-
142
- # Returns the number of elements in the match array.
143
- #
144
- # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
145
- # m.length #=> 5
146
- # m.size #=> 5
147
- #
148
- def length: () -> Integer
149
-
150
- # Returns a Hash using named capture.
151
- #
152
- # A key of the hash is a name of the named captures. A value of the hash is a
153
- # string of last successful capture of corresponding group.
154
- #
155
- # m = /(?<a>.)(?<b>.)/.match("01")
156
- # m.named_captures #=> {"a" => "0", "b" => "1"}
157
- #
158
- # m = /(?<a>.)(?<b>.)?/.match("0")
159
- # m.named_captures #=> {"a" => "0", "b" => nil}
160
- #
161
- # m = /(?<a>.)(?<a>.)/.match("01")
162
- # m.named_captures #=> {"a" => "1"}
163
- #
164
- # m = /(?<a>x)|(?<a>y)/.match("x")
165
- # m.named_captures #=> {"a" => "x"}
166
- #
167
- def named_captures: () -> ::Hash[String, String?]
168
-
169
- # Returns a list of names of captures as an array of strings. It is same as
170
- # mtch.regexp.names.
171
- #
172
- # /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").names
173
- # #=> ["foo", "bar", "baz"]
174
- #
175
- # m = /(?<x>.)(?<y>.)?/.match("a") #=> #<MatchData "a" x:"a" y:nil>
176
- # m.names #=> ["x", "y"]
177
- #
178
- def names: () -> ::Array[String]
179
-
180
- # Returns a two-element array containing the beginning and ending offsets of the
181
- # *n*th match. *n* can be a string or symbol to reference a named capture.
182
- #
183
- # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
184
- # m.offset(0) #=> [1, 7]
185
- # m.offset(4) #=> [6, 7]
186
- #
187
- # m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
188
- # p m.offset(:foo) #=> [0, 1]
189
- # p m.offset(:bar) #=> [2, 3]
190
- #
191
- def offset: (Integer | Symbol | String n_or_name) -> ([ Integer, Integer ] | [ nil, nil ])
192
-
193
- # Returns the portion of the original string after the current match. Equivalent
194
- # to the special variable `$'`.
195
- #
196
- # m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
197
- # m.post_match #=> ": The Movie"
198
- #
199
- def post_match: () -> String
200
-
201
- # Returns the portion of the original string before the current match.
202
- # Equivalent to the special variable `$``.
203
- #
204
- # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
205
- # m.pre_match #=> "T"
206
- #
207
- def pre_match: () -> String
208
-
209
- # Returns the regexp.
210
- #
211
- # m = /a.*b/.match("abc")
212
- # m.regexp #=> /a.*b/
213
- #
214
- def regexp: () -> Regexp
215
-
216
- # Returns the number of elements in the match array.
217
- #
218
- # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
219
- # m.length #=> 5
220
- # m.size #=> 5
221
- #
222
- def size: () -> Integer
223
-
224
- # Returns a frozen copy of the string passed in to `match`.
225
- #
226
- # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
227
- # m.string #=> "THX1138."
228
- #
229
- def string: () -> String
230
-
231
- # Returns the array of matches.
232
- #
233
- # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
234
- # m.to_a #=> ["HX1138", "H", "X", "113", "8"]
235
- #
236
- # Because `to_a` is called when expanding `*`*variable*, there's a useful
237
- # assignment shortcut for extracting matched fields. This is slightly slower
238
- # than accessing the fields directly (as an intermediate array is generated).
239
- #
240
- # all,f1,f2,f3 = * /(.)(.)(\d+)(\d)/.match("THX1138.")
241
- # all #=> "HX1138"
242
- # f1 #=> "H"
243
- # f2 #=> "X"
244
- # f3 #=> "113"
245
- #
246
- def to_a: () -> ::Array[String?]
247
-
248
- # Returns the entire matched string.
249
- #
250
- # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
251
- # m.to_s #=> "HX1138"
252
- #
253
- def to_s: () -> String
254
-
255
- # Uses each *index* to access the matching values, returning an array of the
256
- # corresponding matches.
257
- #
258
- # m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
259
- # m.to_a #=> ["HX1138", "H", "X", "113", "8"]
260
- # m.values_at(0, 2, -2) #=> ["HX1138", "X", "113"]
261
- #
262
- # m = /(?<a>\d+) *(?<op>[+\-*\/]) *(?<b>\d+)/.match("1 + 2")
263
- # m.to_a #=> ["1 + 2", "1", "+", "2"]
264
- # m.values_at(:a, :b, :op) #=> ["1", "2", "+"]
265
- #
266
- def values_at: (*Integer | Symbol | String n_or_name) -> ::Array[String?]
267
-
268
- private
269
-
270
- def initialize_copy: (self object) -> void
271
- end
@@ -1,369 +0,0 @@
1
- # The Math module contains module functions for basic trigonometric and
2
- # transcendental functions. See class Float for a list of constants that define
3
- # Ruby's floating point accuracy.
4
- #
5
- # Domains and codomains are given only for real (not complex) numbers.
6
- #
7
- module Math
8
- # Computes the arc cosine of `x`. Returns 0..PI.
9
- #
10
- # Domain: [-1, 1]
11
- #
12
- # Codomain: [0, PI]
13
- #
14
- # Math.acos(0) == Math::PI/2 #=> true
15
- #
16
- def self.acos: (Integer | Float | Rational | BigDecimal x) -> Float
17
-
18
- # Computes the inverse hyperbolic cosine of `x`.
19
- #
20
- # Domain: [1, INFINITY)
21
- #
22
- # Codomain: [0, INFINITY)
23
- #
24
- # Math.acosh(1) #=> 0.0
25
- #
26
- def self.acosh: (Integer | Float | Rational | BigDecimal x) -> Float
27
-
28
- # Computes the arc sine of `x`. Returns -PI/2..PI/2.
29
- #
30
- # Domain: [-1, -1]
31
- #
32
- # Codomain: [-PI/2, PI/2]
33
- #
34
- # Math.asin(1) == Math::PI/2 #=> true
35
- #
36
- def self.asin: (Integer | Float | Rational | BigDecimal x) -> Float
37
-
38
- # Computes the inverse hyperbolic sine of `x`.
39
- #
40
- # Domain: (-INFINITY, INFINITY)
41
- #
42
- # Codomain: (-INFINITY, INFINITY)
43
- #
44
- # Math.asinh(1) #=> 0.881373587019543
45
- #
46
- def self.asinh: (Integer | Float | Rational | BigDecimal x) -> Float
47
-
48
- # Computes the arc tangent of `x`. Returns -PI/2..PI/2.
49
- #
50
- # Domain: (-INFINITY, INFINITY)
51
- #
52
- # Codomain: (-PI/2, PI/2)
53
- #
54
- # Math.atan(0) #=> 0.0
55
- #
56
- def self.atan: (Integer | Float | Rational | BigDecimal x) -> Float
57
-
58
- # Computes the arc tangent given `y` and `x`. Returns a Float in the range
59
- # -PI..PI. Return value is a angle in radians between the positive x-axis of
60
- # cartesian plane and the point given by the coordinates (`x`, `y`) on it.
61
- #
62
- # Domain: (-INFINITY, INFINITY)
63
- #
64
- # Codomain: [-PI, PI]
65
- #
66
- # Math.atan2(-0.0, -1.0) #=> -3.141592653589793
67
- # Math.atan2(-1.0, -1.0) #=> -2.356194490192345
68
- # Math.atan2(-1.0, 0.0) #=> -1.5707963267948966
69
- # Math.atan2(-1.0, 1.0) #=> -0.7853981633974483
70
- # Math.atan2(-0.0, 1.0) #=> -0.0
71
- # Math.atan2(0.0, 1.0) #=> 0.0
72
- # Math.atan2(1.0, 1.0) #=> 0.7853981633974483
73
- # Math.atan2(1.0, 0.0) #=> 1.5707963267948966
74
- # Math.atan2(1.0, -1.0) #=> 2.356194490192345
75
- # Math.atan2(0.0, -1.0) #=> 3.141592653589793
76
- # Math.atan2(INFINITY, INFINITY) #=> 0.7853981633974483
77
- # Math.atan2(INFINITY, -INFINITY) #=> 2.356194490192345
78
- # Math.atan2(-INFINITY, INFINITY) #=> -0.7853981633974483
79
- # Math.atan2(-INFINITY, -INFINITY) #=> -2.356194490192345
80
- #
81
- def self.atan2: (Integer | Float | Rational | BigDecimal y, Integer | Float | Rational | BigDecimal x) -> Float
82
-
83
- # Computes the inverse hyperbolic tangent of `x`.
84
- #
85
- # Domain: (-1, 1)
86
- #
87
- # Codomain: (-INFINITY, INFINITY)
88
- #
89
- # Math.atanh(1) #=> Infinity
90
- #
91
- def self.atanh: (Integer | Float | Rational | BigDecimal x) -> Float
92
-
93
- # Returns the cube root of `x`.
94
- #
95
- # Domain: (-INFINITY, INFINITY)
96
- #
97
- # Codomain: (-INFINITY, INFINITY)
98
- #
99
- # -9.upto(9) {|x|
100
- # p [x, Math.cbrt(x), Math.cbrt(x)**3]
101
- # }
102
- # #=> [-9, -2.0800838230519, -9.0]
103
- # # [-8, -2.0, -8.0]
104
- # # [-7, -1.91293118277239, -7.0]
105
- # # [-6, -1.81712059283214, -6.0]
106
- # # [-5, -1.7099759466767, -5.0]
107
- # # [-4, -1.5874010519682, -4.0]
108
- # # [-3, -1.44224957030741, -3.0]
109
- # # [-2, -1.25992104989487, -2.0]
110
- # # [-1, -1.0, -1.0]
111
- # # [0, 0.0, 0.0]
112
- # # [1, 1.0, 1.0]
113
- # # [2, 1.25992104989487, 2.0]
114
- # # [3, 1.44224957030741, 3.0]
115
- # # [4, 1.5874010519682, 4.0]
116
- # # [5, 1.7099759466767, 5.0]
117
- # # [6, 1.81712059283214, 6.0]
118
- # # [7, 1.91293118277239, 7.0]
119
- # # [8, 2.0, 8.0]
120
- # # [9, 2.0800838230519, 9.0]
121
- #
122
- def self.cbrt: (Integer | Float | Rational | BigDecimal x) -> Float
123
-
124
- # Computes the cosine of `x` (expressed in radians). Returns a Float in the
125
- # range -1.0..1.0.
126
- #
127
- # Domain: (-INFINITY, INFINITY)
128
- #
129
- # Codomain: [-1, 1]
130
- #
131
- # Math.cos(Math::PI) #=> -1.0
132
- #
133
- def self.cos: (Integer | Float | Rational | BigDecimal x) -> Float
134
-
135
- # Computes the hyperbolic cosine of `x` (expressed in radians).
136
- #
137
- # Domain: (-INFINITY, INFINITY)
138
- #
139
- # Codomain: [1, INFINITY)
140
- #
141
- # Math.cosh(0) #=> 1.0
142
- #
143
- def self.cosh: (Integer | Float | Rational | BigDecimal x) -> Float
144
-
145
- # Calculates the error function of `x`.
146
- #
147
- # Domain: (-INFINITY, INFINITY)
148
- #
149
- # Codomain: (-1, 1)
150
- #
151
- # Math.erf(0) #=> 0.0
152
- #
153
- def self.erf: (Integer | Float | Rational | BigDecimal x) -> Float
154
-
155
- # Calculates the complementary error function of x.
156
- #
157
- # Domain: (-INFINITY, INFINITY)
158
- #
159
- # Codomain: (0, 2)
160
- #
161
- # Math.erfc(0) #=> 1.0
162
- #
163
- def self.erfc: (Integer | Float | Rational | BigDecimal x) -> Float
164
-
165
- # Returns e**x.
166
- #
167
- # Domain: (-INFINITY, INFINITY)
168
- #
169
- # Codomain: (0, INFINITY)
170
- #
171
- # Math.exp(0) #=> 1.0
172
- # Math.exp(1) #=> 2.718281828459045
173
- # Math.exp(1.5) #=> 4.4816890703380645
174
- #
175
- def self.exp: (Integer | Float | Rational | BigDecimal x) -> Float
176
-
177
- # Returns a two-element array containing the normalized fraction (a Float) and
178
- # exponent (an Integer) of `x`.
179
- #
180
- # fraction, exponent = Math.frexp(1234) #=> [0.6025390625, 11]
181
- # fraction * 2**exponent #=> 1234.0
182
- #
183
- def self.frexp: (Integer | Float | Rational | BigDecimal x) -> [ Float, Integer ]
184
-
185
- # Calculates the gamma function of x.
186
- #
187
- # Note that gamma(n) is same as fact(n-1) for integer n > 0. However gamma(n)
188
- # returns float and can be an approximation.
189
- #
190
- # def fact(n) (1..n).inject(1) {|r,i| r*i } end
191
- # 1.upto(26) {|i| p [i, Math.gamma(i), fact(i-1)] }
192
- # #=> [1, 1.0, 1]
193
- # # [2, 1.0, 1]
194
- # # [3, 2.0, 2]
195
- # # [4, 6.0, 6]
196
- # # [5, 24.0, 24]
197
- # # [6, 120.0, 120]
198
- # # [7, 720.0, 720]
199
- # # [8, 5040.0, 5040]
200
- # # [9, 40320.0, 40320]
201
- # # [10, 362880.0, 362880]
202
- # # [11, 3628800.0, 3628800]
203
- # # [12, 39916800.0, 39916800]
204
- # # [13, 479001600.0, 479001600]
205
- # # [14, 6227020800.0, 6227020800]
206
- # # [15, 87178291200.0, 87178291200]
207
- # # [16, 1307674368000.0, 1307674368000]
208
- # # [17, 20922789888000.0, 20922789888000]
209
- # # [18, 355687428096000.0, 355687428096000]
210
- # # [19, 6.402373705728e+15, 6402373705728000]
211
- # # [20, 1.21645100408832e+17, 121645100408832000]
212
- # # [21, 2.43290200817664e+18, 2432902008176640000]
213
- # # [22, 5.109094217170944e+19, 51090942171709440000]
214
- # # [23, 1.1240007277776077e+21, 1124000727777607680000]
215
- # # [24, 2.5852016738885062e+22, 25852016738884976640000]
216
- # # [25, 6.204484017332391e+23, 620448401733239439360000]
217
- # # [26, 1.5511210043330954e+25, 15511210043330985984000000]
218
- #
219
- def self.gamma: (Integer | Float | Rational | BigDecimal x) -> Float
220
-
221
- # Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle with
222
- # sides `x` and `y`.
223
- #
224
- # Math.hypot(3, 4) #=> 5.0
225
- #
226
- def self.hypot: (Integer | Float | Rational | BigDecimal x, Integer | Float | Rational | BigDecimal y) -> Float
227
-
228
- # Returns the value of `fraction`*(2**`exponent`).
229
- #
230
- # fraction, exponent = Math.frexp(1234)
231
- # Math.ldexp(fraction, exponent) #=> 1234.0
232
- #
233
- def self.ldexp: (Integer | Float | Rational | BigDecimal fraction, Integer | Float | Rational | BigDecimal exponent) -> Float
234
-
235
- # Calculates the logarithmic gamma of `x` and the sign of gamma of `x`.
236
- #
237
- # Math.lgamma(x) is same as
238
- # [Math.log(Math.gamma(x).abs), Math.gamma(x) < 0 ? -1 : 1]
239
- #
240
- # but avoid overflow by Math.gamma(x) for large x.
241
- #
242
- # Math.lgamma(0) #=> [Infinity, 1]
243
- #
244
- def self.lgamma: (Integer | Float | Rational | BigDecimal x) -> [ Float, Integer ]
245
-
246
- def self.log: (Integer | Float | Rational | BigDecimal x, ?Integer | Float | Rational | BigDecimal base) -> Float
247
-
248
- # Returns the base 10 logarithm of `x`.
249
- #
250
- # Domain: (0, INFINITY)
251
- #
252
- # Codomain: (-INFINITY, INFINITY)
253
- #
254
- # Math.log10(1) #=> 0.0
255
- # Math.log10(10) #=> 1.0
256
- # Math.log10(10**100) #=> 100.0
257
- #
258
- def self.log10: (Integer | Float | Rational | BigDecimal x) -> Float
259
-
260
- # Returns the base 2 logarithm of `x`.
261
- #
262
- # Domain: (0, INFINITY)
263
- #
264
- # Codomain: (-INFINITY, INFINITY)
265
- #
266
- # Math.log2(1) #=> 0.0
267
- # Math.log2(2) #=> 1.0
268
- # Math.log2(32768) #=> 15.0
269
- # Math.log2(65536) #=> 16.0
270
- #
271
- def self.log2: (Integer | Float | Rational | BigDecimal x) -> Float
272
-
273
- # Computes the sine of `x` (expressed in radians). Returns a Float in the range
274
- # -1.0..1.0.
275
- #
276
- # Domain: (-INFINITY, INFINITY)
277
- #
278
- # Codomain: [-1, 1]
279
- #
280
- # Math.sin(Math::PI/2) #=> 1.0
281
- #
282
- def self.sin: (Integer | Float | Rational | BigDecimal x) -> Float
283
-
284
- # Computes the hyperbolic sine of `x` (expressed in radians).
285
- #
286
- # Domain: (-INFINITY, INFINITY)
287
- #
288
- # Codomain: (-INFINITY, INFINITY)
289
- #
290
- # Math.sinh(0) #=> 0.0
291
- #
292
- def self.sinh: (Integer | Float | Rational | BigDecimal x) -> Float
293
-
294
- # Returns the non-negative square root of `x`.
295
- #
296
- # Domain: [0, INFINITY)
297
- #
298
- # Codomain:[0, INFINITY)
299
- #
300
- # 0.upto(10) {|x|
301
- # p [x, Math.sqrt(x), Math.sqrt(x)**2]
302
- # }
303
- # #=> [0, 0.0, 0.0]
304
- # # [1, 1.0, 1.0]
305
- # # [2, 1.4142135623731, 2.0]
306
- # # [3, 1.73205080756888, 3.0]
307
- # # [4, 2.0, 4.0]
308
- # # [5, 2.23606797749979, 5.0]
309
- # # [6, 2.44948974278318, 6.0]
310
- # # [7, 2.64575131106459, 7.0]
311
- # # [8, 2.82842712474619, 8.0]
312
- # # [9, 3.0, 9.0]
313
- # # [10, 3.16227766016838, 10.0]
314
- #
315
- # Note that the limited precision of floating point arithmetic might lead to
316
- # surprising results:
317
- #
318
- # Math.sqrt(10**46).to_i #=> 99999999999999991611392 (!)
319
- #
320
- # See also BigDecimal#sqrt and Integer.sqrt.
321
- #
322
- def self.sqrt: (Integer | Float | Rational | BigDecimal x) -> Float
323
-
324
- # Computes the tangent of `x` (expressed in radians).
325
- #
326
- # Domain: (-INFINITY, INFINITY)
327
- #
328
- # Codomain: (-INFINITY, INFINITY)
329
- #
330
- # Math.tan(0) #=> 0.0
331
- #
332
- def self.tan: (Integer | Float | Rational | BigDecimal x) -> Float
333
-
334
- # Computes the hyperbolic tangent of `x` (expressed in radians).
335
- #
336
- # Domain: (-INFINITY, INFINITY)
337
- #
338
- # Codomain: (-1, 1)
339
- #
340
- # Math.tanh(0) #=> 0.0
341
- #
342
- def self.tanh: (Integer | Float | Rational | BigDecimal x) -> Float
343
- end
344
-
345
- # Definition of the mathematical constant E for Euler's number (e) as a Float
346
- # number.
347
- #
348
- #
349
- Math::E: Float
350
-
351
- # Definition of the mathematical constant PI as a Float number.
352
- #
353
- #
354
- Math::PI: Float
355
-
356
- # Raised when a mathematical function is evaluated outside of its domain of
357
- # definition.
358
- #
359
- # For example, since `cos` returns values in the range -1..1, its inverse
360
- # function `acos` is only defined on that interval:
361
- #
362
- # Math.acos(42)
363
- #
364
- # *produces:*
365
- #
366
- # Math::DomainError: Numerical argument is out of domain - "acos"
367
- #
368
- class Math::DomainError < StandardError
369
- end