steep 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/exe/rbs +1 -1
  4. data/lib/steep/annotation_parser.rb +4 -4
  5. data/lib/steep/ast/buffer.rb +11 -7
  6. data/lib/steep/ast/builtin.rb +8 -0
  7. data/lib/steep/ast/types/factory.rb +55 -55
  8. data/lib/steep/drivers/check.rb +20 -4
  9. data/lib/steep/drivers/langserver.rb +6 -1
  10. data/lib/steep/drivers/vendor.rb +2 -2
  11. data/lib/steep/project/completion_provider.rb +5 -11
  12. data/lib/steep/project/dsl.rb +14 -0
  13. data/lib/steep/project/file.rb +42 -46
  14. data/lib/steep/project/hover_content.rb +11 -5
  15. data/lib/steep/project/options.rb +25 -3
  16. data/lib/steep/project/target.rb +10 -4
  17. data/lib/steep/signature/errors.rb +1 -1
  18. data/lib/steep/signature/validator.rb +8 -8
  19. data/lib/steep/source.rb +1 -1
  20. data/lib/steep/type_construction.rb +987 -711
  21. data/lib/steep/type_inference/constant_env.rb +1 -1
  22. data/lib/steep/type_inference/context.rb +7 -3
  23. data/lib/steep/type_inference/context_array.rb +111 -0
  24. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  25. data/lib/steep/type_inference/logic.rb +130 -0
  26. data/lib/steep/type_inference/type_env.rb +5 -69
  27. data/lib/steep/typing.rb +79 -22
  28. data/lib/steep/version.rb +1 -1
  29. data/lib/steep.rb +6 -1
  30. data/smoke/alias/Steepfile +1 -0
  31. data/smoke/and/Steepfile +1 -0
  32. data/smoke/array/Steepfile +1 -0
  33. data/smoke/array/b.rb +0 -2
  34. data/smoke/block/Steepfile +1 -0
  35. data/smoke/case/Steepfile +1 -0
  36. data/smoke/class/Steepfile +1 -0
  37. data/smoke/const/Steepfile +1 -0
  38. data/smoke/dstr/Steepfile +1 -0
  39. data/smoke/ensure/Steepfile +1 -0
  40. data/smoke/enumerator/Steepfile +1 -0
  41. data/smoke/extension/Steepfile +1 -0
  42. data/smoke/extension/c.rb +1 -0
  43. data/smoke/hash/Steepfile +1 -0
  44. data/smoke/hello/Steepfile +1 -0
  45. data/smoke/if/Steepfile +1 -0
  46. data/smoke/if/a.rb +1 -1
  47. data/smoke/implements/Steepfile +1 -0
  48. data/smoke/initialize/Steepfile +1 -0
  49. data/smoke/integer/Steepfile +1 -0
  50. data/smoke/interface/Steepfile +1 -0
  51. data/smoke/kwbegin/Steepfile +1 -0
  52. data/smoke/lambda/Steepfile +1 -0
  53. data/smoke/literal/Steepfile +1 -0
  54. data/smoke/map/Steepfile +1 -0
  55. data/smoke/method/Steepfile +1 -0
  56. data/smoke/module/Steepfile +1 -0
  57. data/smoke/regexp/Steepfile +1 -0
  58. data/smoke/regression/Steepfile +1 -0
  59. data/smoke/rescue/Steepfile +1 -0
  60. data/smoke/rescue/a.rb +1 -1
  61. data/smoke/self/Steepfile +1 -0
  62. data/smoke/skip/Steepfile +1 -0
  63. data/smoke/stdout/Steepfile +1 -0
  64. data/smoke/super/Steepfile +1 -0
  65. data/smoke/type_case/Steepfile +1 -0
  66. data/smoke/yield/Steepfile +1 -0
  67. data/steep.gemspec +1 -1
  68. data/vendor/ruby-signature/.gitignore +2 -2
  69. data/vendor/ruby-signature/README.md +2 -2
  70. data/vendor/ruby-signature/Rakefile +2 -2
  71. data/vendor/ruby-signature/bin/annotate-with-rdoc +14 -13
  72. data/vendor/ruby-signature/bin/console +1 -1
  73. data/vendor/ruby-signature/bin/sort +7 -6
  74. data/vendor/ruby-signature/bin/test_runner.rb +0 -1
  75. data/vendor/ruby-signature/docs/CONTRIBUTING.md +1 -1
  76. data/vendor/ruby-signature/docs/sigs.md +3 -3
  77. data/vendor/ruby-signature/docs/stdlib.md +1 -1
  78. data/vendor/ruby-signature/docs/syntax.md +9 -9
  79. data/vendor/ruby-signature/exe/rbs +5 -1
  80. data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +27 -0
  81. data/vendor/ruby-signature/lib/rbs/ast/comment.rb +27 -0
  82. data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +395 -0
  83. data/vendor/ruby-signature/lib/rbs/ast/members.rb +362 -0
  84. data/vendor/ruby-signature/lib/rbs/buffer.rb +50 -0
  85. data/vendor/ruby-signature/lib/rbs/builtin_names.rb +55 -0
  86. data/vendor/ruby-signature/lib/rbs/cli.rb +558 -0
  87. data/vendor/ruby-signature/lib/rbs/constant.rb +26 -0
  88. data/vendor/ruby-signature/lib/rbs/constant_table.rb +150 -0
  89. data/vendor/ruby-signature/lib/rbs/definition.rb +170 -0
  90. data/vendor/ruby-signature/lib/rbs/definition_builder.rb +919 -0
  91. data/vendor/ruby-signature/lib/rbs/environment.rb +281 -0
  92. data/vendor/ruby-signature/lib/rbs/environment_loader.rb +136 -0
  93. data/vendor/ruby-signature/lib/rbs/environment_walker.rb +124 -0
  94. data/vendor/ruby-signature/lib/rbs/errors.rb +187 -0
  95. data/vendor/ruby-signature/lib/rbs/location.rb +102 -0
  96. data/vendor/ruby-signature/lib/rbs/method_type.rb +123 -0
  97. data/vendor/ruby-signature/lib/rbs/namespace.rb +91 -0
  98. data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.rb +21 -23
  99. data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.y +18 -18
  100. data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +553 -0
  101. data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +587 -0
  102. data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +381 -0
  103. data/vendor/ruby-signature/lib/rbs/substitution.rb +46 -0
  104. data/vendor/ruby-signature/lib/rbs/test/errors.rb +61 -0
  105. data/vendor/ruby-signature/lib/rbs/test/hook.rb +294 -0
  106. data/vendor/ruby-signature/lib/{ruby/signature → rbs}/test/setup.rb +7 -7
  107. data/vendor/ruby-signature/lib/rbs/test/spy.rb +325 -0
  108. data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +183 -0
  109. data/vendor/ruby-signature/lib/rbs/test/type_check.rb +254 -0
  110. data/vendor/ruby-signature/lib/rbs/test.rb +26 -0
  111. data/vendor/ruby-signature/lib/rbs/type_name.rb +70 -0
  112. data/vendor/ruby-signature/lib/rbs/types.rb +936 -0
  113. data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +138 -0
  114. data/vendor/ruby-signature/lib/rbs/vendorer.rb +47 -0
  115. data/vendor/ruby-signature/lib/rbs/version.rb +3 -0
  116. data/vendor/ruby-signature/lib/rbs/writer.rb +269 -0
  117. data/vendor/ruby-signature/lib/rbs.rb +64 -0
  118. data/vendor/ruby-signature/lib/ruby/signature.rb +4 -61
  119. data/vendor/ruby-signature/{ruby-signature.gemspec → rbs.gemspec} +4 -4
  120. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +58 -1
  121. data/vendor/ruby-signature/stdlib/base64/base64.rbs +69 -13
  122. data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +372 -0
  123. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +9 -0
  124. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +1 -7
  125. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +2 -1
  126. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +3 -2
  127. data/vendor/ruby-signature/stdlib/builtin/file.rbs +902 -302
  128. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +190 -68
  129. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +3 -6
  130. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +6 -4
  131. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +146 -120
  132. data/vendor/ruby-signature/stdlib/builtin/math.rbs +310 -7
  133. data/vendor/ruby-signature/stdlib/builtin/method.rbs +11 -8
  134. data/vendor/ruby-signature/stdlib/builtin/module.rbs +959 -103
  135. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +3 -0
  136. data/vendor/ruby-signature/stdlib/builtin/process.rbs +981 -108
  137. data/vendor/ruby-signature/stdlib/builtin/random.rbs +215 -41
  138. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +47 -0
  139. data/vendor/ruby-signature/stdlib/builtin/string.rbs +9 -2
  140. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +282 -11
  141. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +11 -13
  142. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +25 -29
  143. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +1 -1
  144. data/vendor/ruby-signature/stdlib/builtin/time.rbs +875 -567
  145. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +243 -44
  146. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +103 -109
  147. data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +62 -0
  148. data/vendor/ruby-signature/stdlib/csv/csv.rbs +773 -0
  149. data/vendor/ruby-signature/stdlib/erb/erb.rbs +375 -1
  150. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -4
  151. data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +247 -0
  152. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +1088 -16
  153. data/vendor/ruby-signature/stdlib/set/set.rbs +251 -27
  154. metadata +49 -44
  155. data/exe/ruby-signature +0 -3
  156. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  157. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  158. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  159. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  160. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  161. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  162. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  163. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -555
  164. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  165. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  166. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  167. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  168. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  169. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  170. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  171. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  172. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  173. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  174. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  175. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
  176. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  177. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  178. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  179. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  180. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  181. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -327
  182. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  183. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  184. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  185. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  186. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  187. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  188. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  189. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  190. 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
- # This data may subsequently be read and the original objects
4
- # reconstituted.
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
- # with the same major version number and an equal or lower minor version
9
- # number. If Rubys 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
- #
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
- # 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
- #
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
- # ```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
- #
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
- # ```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.
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 [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
- #
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
- def self.frexp: (Integer | Float | Rational | BigDecimal x) -> [ Integer | Float | Rational | BigDecimal, Integer | Float | Rational | BigDecimal ]
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
- def self.lgamma: (Integer | Float | Rational | BigDecimal x) -> (Integer | Float)
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