steep 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +27 -0
- data/.gitmodules +3 -0
- data/CHANGELOG.md +5 -0
- data/README.md +48 -90
- data/Rakefile +10 -6
- data/Steepfile +1 -0
- data/bin/setup +1 -0
- data/bin/smoke_runner.rb +9 -14
- data/exe/rbs +3 -0
- data/exe/ruby-signature +3 -0
- data/exe/steep +1 -0
- data/lib/steep.rb +32 -26
- data/lib/steep/annotation_parser.rb +167 -0
- data/lib/steep/ast/annotation/collection.rb +7 -7
- data/lib/steep/ast/types.rb +60 -0
- data/lib/steep/ast/types/any.rb +1 -1
- data/lib/steep/ast/types/factory.rb +535 -0
- data/lib/steep/ast/types/name.rb +3 -3
- data/lib/steep/ast/types/var.rb +1 -1
- data/lib/steep/cli.rb +56 -240
- data/lib/steep/drivers/annotations.rb +36 -19
- data/lib/steep/drivers/check.rb +55 -91
- data/lib/steep/drivers/init.rb +54 -0
- data/lib/steep/drivers/langserver.rb +241 -150
- data/lib/steep/drivers/print_project.rb +56 -0
- data/lib/steep/drivers/signature_error_printer.rb +25 -0
- data/lib/steep/drivers/trace_printer.rb +25 -0
- data/lib/steep/drivers/utils/driver_helper.rb +26 -0
- data/lib/steep/drivers/validate.rb +18 -38
- data/lib/steep/drivers/vendor.rb +46 -0
- data/lib/steep/drivers/watch.rb +78 -140
- data/lib/steep/errors.rb +22 -13
- data/lib/steep/interface/interface.rb +91 -0
- data/lib/steep/interface/method.rb +0 -4
- data/lib/steep/interface/method_type.rb +362 -2
- data/lib/steep/interface/substitution.rb +22 -0
- data/lib/steep/project.rb +25 -233
- data/lib/steep/project/dsl.rb +132 -0
- data/lib/steep/project/file.rb +93 -76
- data/lib/steep/project/file_loader.rb +63 -0
- data/lib/steep/project/options.rb +7 -0
- data/lib/steep/project/target.rb +190 -0
- data/lib/steep/signature/errors.rb +25 -77
- data/lib/steep/signature/validator.rb +122 -0
- data/lib/steep/source.rb +12 -7
- data/lib/steep/subtyping/check.rb +357 -633
- data/lib/steep/subtyping/constraints.rb +2 -2
- data/lib/steep/subtyping/trace.rb +23 -0
- data/lib/steep/type_construction.rb +509 -455
- data/lib/steep/type_inference/constant_env.rb +16 -24
- data/lib/steep/type_inference/type_env.rb +26 -18
- data/lib/steep/version.rb +1 -1
- data/sample/Steepfile +6 -0
- data/sample/lib/conference.rb +12 -0
- data/sample/sig/conference.rbs +6 -0
- data/smoke/alias/Steepfile +4 -0
- data/smoke/alias/a.rb +2 -2
- data/smoke/alias/{a.rbi → a.rbs} +1 -1
- data/smoke/and/Steepfile +4 -0
- data/smoke/array/Steepfile +4 -0
- data/smoke/array/a.rb +2 -2
- data/smoke/array/b.rb +4 -4
- data/smoke/array/c.rb +2 -2
- data/smoke/block/Steepfile +5 -0
- data/smoke/block/{a.rbi → a.rbs} +1 -1
- data/smoke/block/{c.rbi → c.rbs} +0 -0
- data/smoke/block/d.rb +6 -6
- data/smoke/case/Steepfile +4 -0
- data/smoke/case/a.rb +4 -3
- data/smoke/class/Steepfile +4 -0
- data/smoke/class/a.rb +1 -4
- data/smoke/class/a.rbs +24 -0
- data/smoke/class/h.rb +6 -2
- data/smoke/class/{h.rbi → h.rbs} +1 -2
- data/smoke/class/i.rb +1 -2
- data/smoke/class/i.rbs +9 -0
- data/smoke/const/Steepfile +4 -0
- data/smoke/dstr/Steepfile +4 -0
- data/smoke/ensure/Steepfile +4 -0
- data/smoke/ensure/a.rb +1 -1
- data/smoke/enumerator/Steepfile +4 -0
- data/smoke/enumerator/a.rb +7 -7
- data/smoke/enumerator/b.rb +6 -6
- data/smoke/extension/Steepfile +4 -0
- data/smoke/extension/{a.rbi → a.rbs} +2 -2
- data/smoke/extension/{e.rbi → e.rbs} +2 -2
- data/smoke/hash/Steepfile +4 -0
- data/smoke/hash/{a.rbi → a.rbs} +0 -0
- data/smoke/hash/b.rb +2 -2
- data/smoke/hash/c.rb +1 -1
- data/smoke/hash/e.rbs +3 -0
- data/smoke/hash/f.rb +1 -1
- data/smoke/hello/Steepfile +4 -0
- data/smoke/hello/hello.rbs +7 -0
- data/smoke/if/Steepfile +4 -0
- data/smoke/implements/Steepfile +4 -0
- data/smoke/implements/a.rbs +6 -0
- data/smoke/initialize/Steepfile +4 -0
- data/smoke/initialize/a.rbs +3 -0
- data/smoke/integer/Steepfile +4 -0
- data/smoke/integer/a.rb +5 -3
- data/smoke/interface/Steepfile +4 -0
- data/smoke/interface/{a.rbi → a.rbs} +0 -0
- data/smoke/kwbegin/Steepfile +4 -0
- data/smoke/lambda/Steepfile +4 -0
- data/smoke/lambda/a.rb +9 -2
- data/smoke/literal/Steepfile +4 -0
- data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
- data/smoke/map/Steepfile +4 -0
- data/smoke/map/a.rb +1 -1
- data/smoke/method/Steepfile +4 -0
- data/smoke/method/{a.rbi → a.rbs} +0 -0
- data/smoke/method/b.rb +1 -4
- data/smoke/method/d.rb +1 -0
- data/smoke/method/d.rbs +3 -0
- data/smoke/module/Steepfile +4 -0
- data/smoke/module/a.rb +1 -1
- data/smoke/module/a.rbs +16 -0
- data/smoke/module/c.rb +1 -1
- data/smoke/regexp/Steepfile +4 -0
- data/smoke/regexp/a.rb +2 -2
- data/smoke/regexp/b.rb +16 -16
- data/smoke/regression/Steepfile +5 -0
- data/smoke/regression/array.rb +2 -2
- data/smoke/regression/hash.rb +2 -2
- data/smoke/regression/poly_new.rb +2 -0
- data/smoke/regression/poly_new.rbs +4 -0
- data/smoke/regression/set_divide.rb +2 -2
- data/smoke/rescue/Steepfile +4 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +4 -0
- data/smoke/self/a.rbs +4 -0
- data/smoke/skip/Steepfile +4 -0
- data/smoke/stdout/Steepfile +4 -0
- data/smoke/stdout/{a.rbi → a.rbs} +1 -1
- data/smoke/super/Steepfile +4 -0
- data/smoke/super/a.rbs +10 -0
- data/smoke/type_case/Steepfile +4 -0
- data/smoke/type_case/a.rb +1 -1
- data/smoke/yield/Steepfile +4 -0
- data/smoke/yield/a.rb +2 -2
- data/steep.gemspec +14 -7
- data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
- data/vendor/ruby-signature/.gitignore +12 -0
- data/vendor/ruby-signature/.rubocop.yml +15 -0
- data/vendor/ruby-signature/BSDL +22 -0
- data/vendor/ruby-signature/COPYING +56 -0
- data/vendor/ruby-signature/Gemfile +6 -0
- data/vendor/ruby-signature/README.md +93 -0
- data/vendor/ruby-signature/Rakefile +66 -0
- data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
- data/vendor/ruby-signature/bin/console +14 -0
- data/vendor/ruby-signature/bin/query-rdoc +103 -0
- data/vendor/ruby-signature/bin/setup +10 -0
- data/vendor/ruby-signature/bin/sort +88 -0
- data/vendor/ruby-signature/bin/test_runner.rb +17 -0
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
- data/vendor/ruby-signature/docs/sigs.md +148 -0
- data/vendor/ruby-signature/docs/stdlib.md +152 -0
- data/vendor/ruby-signature/docs/syntax.md +528 -0
- data/vendor/ruby-signature/exe/rbs +3 -0
- data/vendor/ruby-signature/exe/ruby-signature +7 -0
- data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
- data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
- data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
- data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
- metadata +244 -54
- data/.travis.yml +0 -7
- data/lib/steep/ast/signature/alias.rb +0 -19
- data/lib/steep/ast/signature/class.rb +0 -33
- data/lib/steep/ast/signature/const.rb +0 -17
- data/lib/steep/ast/signature/env.rb +0 -138
- data/lib/steep/ast/signature/extension.rb +0 -21
- data/lib/steep/ast/signature/gvar.rb +0 -17
- data/lib/steep/ast/signature/interface.rb +0 -31
- data/lib/steep/ast/signature/members.rb +0 -115
- data/lib/steep/ast/signature/module.rb +0 -21
- data/lib/steep/drivers/print_interface.rb +0 -94
- data/lib/steep/drivers/scaffold.rb +0 -321
- data/lib/steep/drivers/utils/each_signature.rb +0 -31
- data/lib/steep/interface/abstract.rb +0 -68
- data/lib/steep/interface/builder.rb +0 -637
- data/lib/steep/interface/instantiated.rb +0 -163
- data/lib/steep/interface/ivar_chain.rb +0 -26
- data/lib/steep/parser.y +0 -1278
- data/lib/steep/project/listener.rb +0 -53
- data/smoke/class/a.rbi +0 -24
- data/smoke/class/d.rb +0 -9
- data/smoke/class/e.rb +0 -12
- data/smoke/class/i.rbi +0 -9
- data/smoke/hash/e.rbi +0 -3
- data/smoke/hello/hello.rbi +0 -7
- data/smoke/implements/a.rbi +0 -6
- data/smoke/initialize/a.rbi +0 -3
- data/smoke/module/a.rbi +0 -16
- data/smoke/self/a.rbi +0 -4
- data/smoke/super/a.rbi +0 -10
- data/stdlib/builtin.rbi +0 -787
@@ -0,0 +1,135 @@
|
|
1
|
+
# The marshaling library converts collections of Ruby objects into a byte
|
2
|
+
# stream, allowing them to be stored outside the currently active script.
|
3
|
+
# This data may subsequently be read and the original objects
|
4
|
+
# reconstituted.
|
5
|
+
#
|
6
|
+
# Marshaled data has major and minor version numbers stored along with the
|
7
|
+
# object information. In normal use, marshaling can only load data written
|
8
|
+
# with the same major version number and an equal or lower minor version
|
9
|
+
# number. If Ruby’s “verbose” flag is set (normally using -d, -v, -w, or
|
10
|
+
# –verbose) the major and minor numbers must match exactly.
|
11
|
+
# [Marshal](Marshal) versioning is independent of
|
12
|
+
# Ruby’s version numbers. You can extract the version by reading the
|
13
|
+
# first two bytes of marshaled data.
|
14
|
+
#
|
15
|
+
# ```ruby
|
16
|
+
# str = Marshal.dump("thing")
|
17
|
+
# RUBY_VERSION #=> "1.9.0"
|
18
|
+
# str[0].ord #=> 4
|
19
|
+
# str[1].ord #=> 8
|
20
|
+
# ```
|
21
|
+
#
|
22
|
+
# Some objects cannot be dumped: if the objects to be dumped include
|
23
|
+
# bindings, procedure or method objects, instances of class
|
24
|
+
# [IO](https://ruby-doc.org/core-2.6.3/IO.html), or singleton objects, a
|
25
|
+
# [TypeError](https://ruby-doc.org/core-2.6.3/TypeError.html) will be
|
26
|
+
# raised.
|
27
|
+
#
|
28
|
+
# If your class has special serialization needs (for example, if you want
|
29
|
+
# to serialize in some specific format), or if it contains objects that
|
30
|
+
# would otherwise not be serializable, you can implement your own
|
31
|
+
# serialization strategy.
|
32
|
+
#
|
33
|
+
# There are two methods of doing this, your object can define either
|
34
|
+
# marshal\_dump and marshal\_load or \_dump and \_load. marshal\_dump will
|
35
|
+
# take precedence over \_dump if both are defined. marshal\_dump may
|
36
|
+
# result in smaller [Marshal](Marshal) strings.
|
37
|
+
#
|
38
|
+
#
|
39
|
+
# By design, [::load](Marshal#method-c-load) can
|
40
|
+
# deserialize almost any class loaded into the Ruby process. In many cases
|
41
|
+
# this can lead to remote code execution if the
|
42
|
+
# [Marshal](Marshal) data is loaded from an untrusted
|
43
|
+
# source.
|
44
|
+
#
|
45
|
+
# As a result, [::load](Marshal#method-c-load) is not
|
46
|
+
# suitable as a general purpose serialization format and you should never
|
47
|
+
# unmarshal user supplied input or other untrusted data.
|
48
|
+
#
|
49
|
+
# If you need to deserialize untrusted data, use JSON or another
|
50
|
+
# serialization format that is only able to load simple, ‘primitive’ types
|
51
|
+
# such as [String](https://ruby-doc.org/core-2.6.3/String.html),
|
52
|
+
# [Array](https://ruby-doc.org/core-2.6.3/Array.html),
|
53
|
+
# [Hash](https://ruby-doc.org/core-2.6.3/Hash.html), etc. Never allow
|
54
|
+
# user input to specify arbitrary types to deserialize into.
|
55
|
+
#
|
56
|
+
#
|
57
|
+
# When dumping an object the method marshal\_dump will be called.
|
58
|
+
# marshal\_dump must return a result containing the information necessary
|
59
|
+
# for marshal\_load to reconstitute the object. The result can be any
|
60
|
+
# object.
|
61
|
+
#
|
62
|
+
# When loading an object dumped using marshal\_dump the object is first
|
63
|
+
# allocated then marshal\_load is called with the result from
|
64
|
+
# marshal\_dump. marshal\_load must recreate the object from the
|
65
|
+
# information in the result.
|
66
|
+
#
|
67
|
+
# Example:
|
68
|
+
#
|
69
|
+
# ```ruby
|
70
|
+
# class MyObj
|
71
|
+
# def initialize name, version, data
|
72
|
+
# @name = name
|
73
|
+
# @version = version
|
74
|
+
# @data = data
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# def marshal_dump
|
78
|
+
# [@name, @version]
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# def marshal_load array
|
82
|
+
# @name, @version = array
|
83
|
+
# end
|
84
|
+
# end
|
85
|
+
# ```
|
86
|
+
#
|
87
|
+
#
|
88
|
+
# Use \_dump and \_load when you need to allocate the object you’re
|
89
|
+
# restoring yourself.
|
90
|
+
#
|
91
|
+
# When dumping an object the instance method \_dump is called with an
|
92
|
+
# [Integer](https://ruby-doc.org/core-2.6.3/Integer.html) which indicates
|
93
|
+
# the maximum depth of objects to dump (a value of -1 implies that you
|
94
|
+
# should disable depth checking). \_dump must return a
|
95
|
+
# [String](https://ruby-doc.org/core-2.6.3/String.html) containing the
|
96
|
+
# information necessary to reconstitute the object.
|
97
|
+
#
|
98
|
+
# The class method \_load should take a
|
99
|
+
# [String](https://ruby-doc.org/core-2.6.3/String.html) and use it to
|
100
|
+
# return an object of the same class.
|
101
|
+
#
|
102
|
+
# Example:
|
103
|
+
#
|
104
|
+
# ```ruby
|
105
|
+
# class MyObj
|
106
|
+
# def initialize name, version, data
|
107
|
+
# @name = name
|
108
|
+
# @version = version
|
109
|
+
# @data = data
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
# def _dump level
|
113
|
+
# [@name, @version].join ':'
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# def self._load args
|
117
|
+
# new(*args.split(':'))
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
# ```
|
121
|
+
#
|
122
|
+
# Since [::dump](Marshal#method-c-dump) outputs a
|
123
|
+
# string you can have \_dump return a
|
124
|
+
# [Marshal](Marshal) string which is Marshal.loaded in
|
125
|
+
# \_load for complex objects.
|
126
|
+
module Marshal
|
127
|
+
def self.dump: (Object arg0, ?IO arg1, ?Integer arg2) -> Object
|
128
|
+
| (Object arg0, ?Integer arg1) -> Object
|
129
|
+
|
130
|
+
def self.load: (String arg0, ?Proc arg1) -> Object
|
131
|
+
end
|
132
|
+
|
133
|
+
Marshal::MAJOR_VERSION: Integer
|
134
|
+
|
135
|
+
Marshal::MINOR_VERSION: Integer
|
@@ -0,0 +1,141 @@
|
|
1
|
+
class MatchData < Object
|
2
|
+
def ==: (untyped arg0) -> bool
|
3
|
+
|
4
|
+
def []: (Integer i_or_start_or_range_or_name) -> String?
|
5
|
+
| (Integer i_or_start_or_range_or_name, ?Integer length) -> ::Array[String]
|
6
|
+
| (::Range[Integer] i_or_start_or_range_or_name) -> ::Array[String]
|
7
|
+
| (String | Symbol i_or_start_or_range_or_name) -> String?
|
8
|
+
|
9
|
+
def begin: (Integer | String | Symbol n) -> Integer?
|
10
|
+
|
11
|
+
# Returns the array of captures; equivalent to `mtch.to_a[1..-1]` .
|
12
|
+
#
|
13
|
+
# ```ruby
|
14
|
+
# f1,f2,f3,f4 = /(.)(.)(\d+)(\d)/.match("THX1138.").captures
|
15
|
+
# f1 #=> "H"
|
16
|
+
# f2 #=> "X"
|
17
|
+
# f3 #=> "113"
|
18
|
+
# f4 #=> "8"
|
19
|
+
# ```
|
20
|
+
def captures: () -> ::Array[String]
|
21
|
+
|
22
|
+
def `end`: (Integer | String | Symbol n) -> Integer?
|
23
|
+
|
24
|
+
def eql?: (untyped other) -> bool
|
25
|
+
|
26
|
+
# Produce a hash based on the target string, regexp and matched positions
|
27
|
+
# of this matchdata.
|
28
|
+
#
|
29
|
+
# See also Object\#hash.
|
30
|
+
def hash: () -> Integer
|
31
|
+
|
32
|
+
def inspect: () -> String
|
33
|
+
|
34
|
+
# Returns the number of elements in the match array.
|
35
|
+
#
|
36
|
+
# ```ruby
|
37
|
+
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
38
|
+
# m.length #=> 5
|
39
|
+
# m.size #=> 5
|
40
|
+
# ```
|
41
|
+
def length: () -> Integer
|
42
|
+
|
43
|
+
# Returns a [Hash](https://ruby-doc.org/core-2.6.3/Hash.html) using named
|
44
|
+
# capture.
|
45
|
+
#
|
46
|
+
# A key of the hash is a name of the named captures. A value of the hash
|
47
|
+
# is a string of last successful capture of corresponding group.
|
48
|
+
#
|
49
|
+
# ```ruby
|
50
|
+
# m = /(?.)(?.)/.match("01")
|
51
|
+
# m.named_captures #=> {"a" => "0", "b" => "1"}
|
52
|
+
#
|
53
|
+
# m = /(?.)(?.)?/.match("0")
|
54
|
+
# m.named_captures #=> {"a" => "0", "b" => nil}
|
55
|
+
#
|
56
|
+
# m = /(?.)(?.)/.match("01")
|
57
|
+
# m.named_captures #=> {"a" => "1"}
|
58
|
+
#
|
59
|
+
# m = /(?x)|(?y)/.match("x")
|
60
|
+
# m.named_captures #=> {"a" => "x"}
|
61
|
+
# ```
|
62
|
+
def named_captures: () -> ::Hash[String, String?]
|
63
|
+
|
64
|
+
def names: () -> ::Array[String]
|
65
|
+
|
66
|
+
def offset: (Integer | Symbol | String n) -> ([Integer, Integer] | [nil, nil])
|
67
|
+
|
68
|
+
# Returns the portion of the original string after the current match.
|
69
|
+
# Equivalent to the special variable `$'` .
|
70
|
+
#
|
71
|
+
# ```ruby
|
72
|
+
# m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
|
73
|
+
# m.post_match #=> ": The Movie"
|
74
|
+
# ```
|
75
|
+
def post_match: () -> String
|
76
|
+
|
77
|
+
# Returns the portion of the original string before the current match.
|
78
|
+
# Equivalent to the special variable `` $` `` .
|
79
|
+
#
|
80
|
+
# ```ruby
|
81
|
+
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
82
|
+
# m.pre_match #=> "T"
|
83
|
+
# ```
|
84
|
+
def pre_match: () -> String
|
85
|
+
|
86
|
+
# Returns the regexp.
|
87
|
+
#
|
88
|
+
# ```ruby
|
89
|
+
# m = /a.*b/.match("abc")
|
90
|
+
# m.regexp #=> /a.*b/
|
91
|
+
# ```
|
92
|
+
def regexp: () -> Regexp
|
93
|
+
|
94
|
+
# Returns the number of elements in the match array.
|
95
|
+
#
|
96
|
+
# ```ruby
|
97
|
+
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
98
|
+
# m.length #=> 5
|
99
|
+
# m.size #=> 5
|
100
|
+
# ```
|
101
|
+
def size: () -> Integer
|
102
|
+
|
103
|
+
# Returns a frozen copy of the string passed in to `match` .
|
104
|
+
#
|
105
|
+
# ```ruby
|
106
|
+
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
107
|
+
# m.string #=> "THX1138."
|
108
|
+
# ```
|
109
|
+
def string: () -> String
|
110
|
+
|
111
|
+
# Returns the array of matches.
|
112
|
+
#
|
113
|
+
# ```ruby
|
114
|
+
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
115
|
+
# m.to_a #=> ["HX1138", "H", "X", "113", "8"]
|
116
|
+
# ```
|
117
|
+
#
|
118
|
+
# Because `to_a` is called when expanding `*` *variable* , there’s a
|
119
|
+
# useful assignment shortcut for extracting matched fields. This is
|
120
|
+
# slightly slower than accessing the fields directly (as an intermediate
|
121
|
+
# array is generated).
|
122
|
+
#
|
123
|
+
# ```ruby
|
124
|
+
# all,f1,f2,f3 = * /(.)(.)(\d+)(\d)/.match("THX1138.")
|
125
|
+
# all #=> "HX1138"
|
126
|
+
# f1 #=> "H"
|
127
|
+
# f2 #=> "X"
|
128
|
+
# f3 #=> "113"
|
129
|
+
# ```
|
130
|
+
def to_a: () -> ::Array[String]
|
131
|
+
|
132
|
+
# Returns the entire matched string.
|
133
|
+
#
|
134
|
+
# ```ruby
|
135
|
+
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
136
|
+
# m.to_s #=> "HX1138"
|
137
|
+
# ```
|
138
|
+
def to_s: () -> String
|
139
|
+
|
140
|
+
def values_at: (*Integer | Symbol | String indexes) -> ::Array[String?]
|
141
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# The [Math](Math) module contains module functions
|
2
|
+
# for basic trigonometric and transcendental functions. See class
|
3
|
+
# [Float](https://ruby-doc.org/core-2.6.3/Float.html) for a list of
|
4
|
+
# constants that define Ruby's floating point accuracy.
|
5
|
+
#
|
6
|
+
# Domains and codomains are given only for real (not complex) numbers.
|
7
|
+
module Math
|
8
|
+
def self.acos: (Integer | Float | Rational | BigDecimal x) -> Float
|
9
|
+
|
10
|
+
def self.acosh: (Integer | Float | Rational | BigDecimal x) -> Float
|
11
|
+
|
12
|
+
def self.asin: (Integer | Float | Rational | BigDecimal x) -> Float
|
13
|
+
|
14
|
+
def self.asinh: (Integer | Float | Rational | BigDecimal x) -> Float
|
15
|
+
|
16
|
+
def self.atan: (Integer | Float | Rational | BigDecimal x) -> Float
|
17
|
+
|
18
|
+
def self.atan2: (Integer | Float | Rational | BigDecimal y, Integer | Float | Rational | BigDecimal x) -> Float
|
19
|
+
|
20
|
+
def self.atanh: (Integer | Float | Rational | BigDecimal x) -> Float
|
21
|
+
|
22
|
+
def self.cbrt: (Integer | Float | Rational | BigDecimal x) -> Float
|
23
|
+
|
24
|
+
def self.cos: (Integer | Float | Rational | BigDecimal x) -> Float
|
25
|
+
|
26
|
+
def self.cosh: (Integer | Float | Rational | BigDecimal x) -> Float
|
27
|
+
|
28
|
+
def self.erf: (Integer | Float | Rational | BigDecimal x) -> Float
|
29
|
+
|
30
|
+
def self.erfc: (Integer | Float | Rational | BigDecimal x) -> Float
|
31
|
+
|
32
|
+
def self.exp: (Integer | Float | Rational | BigDecimal x) -> Float
|
33
|
+
|
34
|
+
def self.frexp: (Integer | Float | Rational | BigDecimal x) -> [ Integer | Float | Rational | BigDecimal, Integer | Float | Rational | BigDecimal ]
|
35
|
+
|
36
|
+
def self.gamma: (Integer | Float | Rational | BigDecimal x) -> Float
|
37
|
+
|
38
|
+
def self.hypot: (Integer | Float | Rational | BigDecimal x, Integer | Float | Rational | BigDecimal y) -> Float
|
39
|
+
|
40
|
+
def self.ldexp: (Integer | Float | Rational | BigDecimal fraction, Integer | Float | Rational | BigDecimal exponent) -> Float
|
41
|
+
|
42
|
+
def self.lgamma: (Integer | Float | Rational | BigDecimal x) -> (Integer | Float)
|
43
|
+
|
44
|
+
def self.log: (Integer | Float | Rational | BigDecimal x, ?Integer | Float | Rational | BigDecimal base) -> Float
|
45
|
+
|
46
|
+
def self.log10: (Integer | Float | Rational | BigDecimal x) -> Float
|
47
|
+
|
48
|
+
def self.log2: (Integer | Float | Rational | BigDecimal x) -> Float
|
49
|
+
|
50
|
+
def self.sin: (Integer | Float | Rational | BigDecimal x) -> Float
|
51
|
+
|
52
|
+
def self.sinh: (Integer | Float | Rational | BigDecimal x) -> Float
|
53
|
+
|
54
|
+
def self.sqrt: (Integer | Float | Rational | BigDecimal x) -> Float
|
55
|
+
|
56
|
+
def self.tan: (Integer | Float | Rational | BigDecimal x) -> Float
|
57
|
+
|
58
|
+
def self.tanh: (Integer | Float | Rational | BigDecimal x) -> Float
|
59
|
+
end
|
60
|
+
|
61
|
+
Math::E: Float
|
62
|
+
|
63
|
+
Math::PI: Float
|
64
|
+
|
65
|
+
class Math::DomainError < StandardError
|
66
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
class Method < Object
|
2
|
+
# Returns a `Proc` object corresponding to this method.
|
3
|
+
def to_proc: () -> Proc
|
4
|
+
|
5
|
+
# Invokes the *meth* with the specified arguments, returning the method’s
|
6
|
+
# return value.
|
7
|
+
#
|
8
|
+
# ```ruby
|
9
|
+
# m = 12.method("+")
|
10
|
+
# m.call(3) #=> 15
|
11
|
+
# m.call(20) #=> 32
|
12
|
+
# ```
|
13
|
+
def call: (*untyped args) -> untyped
|
14
|
+
|
15
|
+
# Returns a proc that is the composition of this method and the given *g*
|
16
|
+
# . The returned proc takes a variable number of arguments, calls *g* with
|
17
|
+
# them then calls this method with the result.
|
18
|
+
#
|
19
|
+
# ```ruby
|
20
|
+
# def f(x)
|
21
|
+
# x * x
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# f = self.method(:f)
|
25
|
+
# g = proc {|x| x + x }
|
26
|
+
# p (f << g).call(2) #=> 16
|
27
|
+
# ```
|
28
|
+
def <<: (untyped g) -> untyped
|
29
|
+
|
30
|
+
# Invokes the method with `obj` as the parameter like
|
31
|
+
# [call](Method.downloaded.ruby_doc#method-i-call). This allows a method
|
32
|
+
# object to be the target of a `when` clause in a case statement.
|
33
|
+
#
|
34
|
+
# ```ruby
|
35
|
+
# require 'prime'
|
36
|
+
#
|
37
|
+
# case 1373
|
38
|
+
# when Prime.method(:prime?)
|
39
|
+
# # ...
|
40
|
+
# end
|
41
|
+
# ```
|
42
|
+
def ===: (*untyped obj) -> untyped
|
43
|
+
|
44
|
+
# Returns a proc that is the composition of this method and the given *g*
|
45
|
+
# . The returned proc takes a variable number of arguments, calls *g* with
|
46
|
+
# them then calls this method with the result.
|
47
|
+
#
|
48
|
+
# ```ruby
|
49
|
+
# def f(x)
|
50
|
+
# x * x
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# f = self.method(:f)
|
54
|
+
# g = proc {|x| x + x }
|
55
|
+
# p (f >> g).call(2) #=> 8
|
56
|
+
# ```
|
57
|
+
def >>: (untyped g) -> untyped
|
58
|
+
|
59
|
+
# Invokes the *meth* with the specified arguments, returning the method’s
|
60
|
+
# return value.
|
61
|
+
#
|
62
|
+
# ```ruby
|
63
|
+
# m = 12.method("+")
|
64
|
+
# m.call(3) #=> 15
|
65
|
+
# m.call(20) #=> 32
|
66
|
+
# ```
|
67
|
+
def []: (*untyped args) -> untyped
|
68
|
+
|
69
|
+
# Returns an indication of the number of arguments accepted by a method.
|
70
|
+
# Returns a nonnegative integer for methods that take a fixed number of
|
71
|
+
# arguments. For Ruby methods that take a variable number of arguments,
|
72
|
+
# returns -n-1, where n is the number of required arguments. Keyword
|
73
|
+
# arguments will be considered as a single additional argument, that
|
74
|
+
# argument being mandatory if any keyword argument is mandatory. For
|
75
|
+
# methods written in C, returns -1 if the call takes a variable number of
|
76
|
+
# arguments.
|
77
|
+
#
|
78
|
+
# class C
|
79
|
+
# def one; end
|
80
|
+
# def two(a); end
|
81
|
+
# def three(*a); end
|
82
|
+
# def four(a, b); end
|
83
|
+
# def five(a, b, *c); end
|
84
|
+
# def six(a, b, *c, &d); end
|
85
|
+
# def seven(a, b, x:0); end
|
86
|
+
# def eight(x:, y:); end
|
87
|
+
# def nine(x:, y:, **z); end
|
88
|
+
# def ten(*a, x:, y:); end
|
89
|
+
# end
|
90
|
+
# c = C.new
|
91
|
+
# c.method(:one).arity #=> 0
|
92
|
+
# c.method(:two).arity #=> 1
|
93
|
+
# c.method(:three).arity #=> -1
|
94
|
+
# c.method(:four).arity #=> 2
|
95
|
+
# c.method(:five).arity #=> -3
|
96
|
+
# c.method(:six).arity #=> -3
|
97
|
+
# c.method(:seven).arity #=> -3
|
98
|
+
# c.method(:eight).arity #=> 1
|
99
|
+
# c.method(:nine).arity #=> 1
|
100
|
+
# c.method(:ten).arity #=> -2
|
101
|
+
#
|
102
|
+
# "cat".method(:size).arity #=> 0
|
103
|
+
# "cat".method(:replace).arity #=> 1
|
104
|
+
# "cat".method(:squeeze).arity #=> -1
|
105
|
+
# "cat".method(:count).arity #=> -1
|
106
|
+
def arity: () -> Integer
|
107
|
+
|
108
|
+
# Returns a clone of this method.
|
109
|
+
#
|
110
|
+
# ```ruby
|
111
|
+
# class A
|
112
|
+
# def foo
|
113
|
+
# return "bar"
|
114
|
+
# end
|
115
|
+
# end
|
116
|
+
#
|
117
|
+
# m = A.new.method(:foo)
|
118
|
+
# m.call # => "bar"
|
119
|
+
# n = m.clone.call # => "bar"
|
120
|
+
# ```
|
121
|
+
def clone: () -> Method
|
122
|
+
|
123
|
+
def curry: (*untyped args) -> untyped
|
124
|
+
|
125
|
+
# Returns the name of the method.
|
126
|
+
def name: () -> Symbol
|
127
|
+
|
128
|
+
# Returns the original name of the method.
|
129
|
+
#
|
130
|
+
# ```ruby
|
131
|
+
# class C
|
132
|
+
# def foo; end
|
133
|
+
# alias bar foo
|
134
|
+
# end
|
135
|
+
# C.instance_method(:bar).original_name # => :foo
|
136
|
+
# ```
|
137
|
+
def original_name: () -> Symbol
|
138
|
+
|
139
|
+
# Returns the class or module that defines the method. See also receiver.
|
140
|
+
#
|
141
|
+
# ```ruby
|
142
|
+
# (1..3).method(:map).owner #=> Enumerable
|
143
|
+
# ```
|
144
|
+
def owner: () -> (Class | Module)
|
145
|
+
|
146
|
+
# Returns the parameter information of this method.
|
147
|
+
#
|
148
|
+
# ```ruby
|
149
|
+
# def foo(bar); end
|
150
|
+
# method(:foo).parameters #=> [[:req, :bar]]
|
151
|
+
#
|
152
|
+
# def foo(bar, baz, bat, &blk); end
|
153
|
+
# method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:req, :bat], [:block, :blk]]
|
154
|
+
#
|
155
|
+
# def foo(bar, *args); end
|
156
|
+
# method(:foo).parameters #=> [[:req, :bar], [:rest, :args]]
|
157
|
+
#
|
158
|
+
# def foo(bar, baz, *args, &blk); end
|
159
|
+
# method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:rest, :args], [:block, :blk]]
|
160
|
+
# ```
|
161
|
+
def parameters: () -> ::Array[untyped]
|
162
|
+
|
163
|
+
# Returns the bound receiver of the method object.
|
164
|
+
#
|
165
|
+
# ```ruby
|
166
|
+
# (1..3).method(:map).receiver # => 1..3
|
167
|
+
# ```
|
168
|
+
def receiver: () -> untyped
|
169
|
+
|
170
|
+
# Returns the Ruby source filename and line number containing this method
|
171
|
+
# or nil if this method was not defined in Ruby (i.e. native).
|
172
|
+
def source_location: () -> untyped
|
173
|
+
|
174
|
+
# Returns a [Method](Method.downloaded.ruby_doc) of superclass which would
|
175
|
+
# be called when super is used or nil if there is no method on superclass.
|
176
|
+
def super_method: () -> Method?
|
177
|
+
|
178
|
+
# Dissociates *meth* from its current receiver. The resulting
|
179
|
+
# `UnboundMethod` can subsequently be bound to a new object of the same
|
180
|
+
# class (see `UnboundMethod` ).
|
181
|
+
def unbind: () -> untyped
|
182
|
+
end
|