steep 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/exe/rbs +1 -1
- data/lib/steep/annotation_parser.rb +4 -4
- data/lib/steep/ast/buffer.rb +11 -7
- data/lib/steep/ast/builtin.rb +8 -0
- data/lib/steep/ast/types/factory.rb +55 -55
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/langserver.rb +6 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/project/completion_provider.rb +5 -11
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +42 -46
- data/lib/steep/project/hover_content.rb +11 -5
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +10 -4
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +8 -8
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +987 -711
- data/lib/steep/type_inference/constant_env.rb +1 -1
- data/lib/steep/type_inference/context.rb +7 -3
- data/lib/steep/type_inference/context_array.rb +111 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
- data/lib/steep/type_inference/logic.rb +130 -0
- data/lib/steep/type_inference/type_env.rb +5 -69
- data/lib/steep/typing.rb +79 -22
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +6 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/and/Steepfile +1 -0
- data/smoke/array/Steepfile +1 -0
- data/smoke/array/b.rb +0 -2
- data/smoke/block/Steepfile +1 -0
- data/smoke/case/Steepfile +1 -0
- data/smoke/class/Steepfile +1 -0
- data/smoke/const/Steepfile +1 -0
- data/smoke/dstr/Steepfile +1 -0
- data/smoke/ensure/Steepfile +1 -0
- data/smoke/enumerator/Steepfile +1 -0
- data/smoke/extension/Steepfile +1 -0
- data/smoke/extension/c.rb +1 -0
- data/smoke/hash/Steepfile +1 -0
- data/smoke/hello/Steepfile +1 -0
- data/smoke/if/Steepfile +1 -0
- data/smoke/if/a.rb +1 -1
- data/smoke/implements/Steepfile +1 -0
- data/smoke/initialize/Steepfile +1 -0
- data/smoke/integer/Steepfile +1 -0
- data/smoke/interface/Steepfile +1 -0
- data/smoke/kwbegin/Steepfile +1 -0
- data/smoke/lambda/Steepfile +1 -0
- data/smoke/literal/Steepfile +1 -0
- data/smoke/map/Steepfile +1 -0
- data/smoke/method/Steepfile +1 -0
- data/smoke/module/Steepfile +1 -0
- data/smoke/regexp/Steepfile +1 -0
- data/smoke/regression/Steepfile +1 -0
- data/smoke/rescue/Steepfile +1 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +1 -0
- data/smoke/skip/Steepfile +1 -0
- data/smoke/stdout/Steepfile +1 -0
- data/smoke/super/Steepfile +1 -0
- data/smoke/type_case/Steepfile +1 -0
- data/smoke/yield/Steepfile +1 -0
- data/steep.gemspec +1 -1
- data/vendor/ruby-signature/.gitignore +2 -2
- data/vendor/ruby-signature/README.md +2 -2
- data/vendor/ruby-signature/Rakefile +2 -2
- data/vendor/ruby-signature/bin/annotate-with-rdoc +14 -13
- data/vendor/ruby-signature/bin/console +1 -1
- data/vendor/ruby-signature/bin/sort +7 -6
- data/vendor/ruby-signature/bin/test_runner.rb +0 -1
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +1 -1
- data/vendor/ruby-signature/docs/sigs.md +3 -3
- data/vendor/ruby-signature/docs/stdlib.md +1 -1
- data/vendor/ruby-signature/docs/syntax.md +9 -9
- data/vendor/ruby-signature/exe/rbs +5 -1
- data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +27 -0
- data/vendor/ruby-signature/lib/rbs/ast/comment.rb +27 -0
- data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +395 -0
- data/vendor/ruby-signature/lib/rbs/ast/members.rb +362 -0
- data/vendor/ruby-signature/lib/rbs/buffer.rb +50 -0
- data/vendor/ruby-signature/lib/rbs/builtin_names.rb +55 -0
- data/vendor/ruby-signature/lib/rbs/cli.rb +558 -0
- data/vendor/ruby-signature/lib/rbs/constant.rb +26 -0
- data/vendor/ruby-signature/lib/rbs/constant_table.rb +150 -0
- data/vendor/ruby-signature/lib/rbs/definition.rb +170 -0
- data/vendor/ruby-signature/lib/rbs/definition_builder.rb +919 -0
- data/vendor/ruby-signature/lib/rbs/environment.rb +281 -0
- data/vendor/ruby-signature/lib/rbs/environment_loader.rb +136 -0
- data/vendor/ruby-signature/lib/rbs/environment_walker.rb +124 -0
- data/vendor/ruby-signature/lib/rbs/errors.rb +187 -0
- data/vendor/ruby-signature/lib/rbs/location.rb +102 -0
- data/vendor/ruby-signature/lib/rbs/method_type.rb +123 -0
- data/vendor/ruby-signature/lib/rbs/namespace.rb +91 -0
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.rb +21 -23
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.y +18 -18
- data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +553 -0
- data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +587 -0
- data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +381 -0
- data/vendor/ruby-signature/lib/rbs/substitution.rb +46 -0
- data/vendor/ruby-signature/lib/rbs/test/errors.rb +61 -0
- data/vendor/ruby-signature/lib/rbs/test/hook.rb +294 -0
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/test/setup.rb +7 -7
- data/vendor/ruby-signature/lib/rbs/test/spy.rb +325 -0
- data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +183 -0
- data/vendor/ruby-signature/lib/rbs/test/type_check.rb +254 -0
- data/vendor/ruby-signature/lib/rbs/test.rb +26 -0
- data/vendor/ruby-signature/lib/rbs/type_name.rb +70 -0
- data/vendor/ruby-signature/lib/rbs/types.rb +936 -0
- data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +138 -0
- data/vendor/ruby-signature/lib/rbs/vendorer.rb +47 -0
- data/vendor/ruby-signature/lib/rbs/version.rb +3 -0
- data/vendor/ruby-signature/lib/rbs/writer.rb +269 -0
- data/vendor/ruby-signature/lib/rbs.rb +64 -0
- data/vendor/ruby-signature/lib/ruby/signature.rb +4 -61
- data/vendor/ruby-signature/{ruby-signature.gemspec → rbs.gemspec} +4 -4
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +58 -1
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +69 -13
- data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +372 -0
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +9 -0
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +1 -7
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +2 -1
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +3 -2
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +902 -302
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +190 -68
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +3 -6
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +6 -4
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +146 -120
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +310 -7
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +11 -8
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +959 -103
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +3 -0
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +981 -108
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +215 -41
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +47 -0
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +9 -2
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +282 -11
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +11 -13
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +25 -29
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +1 -1
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +875 -567
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +243 -44
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +103 -109
- data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +62 -0
- data/vendor/ruby-signature/stdlib/csv/csv.rbs +773 -0
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +375 -1
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -4
- data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +247 -0
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +1088 -16
- data/vendor/ruby-signature/stdlib/set/set.rbs +251 -27
- metadata +49 -44
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -555
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -327
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
@@ -1,135 +1,161 @@
|
|
1
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
|
-
#
|
4
|
-
#
|
5
|
-
#
|
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
|
+
#
|
6
5
|
# 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
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
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
|
-
#
|
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
|
+
#
|
33
27
|
# There are two methods of doing this, your object can define either
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# deserialize almost any class loaded into the Ruby
|
41
|
-
# this can lead to remote code execution if the
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
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
|
-
#
|
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
|
+
#
|
67
57
|
# Example:
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
# the
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
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
|
-
#
|
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
|
+
#
|
102
88
|
# Example:
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
# string you can have \_dump return a
|
124
|
-
# [Marshal](Marshal) string which is Marshal.loaded in
|
125
|
-
# \_load for complex objects.
|
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
|
+
#
|
126
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
|
+
#
|
127
139
|
def self.dump: (Object arg0, ?IO arg1, ?Integer arg2) -> Object
|
128
140
|
| (Object arg0, ?Integer arg1) -> Object
|
129
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
|
+
#
|
130
150
|
def self.load: (String arg0, ?Proc arg1) -> Object
|
151
|
+
|
152
|
+
alias self.restore self.load
|
131
153
|
end
|
132
154
|
|
155
|
+
# major version
|
156
|
+
#
|
133
157
|
Marshal::MAJOR_VERSION: Integer
|
134
158
|
|
159
|
+
# minor version
|
160
|
+
#
|
135
161
|
Marshal::MINOR_VERSION: Integer
|
@@ -1,66 +1,369 @@
|
|
1
|
-
# The
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
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
|
+
#
|
6
5
|
# Domains and codomains are given only for real (not complex) numbers.
|
6
|
+
#
|
7
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
|
+
#
|
8
16
|
def self.acos: (Integer | Float | Rational | BigDecimal x) -> Float
|
9
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
|
+
#
|
10
26
|
def self.acosh: (Integer | Float | Rational | BigDecimal x) -> Float
|
11
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
|
+
#
|
12
36
|
def self.asin: (Integer | Float | Rational | BigDecimal x) -> Float
|
13
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
|
+
#
|
14
46
|
def self.asinh: (Integer | Float | Rational | BigDecimal x) -> Float
|
15
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
|
+
#
|
16
56
|
def self.atan: (Integer | Float | Rational | BigDecimal x) -> Float
|
17
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
|
+
#
|
18
81
|
def self.atan2: (Integer | Float | Rational | BigDecimal y, Integer | Float | Rational | BigDecimal x) -> Float
|
19
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
|
+
#
|
20
91
|
def self.atanh: (Integer | Float | Rational | BigDecimal x) -> Float
|
21
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
|
+
#
|
22
122
|
def self.cbrt: (Integer | Float | Rational | BigDecimal x) -> Float
|
23
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
|
+
#
|
24
133
|
def self.cos: (Integer | Float | Rational | BigDecimal x) -> Float
|
25
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
|
+
#
|
26
143
|
def self.cosh: (Integer | Float | Rational | BigDecimal x) -> Float
|
27
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
|
+
#
|
28
153
|
def self.erf: (Integer | Float | Rational | BigDecimal x) -> Float
|
29
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
|
+
#
|
30
163
|
def self.erfc: (Integer | Float | Rational | BigDecimal x) -> Float
|
31
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
|
+
#
|
32
175
|
def self.exp: (Integer | Float | Rational | BigDecimal x) -> Float
|
33
176
|
|
34
|
-
|
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 ]
|
35
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
|
+
#
|
36
219
|
def self.gamma: (Integer | Float | Rational | BigDecimal x) -> Float
|
37
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
|
+
#
|
38
226
|
def self.hypot: (Integer | Float | Rational | BigDecimal x, Integer | Float | Rational | BigDecimal y) -> Float
|
39
227
|
|
228
|
+
# Returns the value of `fraction`*(2**`exponent`).
|
229
|
+
#
|
230
|
+
# fraction, exponent = Math.frexp(1234)
|
231
|
+
# Math.ldexp(fraction, exponent) #=> 1234.0
|
232
|
+
#
|
40
233
|
def self.ldexp: (Integer | Float | Rational | BigDecimal fraction, Integer | Float | Rational | BigDecimal exponent) -> Float
|
41
234
|
|
42
|
-
|
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 ]
|
43
245
|
|
44
246
|
def self.log: (Integer | Float | Rational | BigDecimal x, ?Integer | Float | Rational | BigDecimal base) -> Float
|
45
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
|
+
#
|
46
258
|
def self.log10: (Integer | Float | Rational | BigDecimal x) -> Float
|
47
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
|
+
#
|
48
271
|
def self.log2: (Integer | Float | Rational | BigDecimal x) -> Float
|
49
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
|
+
#
|
50
282
|
def self.sin: (Integer | Float | Rational | BigDecimal x) -> Float
|
51
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
|
+
#
|
52
292
|
def self.sinh: (Integer | Float | Rational | BigDecimal x) -> Float
|
53
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
|
+
#
|
54
322
|
def self.sqrt: (Integer | Float | Rational | BigDecimal x) -> Float
|
55
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
|
+
#
|
56
332
|
def self.tan: (Integer | Float | Rational | BigDecimal x) -> Float
|
57
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
|
+
#
|
58
342
|
def self.tanh: (Integer | Float | Rational | BigDecimal x) -> Float
|
59
343
|
end
|
60
344
|
|
345
|
+
# Definition of the mathematical constant E for Euler's number (e) as a Float
|
346
|
+
# number.
|
347
|
+
#
|
348
|
+
#
|
61
349
|
Math::E: Float
|
62
350
|
|
351
|
+
# Definition of the mathematical constant PI as a Float number.
|
352
|
+
#
|
353
|
+
#
|
63
354
|
Math::PI: Float
|
64
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
|
+
#
|
65
368
|
class Math::DomainError < StandardError
|
66
369
|
end
|