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,91 @@
|
|
1
|
+
class TracePoint < Object
|
2
|
+
def initialize: (*Symbol events) { (TracePoint tp) -> void } -> void
|
3
|
+
|
4
|
+
# Returns internal information of
|
5
|
+
# [TracePoint](TracePoint.downloaded.ruby_doc).
|
6
|
+
#
|
7
|
+
# The contents of the returned value are implementation specific. It may
|
8
|
+
# be changed in future.
|
9
|
+
#
|
10
|
+
# This method is only for debugging
|
11
|
+
# [TracePoint](TracePoint.downloaded.ruby_doc) itself.
|
12
|
+
def self.stat: () -> untyped
|
13
|
+
|
14
|
+
def self.trace: (*Symbol events) { (TracePoint tp) -> void } -> TracePoint
|
15
|
+
|
16
|
+
# Return the generated binding object from event
|
17
|
+
def binding: () -> Binding
|
18
|
+
|
19
|
+
# Return the called name of the method being called
|
20
|
+
def callee_id: () -> Symbol
|
21
|
+
|
22
|
+
def `defined_class`: () -> Module
|
23
|
+
|
24
|
+
# Deactivates the trace
|
25
|
+
#
|
26
|
+
# Return true if trace was enabled. Return false if trace was disabled.
|
27
|
+
#
|
28
|
+
# ```ruby
|
29
|
+
# trace.enabled? #=> true
|
30
|
+
# trace.disable #=> true (previous status)
|
31
|
+
# trace.enabled? #=> false
|
32
|
+
# trace.disable #=> false
|
33
|
+
# ```
|
34
|
+
#
|
35
|
+
# If a block is given, the trace will only be disable within the scope of
|
36
|
+
# the block.
|
37
|
+
#
|
38
|
+
# ```ruby
|
39
|
+
# trace.enabled?
|
40
|
+
# #=> true
|
41
|
+
#
|
42
|
+
# trace.disable do
|
43
|
+
# trace.enabled?
|
44
|
+
# # only disabled for this block
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# trace.enabled?
|
48
|
+
# #=> true
|
49
|
+
# ```
|
50
|
+
#
|
51
|
+
# Note: You cannot access event hooks within the block.
|
52
|
+
#
|
53
|
+
# ```ruby
|
54
|
+
# trace.disable { p tp.lineno }
|
55
|
+
# #=> RuntimeError: access from outside
|
56
|
+
# ```
|
57
|
+
def disable: () -> bool
|
58
|
+
| () { () -> void } -> void
|
59
|
+
|
60
|
+
def enable: () -> bool
|
61
|
+
| () { () -> void } -> void
|
62
|
+
|
63
|
+
# The current status of the trace
|
64
|
+
def enabled?: () -> bool
|
65
|
+
|
66
|
+
def inspect: () -> String
|
67
|
+
|
68
|
+
# Line number of the event
|
69
|
+
def lineno: () -> Integer
|
70
|
+
|
71
|
+
# Return the name at the definition of the method being called
|
72
|
+
def method_id: () -> Symbol
|
73
|
+
|
74
|
+
# Path of the file being run
|
75
|
+
def path: () -> String
|
76
|
+
|
77
|
+
# Value from exception raised on the `:raise` event
|
78
|
+
def raised_exception: () -> untyped
|
79
|
+
|
80
|
+
# Return value from `:return`, `c_return`, and `b_return` event
|
81
|
+
def return_value: () -> untyped
|
82
|
+
|
83
|
+
# Return the trace object during event
|
84
|
+
#
|
85
|
+
# Same as [\#binding](TracePoint.downloaded.ruby_doc#method-i-binding):
|
86
|
+
#
|
87
|
+
# ```ruby
|
88
|
+
# trace.binding.eval('self')
|
89
|
+
# ```
|
90
|
+
def `self`: () -> Binding
|
91
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# The global value `true` is the only instance of class TrueClass and represents
|
2
|
+
# a logically true value in boolean expressions. The class provides operators
|
3
|
+
# allowing `true` to be used in logical expressions.
|
4
|
+
#
|
5
|
+
class TrueClass
|
6
|
+
public
|
7
|
+
|
8
|
+
def !: () -> bool
|
9
|
+
|
10
|
+
# And---Returns `false` if *obj* is `nil` or `false`, `true` otherwise.
|
11
|
+
#
|
12
|
+
def &: (nil) -> false
|
13
|
+
| (false) -> false
|
14
|
+
| (untyped obj) -> bool
|
15
|
+
|
16
|
+
# Case Equality -- For class Object, effectively the same as calling `#==`, but
|
17
|
+
# typically overridden by descendants to provide meaningful semantics in `case`
|
18
|
+
# statements.
|
19
|
+
#
|
20
|
+
def ===: (true) -> true
|
21
|
+
| (untyped obj) -> bool
|
22
|
+
|
23
|
+
# Exclusive Or---Returns `true` if *obj* is `nil` or `false`, `false` otherwise.
|
24
|
+
#
|
25
|
+
def ^: (nil) -> true
|
26
|
+
| (false) -> true
|
27
|
+
| (untyped obj) -> bool
|
28
|
+
|
29
|
+
alias inspect to_s
|
30
|
+
|
31
|
+
# The string representation of `true` is "true".
|
32
|
+
#
|
33
|
+
def to_s: () -> "true"
|
34
|
+
|
35
|
+
# Or---Returns `true`. As *obj* is an argument to a method call, it is always
|
36
|
+
# evaluated; there is no short-circuit evaluation in this case.
|
37
|
+
#
|
38
|
+
# true | puts("or")
|
39
|
+
# true || puts("logical or")
|
40
|
+
#
|
41
|
+
# *produces:*
|
42
|
+
#
|
43
|
+
# or
|
44
|
+
#
|
45
|
+
def |: (bool obj) -> bool
|
46
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# Ruby supports two forms of objectified methods.
|
2
|
+
# [Class](https://ruby-doc.org/core-2.6.3/Class.html) `Method` is used to
|
3
|
+
# represent methods that are associated with a particular object: these
|
4
|
+
# method objects are bound to that object. Bound method objects for an
|
5
|
+
# object can be created using `Object#method` .
|
6
|
+
#
|
7
|
+
# Ruby also supports unbound methods; methods objects that are not
|
8
|
+
# associated with a particular object. These can be created either by
|
9
|
+
# calling `Module#instance_method` or by calling `unbind` on a bound
|
10
|
+
# method object. The result of both of these is an `UnboundMethod` object.
|
11
|
+
#
|
12
|
+
# Unbound methods can only be called after they are bound to an object.
|
13
|
+
# That object must be a kind\_of? the method's original class.
|
14
|
+
#
|
15
|
+
# ```ruby
|
16
|
+
# class Square
|
17
|
+
# def area
|
18
|
+
# @side * @side
|
19
|
+
# end
|
20
|
+
# def initialize(side)
|
21
|
+
# @side = side
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# area_un = Square.instance_method(:area)
|
26
|
+
#
|
27
|
+
# s = Square.new(12)
|
28
|
+
# area = area_un.bind(s)
|
29
|
+
# area.call #=> 144
|
30
|
+
# ```
|
31
|
+
#
|
32
|
+
# Unbound methods are a reference to the method at the time it was
|
33
|
+
# objectified: subsequent changes to the underlying class will not affect
|
34
|
+
# the unbound method.
|
35
|
+
#
|
36
|
+
# ```ruby
|
37
|
+
# class Test
|
38
|
+
# def test
|
39
|
+
# :original
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
# um = Test.instance_method(:test)
|
43
|
+
# class Test
|
44
|
+
# def test
|
45
|
+
# :modified
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# t = Test.new
|
49
|
+
# t.test #=> :modified
|
50
|
+
# um.bind(t).call #=> :original
|
51
|
+
# ```
|
52
|
+
class UnboundMethod
|
53
|
+
# Returns an indication of the number of arguments accepted by a method.
|
54
|
+
# Returns a nonnegative integer for methods that take a fixed number of
|
55
|
+
# arguments. For Ruby methods that take a variable number of arguments,
|
56
|
+
# returns -n-1, where n is the number of required arguments. Keyword
|
57
|
+
# arguments will be considered as a single additional argument, that
|
58
|
+
# argument being mandatory if any keyword argument is mandatory. For
|
59
|
+
# methods written in C, returns -1 if the call takes a variable number of
|
60
|
+
# arguments.
|
61
|
+
#
|
62
|
+
# class C
|
63
|
+
# def one; end
|
64
|
+
# def two(a); end
|
65
|
+
# def three(*a); end
|
66
|
+
# def four(a, b); end
|
67
|
+
# def five(a, b, *c); end
|
68
|
+
# def six(a, b, *c, &d); end
|
69
|
+
# def seven(a, b, x:0); end
|
70
|
+
# def eight(x:, y:); end
|
71
|
+
# def nine(x:, y:, **z); end
|
72
|
+
# def ten(*a, x:, y:); end
|
73
|
+
# end
|
74
|
+
# c = C.new
|
75
|
+
# c.method(:one).arity #=> 0
|
76
|
+
# c.method(:two).arity #=> 1
|
77
|
+
# c.method(:three).arity #=> -1
|
78
|
+
# c.method(:four).arity #=> 2
|
79
|
+
# c.method(:five).arity #=> -3
|
80
|
+
# c.method(:six).arity #=> -3
|
81
|
+
# c.method(:seven).arity #=> -3
|
82
|
+
# c.method(:eight).arity #=> 1
|
83
|
+
# c.method(:nine).arity #=> 1
|
84
|
+
# c.method(:ten).arity #=> -2
|
85
|
+
#
|
86
|
+
# "cat".method(:size).arity #=> 0
|
87
|
+
# "cat".method(:replace).arity #=> 1
|
88
|
+
# "cat".method(:squeeze).arity #=> -1
|
89
|
+
# "cat".method(:count).arity #=> -1
|
90
|
+
def arity: () -> Integer
|
91
|
+
|
92
|
+
# Bind *umeth* to *obj* . If `Klass` was the class from which *umeth* was
|
93
|
+
# obtained, `obj.kind_of?(Klass)` must be true.
|
94
|
+
#
|
95
|
+
# ```ruby
|
96
|
+
# class A
|
97
|
+
# def test
|
98
|
+
# puts "In test, class = #{self.class}"
|
99
|
+
# end
|
100
|
+
# end
|
101
|
+
# class B < A
|
102
|
+
# end
|
103
|
+
# class C < B
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
# um = B.instance_method(:test)
|
107
|
+
# bm = um.bind(C.new)
|
108
|
+
# bm.call
|
109
|
+
# bm = um.bind(B.new)
|
110
|
+
# bm.call
|
111
|
+
# bm = um.bind(A.new)
|
112
|
+
# bm.call
|
113
|
+
# ```
|
114
|
+
#
|
115
|
+
# *produces:*
|
116
|
+
#
|
117
|
+
# In test, class = C
|
118
|
+
# In test, class = B
|
119
|
+
# prog.rb:16:in `bind': bind argument must be an instance of B (TypeError)
|
120
|
+
# from prog.rb:16
|
121
|
+
def bind: (untyped obj) -> Method
|
122
|
+
|
123
|
+
# Returns the name of the method.
|
124
|
+
def name: () -> Symbol
|
125
|
+
|
126
|
+
# Returns the class or module that defines the method. See also receiver.
|
127
|
+
#
|
128
|
+
# ```ruby
|
129
|
+
# (1..3).method(:map).owner #=> Enumerable
|
130
|
+
# ```
|
131
|
+
def owner: () -> Module
|
132
|
+
|
133
|
+
# Returns the parameter information of this method.
|
134
|
+
#
|
135
|
+
# ```ruby
|
136
|
+
# def foo(bar); end
|
137
|
+
# method(:foo).parameters #=> [[:req, :bar]]
|
138
|
+
#
|
139
|
+
# def foo(bar, baz, bat, &blk); end
|
140
|
+
# method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:req, :bat], [:block, :blk]]
|
141
|
+
#
|
142
|
+
# def foo(bar, *args); end
|
143
|
+
# method(:foo).parameters #=> [[:req, :bar], [:rest, :args]]
|
144
|
+
#
|
145
|
+
# def foo(bar, baz, *args, &blk); end
|
146
|
+
# method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:rest, :args], [:block, :blk]]
|
147
|
+
# ```
|
148
|
+
def parameters: () -> ::Array[[ Symbol, Symbol ]]
|
149
|
+
| () -> ::Array[[ Symbol ]]
|
150
|
+
|
151
|
+
# Returns the Ruby source filename and line number containing this method
|
152
|
+
# or nil if this method was not defined in Ruby (i.e. native).
|
153
|
+
def source_location: () -> [ String, Integer ]?
|
154
|
+
|
155
|
+
# Returns a [Method](https://ruby-doc.org/core-2.6.3/Method.html) of
|
156
|
+
# superclass which would be called when super is used or nil if there is
|
157
|
+
# no method on superclass.
|
158
|
+
def super_method: () -> UnboundMethod?
|
159
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# The [Warning](Warning) module contains a single
|
2
|
+
# method named [warn](Warning#method-i-warn), and the
|
3
|
+
# module extends itself, making `Warning.warn` available.
|
4
|
+
# [\#warn](Warning#method-i-warn) is called for all
|
5
|
+
# warnings issued by Ruby. By default, warnings are printed to $stderr.
|
6
|
+
#
|
7
|
+
# By overriding [\#warn](Warning#method-i-warn), you
|
8
|
+
# can change how warnings are handled by Ruby, either filtering some
|
9
|
+
# warnings, and/or outputting warnings somewhere other than $stderr. When
|
10
|
+
# [\#warn](Warning#method-i-warn) is overridden, super
|
11
|
+
# can be called to get the default behavior of printing the warning to
|
12
|
+
# $stderr.
|
13
|
+
module Warning
|
14
|
+
# Writes warning message msg to $stderr, followed by a newline if the message does not end in a newline.
|
15
|
+
# This method is called by Ruby for all emitted warnings.
|
16
|
+
def warn: (String) -> nil
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class ERB
|
2
|
+
def self.version: () -> String
|
3
|
+
|
4
|
+
def initialize: (String, ?trim_mode: Integer | String | NilClass, ?eoutvar: String) -> untyped
|
5
|
+
def src: () -> String
|
6
|
+
def encoding: () -> Encoding
|
7
|
+
def filename: () -> (String | NilClass)
|
8
|
+
def filename=: (String | NilClass) -> untyped
|
9
|
+
def lineno: () -> Integer
|
10
|
+
def lineno=: (Integer) -> untyped
|
11
|
+
def location=: (Array[String | Integer]) -> untyped
|
12
|
+
def run: (?Binding) -> untyped
|
13
|
+
def result: (?Binding) -> String
|
14
|
+
def result_with_hash: (Hash[untyped, untyped]) -> String
|
15
|
+
def def_method: (Module, String, ?String) -> untyped
|
16
|
+
def def_module: (?String) -> Module
|
17
|
+
def def_class: (?Class, ?String) -> Class
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# The `Find` module supports the top-down traversal of a set of file paths.
|
2
|
+
#
|
3
|
+
# For example, to total the size of all files under your home directory,
|
4
|
+
# ignoring anything in a "dot" directory (e.g. $HOME/.ssh):
|
5
|
+
#
|
6
|
+
# require 'find'
|
7
|
+
#
|
8
|
+
# total_size = 0
|
9
|
+
#
|
10
|
+
# Find.find(ENV["HOME"]) do |path|
|
11
|
+
# if FileTest.directory?(path)
|
12
|
+
# if File.basename(path).start_with?('.')
|
13
|
+
# Find.prune # Don't look any further into this directory.
|
14
|
+
# else
|
15
|
+
# next
|
16
|
+
# end
|
17
|
+
# else
|
18
|
+
# total_size += FileTest.size(path)
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
module Find
|
23
|
+
# Calls the associated block with the name of every file and directory listed as
|
24
|
+
# arguments, then recursively on their subdirectories, and so on.
|
25
|
+
#
|
26
|
+
# Returns an enumerator if no block is given.
|
27
|
+
#
|
28
|
+
# See the `Find` module documentation for an example.
|
29
|
+
#
|
30
|
+
def self?.find: (*String | _ToPath paths, ?ignore_error: bool) -> Enumerator[String, nil]
|
31
|
+
| (*String | _ToPath paths, ?ignore_error: bool) { (String arg0) -> void } -> nil
|
32
|
+
|
33
|
+
# Skips the current file or directory, restarting the loop with the next entry.
|
34
|
+
# If the current file is a directory, that directory will not be recursively
|
35
|
+
# entered. Meaningful only within the block associated with Find::find.
|
36
|
+
#
|
37
|
+
# See the `Find` module documentation for an example.
|
38
|
+
#
|
39
|
+
def self?.prune: () -> void
|
40
|
+
end
|
41
|
+
|
42
|
+
interface _ToPath
|
43
|
+
def to_path: () -> String
|
44
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Pathname
|
2
|
+
def self.glob: (Pathname, ?Integer) -> Array[Pathname]
|
3
|
+
def `+`: (Pathname) -> Pathname
|
4
|
+
| (String) -> Pathname
|
5
|
+
def file?: -> bool
|
6
|
+
def relative_path_from: (Pathname) -> Pathname
|
7
|
+
def open: [X] (?String) { (IO) -> X } -> X
|
8
|
+
def join: (String) -> self
|
9
|
+
def realpath: -> self
|
10
|
+
def directory?: -> bool
|
11
|
+
def relative?: -> bool
|
12
|
+
def cleanpath: -> self
|
13
|
+
def read: -> String
|
14
|
+
def mkpath: -> void
|
15
|
+
def write: (String) -> void
|
16
|
+
def sub_ext: (String) -> self
|
17
|
+
end
|
18
|
+
|
19
|
+
extension Kernel (Pathname)
|
20
|
+
def Pathname: (String) -> Pathname
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
extension Integer (Prime)
|
2
|
+
# Iterates the given block over all prime numbers.
|
3
|
+
#
|
4
|
+
# See Prime#each for more details.
|
5
|
+
#
|
6
|
+
def self.each_prime: (Integer) { (Integer) -> void } -> void
|
7
|
+
|
8
|
+
# Re-composes a prime factorization and returns the product.
|
9
|
+
#
|
10
|
+
# See Prime#int_from_prime_division for more details.
|
11
|
+
#
|
12
|
+
def self.from_prime_division: (Array[[ String ]]) -> Integer
|
13
|
+
|
14
|
+
# Returns the factorization of `self`.
|
15
|
+
#
|
16
|
+
# See Prime#prime_division for more details.
|
17
|
+
#
|
18
|
+
def prime_division: (?Prime::PseudoPrimeGenerator) -> Array[[ Integer, Integer ]]
|
19
|
+
|
20
|
+
# Returns true if `self` is a prime number, else returns false.
|
21
|
+
#
|
22
|
+
def prime?: () -> bool
|
23
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# The set of all prime numbers.
|
2
|
+
#
|
3
|
+
# ## Example
|
4
|
+
#
|
5
|
+
# Prime.each(100) do |prime|
|
6
|
+
# p prime #=> 2, 3, 5, 7, 11, ...., 97
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# Prime is Enumerable:
|
10
|
+
#
|
11
|
+
# Prime.first 5 # => [2, 3, 5, 7, 11]
|
12
|
+
#
|
13
|
+
# ## Retrieving the instance
|
14
|
+
#
|
15
|
+
# For convenience, each instance method of `Prime`.instance can be accessed as a
|
16
|
+
# class method of `Prime`.
|
17
|
+
#
|
18
|
+
# e.g.
|
19
|
+
# Prime.instance.prime?(2) #=> true
|
20
|
+
# Prime.prime?(2) #=> true
|
21
|
+
#
|
22
|
+
# ## Generators
|
23
|
+
#
|
24
|
+
# A "generator" provides an implementation of enumerating pseudo-prime numbers
|
25
|
+
# and it remembers the position of enumeration and upper bound. Furthermore, it
|
26
|
+
# is an external iterator of prime enumeration which is compatible with an
|
27
|
+
# Enumerator.
|
28
|
+
#
|
29
|
+
# `Prime`::`PseudoPrimeGenerator` is the base class for generators. There are
|
30
|
+
# few implementations of generator.
|
31
|
+
#
|
32
|
+
# `Prime`::`EratosthenesGenerator`
|
33
|
+
# : Uses eratosthenes' sieve.
|
34
|
+
# `Prime`::`TrialDivisionGenerator`
|
35
|
+
# : Uses the trial division method.
|
36
|
+
# `Prime`::`Generator23`
|
37
|
+
# : Generates all positive integers which are not divisible by either 2 or 3.
|
38
|
+
# This sequence is very bad as a pseudo-prime sequence. But this is faster
|
39
|
+
# and uses much less memory than the other generators. So, it is suitable
|
40
|
+
# for factorizing an integer which is not large but has many prime factors.
|
41
|
+
# e.g. for Prime#prime? .
|
42
|
+
#
|
43
|
+
#
|
44
|
+
class Prime
|
45
|
+
# Iterates the given block over all prime numbers.
|
46
|
+
#
|
47
|
+
# ## Parameters
|
48
|
+
#
|
49
|
+
# `ubound`
|
50
|
+
# : Optional. An arbitrary positive number. The upper bound of enumeration.
|
51
|
+
# The method enumerates prime numbers infinitely if `ubound` is nil.
|
52
|
+
# `generator`
|
53
|
+
# : Optional. An implementation of pseudo-prime generator.
|
54
|
+
#
|
55
|
+
#
|
56
|
+
# ## Return value
|
57
|
+
#
|
58
|
+
# An evaluated value of the given block at the last time. Or an enumerator which
|
59
|
+
# is compatible to an `Enumerator` if no block given.
|
60
|
+
#
|
61
|
+
# ## Description
|
62
|
+
#
|
63
|
+
# Calls `block` once for each prime number, passing the prime as a parameter.
|
64
|
+
#
|
65
|
+
# `ubound`
|
66
|
+
# : Upper bound of prime numbers. The iterator stops after it yields all prime
|
67
|
+
# numbers p <= `ubound`.
|
68
|
+
#
|
69
|
+
def self?.each: (?Integer? ubound, ?PseudoPrimeGenerator generator) { (Integer) -> void } -> void
|
70
|
+
| (?Integer? ubound, ?PseudoPrimeGenerator generator) -> PseudoPrimeGenerator
|
71
|
+
|
72
|
+
# Re-composes a prime factorization and returns the product.
|
73
|
+
#
|
74
|
+
# ## Parameters
|
75
|
+
# `pd`
|
76
|
+
# : Array of pairs of integers. The each internal pair consists of a prime
|
77
|
+
# number -- a prime factor -- and a natural number -- an exponent.
|
78
|
+
#
|
79
|
+
#
|
80
|
+
# ## Example
|
81
|
+
# For `[[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]]`, it returns:
|
82
|
+
#
|
83
|
+
# p_1**e_1 * p_2**e_2 * .... * p_n**e_n.
|
84
|
+
#
|
85
|
+
# Prime.int_from_prime_division([[2,2], [3,1]]) #=> 12
|
86
|
+
#
|
87
|
+
def self?.int_from_prime_division: (Array[[ Integer, Integer ]]) -> Integer
|
88
|
+
|
89
|
+
# Returns true if `value` is a prime number, else returns false.
|
90
|
+
#
|
91
|
+
# ## Parameters
|
92
|
+
#
|
93
|
+
# `value`
|
94
|
+
# : an arbitrary integer to be checked.
|
95
|
+
# `generator`
|
96
|
+
# : optional. A pseudo-prime generator.
|
97
|
+
#
|
98
|
+
def self?.prime?: (Integer value, ?PseudoPrimeGenerator generator) -> bool
|
99
|
+
|
100
|
+
# Returns the factorization of `value`.
|
101
|
+
#
|
102
|
+
# ## Parameters
|
103
|
+
# `value`
|
104
|
+
# : An arbitrary integer.
|
105
|
+
# `generator`
|
106
|
+
# : Optional. A pseudo-prime generator. `generator`.succ must return the next
|
107
|
+
# pseudo-prime number in the ascending order. It must generate all prime
|
108
|
+
# numbers, but may also generate non prime numbers too.
|
109
|
+
#
|
110
|
+
#
|
111
|
+
# ### Exceptions
|
112
|
+
# `ZeroDivisionError`
|
113
|
+
# : when `value` is zero.
|
114
|
+
#
|
115
|
+
#
|
116
|
+
# ## Example
|
117
|
+
# For an arbitrary integer:
|
118
|
+
#
|
119
|
+
# n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,
|
120
|
+
#
|
121
|
+
# prime_division(n) returns:
|
122
|
+
#
|
123
|
+
# [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].
|
124
|
+
#
|
125
|
+
# Prime.prime_division(12) #=> [[2,2], [3,1]]
|
126
|
+
#
|
127
|
+
def self?.prime_division: (Integer, ?PseudoPrimeGenerator generator) -> Array[[ Integer, Integer ]]
|
128
|
+
|
129
|
+
# Returns the singleton instance.
|
130
|
+
#
|
131
|
+
def self.instance: () -> Prime
|
132
|
+
end
|
133
|
+
|
134
|
+
# An abstract class for enumerating pseudo-prime numbers.
|
135
|
+
#
|
136
|
+
# Concrete subclasses should override succ, next, rewind.
|
137
|
+
#
|
138
|
+
class Prime::PseudoPrimeGenerator
|
139
|
+
def initialize: (?Integer?) -> void
|
140
|
+
|
141
|
+
include Enumerable[Integer, void]
|
142
|
+
|
143
|
+
attr_accessor upper_bound (): Integer?
|
144
|
+
|
145
|
+
# Iterates the given block for each prime number.
|
146
|
+
#
|
147
|
+
def each: () { (Integer) -> void } -> void
|
148
|
+
|
149
|
+
# alias of `succ`.
|
150
|
+
#
|
151
|
+
def next: () -> Integer
|
152
|
+
|
153
|
+
# Rewinds the internal position for enumeration.
|
154
|
+
#
|
155
|
+
# See `Enumerator`#rewind.
|
156
|
+
#
|
157
|
+
def rewind: () -> void
|
158
|
+
|
159
|
+
def size: () -> Float
|
160
|
+
|
161
|
+
# returns the next pseudo-prime number, and move the internal position forward.
|
162
|
+
#
|
163
|
+
# `PseudoPrimeGenerator`#succ raises `NotImplementedError`.
|
164
|
+
#
|
165
|
+
def succ: () -> Integer
|
166
|
+
end
|
167
|
+
|
168
|
+
# An implementation of `PseudoPrimeGenerator`.
|
169
|
+
#
|
170
|
+
# Uses `EratosthenesSieve`.
|
171
|
+
#
|
172
|
+
class Prime::EratosthenesGenerator < PseudoPrimeGenerator
|
173
|
+
end
|
174
|
+
|
175
|
+
# An implementation of `PseudoPrimeGenerator` which uses a prime table generated
|
176
|
+
# by trial division.
|
177
|
+
#
|
178
|
+
class Prime::TrialDivisionGenerator < PseudoPrimeGenerator
|
179
|
+
end
|
180
|
+
|
181
|
+
# Generates all integers which are greater than 2 and are not divisible by
|
182
|
+
# either 2 or 3.
|
183
|
+
#
|
184
|
+
# This is a pseudo-prime generator, suitable on checking primality of an integer
|
185
|
+
# by brute force method.
|
186
|
+
#
|
187
|
+
class Prime::Generator23 < PseudoPrimeGenerator
|
188
|
+
end
|