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,161 @@
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
@@ -0,0 +1,271 @@
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
@@ -0,0 +1,369 @@
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