steep 0.13.0 → 0.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +28 -0
- data/Rakefile +0 -13
- data/bin/setup +0 -2
- data/bin/smoke_runner.rb +0 -1
- data/exe/steep +0 -1
- data/lib/steep.rb +33 -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 +124 -89
- data/lib/steep/cli.rb +16 -1
- data/lib/steep/drivers/annotations.rb +1 -1
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/init.rb +5 -5
- data/lib/steep/drivers/langserver.rb +13 -287
- data/lib/steep/drivers/utils/driver_helper.rb +1 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/drivers/watch.rb +97 -85
- data/lib/steep/drivers/worker.rb +51 -0
- data/lib/steep/project.rb +9 -5
- data/lib/steep/project/completion_provider.rb +298 -0
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +54 -47
- data/lib/steep/project/hover_content.rb +17 -8
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +40 -24
- data/lib/steep/server/base_worker.rb +56 -0
- data/lib/steep/server/code_worker.rb +151 -0
- data/lib/steep/server/interaction_worker.rb +281 -0
- data/lib/steep/server/master.rb +196 -0
- data/lib/steep/server/signature_worker.rb +148 -0
- data/lib/steep/server/utils.rb +36 -0
- data/lib/steep/server/worker_process.rb +62 -0
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +13 -13
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +1004 -727
- data/lib/steep/type_inference/constant_env.rb +3 -11
- data/lib/steep/type_inference/context.rb +8 -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 +91 -23
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/alias/a.rb +1 -1
- 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/regexp/b.rb +4 -4
- 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 +8 -8
- metadata +38 -138
- data/exe/rbs +0 -3
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
- data/vendor/ruby-signature/.gitignore +0 -12
- data/vendor/ruby-signature/.rubocop.yml +0 -15
- data/vendor/ruby-signature/BSDL +0 -22
- data/vendor/ruby-signature/COPYING +0 -56
- data/vendor/ruby-signature/Gemfile +0 -6
- data/vendor/ruby-signature/README.md +0 -93
- data/vendor/ruby-signature/Rakefile +0 -66
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
- data/vendor/ruby-signature/bin/console +0 -14
- data/vendor/ruby-signature/bin/query-rdoc +0 -103
- data/vendor/ruby-signature/bin/setup +0 -10
- data/vendor/ruby-signature/bin/sort +0 -88
- data/vendor/ruby-signature/bin/test_runner.rb +0 -17
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
- data/vendor/ruby-signature/docs/sigs.md +0 -148
- data/vendor/ruby-signature/docs/stdlib.md +0 -152
- data/vendor/ruby-signature/docs/syntax.md +0 -528
- data/vendor/ruby-signature/exe/rbs +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
- 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 -534
- 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/parser.y +0 -1343
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
- 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.rb +0 -28
- 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/setup.rb +0 -58
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
- 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/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
- data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
- data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,280 +0,0 @@
|
|
1
|
-
# BasicObject is the parent class of all classes in Ruby. It's an explicit
|
2
|
-
# blank class.
|
3
|
-
#
|
4
|
-
# BasicObject can be used for creating object hierarchies independent of Ruby's
|
5
|
-
# object hierarchy, proxy objects like the Delegator class, or other uses where
|
6
|
-
# namespace pollution from Ruby's methods and classes must be avoided.
|
7
|
-
#
|
8
|
-
# To avoid polluting BasicObject for other users an appropriately named subclass
|
9
|
-
# of BasicObject should be created instead of directly modifying BasicObject:
|
10
|
-
#
|
11
|
-
# class MyObjectSystem < BasicObject
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# BasicObject does not include Kernel (for methods like `puts`) and BasicObject
|
15
|
-
# is outside of the namespace of the standard library so common classes will not
|
16
|
-
# be found without using a full class path.
|
17
|
-
#
|
18
|
-
# A variety of strategies can be used to provide useful portions of the standard
|
19
|
-
# library to subclasses of BasicObject. A subclass could `include Kernel` to
|
20
|
-
# obtain `puts`, `exit`, etc. A custom Kernel-like module could be created and
|
21
|
-
# included or delegation can be used via #method_missing:
|
22
|
-
#
|
23
|
-
# class MyObjectSystem < BasicObject
|
24
|
-
# DELEGATE = [:puts, :p]
|
25
|
-
#
|
26
|
-
# def method_missing(name, *args, &block)
|
27
|
-
# super unless DELEGATE.include? name
|
28
|
-
# ::Kernel.send(name, *args, &block)
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# def respond_to_missing?(name, include_private = false)
|
32
|
-
# DELEGATE.include?(name) or super
|
33
|
-
# end
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# Access to classes and modules from the Ruby standard library can be obtained
|
37
|
-
# in a BasicObject subclass by referencing the desired constant from the root
|
38
|
-
# like `::File` or `::Enumerator`. Like #method_missing, #const_missing can be
|
39
|
-
# used to delegate constant lookup to `Object`:
|
40
|
-
#
|
41
|
-
# class MyObjectSystem < BasicObject
|
42
|
-
# def self.const_missing(name)
|
43
|
-
# ::Object.const_get(name)
|
44
|
-
# end
|
45
|
-
# end
|
46
|
-
#
|
47
|
-
class BasicObject
|
48
|
-
# Boolean negate.
|
49
|
-
#
|
50
|
-
def !: () -> bool
|
51
|
-
|
52
|
-
# Returns true if two objects are not-equal, otherwise false.
|
53
|
-
#
|
54
|
-
def !=: (untyped other) -> bool
|
55
|
-
|
56
|
-
# Equality --- At the `Object` level, `==` returns `true` only if `obj` and
|
57
|
-
# `other` are the same object. Typically, this method is overridden in
|
58
|
-
# descendant classes to provide class-specific meaning.
|
59
|
-
#
|
60
|
-
# Unlike `==`, the `equal?` method should never be overridden by subclasses as
|
61
|
-
# it is used to determine object identity (that is, `a.equal?(b)` if and only if
|
62
|
-
# `a` is the same object as `b`):
|
63
|
-
#
|
64
|
-
# obj = "a"
|
65
|
-
# other = obj.dup
|
66
|
-
#
|
67
|
-
# obj == other #=> true
|
68
|
-
# obj.equal? other #=> false
|
69
|
-
# obj.equal? obj #=> true
|
70
|
-
#
|
71
|
-
# The `eql?` method returns `true` if `obj` and `other` refer to the same hash
|
72
|
-
# key. This is used by Hash to test members for equality. For objects of class
|
73
|
-
# `Object`, `eql?` is synonymous with `==`. Subclasses normally continue this
|
74
|
-
# tradition by aliasing `eql?` to their overridden `==` method, but there are
|
75
|
-
# exceptions. `Numeric` types, for example, perform type conversion across
|
76
|
-
# `==`, but not across `eql?`, so:
|
77
|
-
#
|
78
|
-
# 1 == 1.0 #=> true
|
79
|
-
# 1.eql? 1.0 #=> false
|
80
|
-
#
|
81
|
-
def ==: (untyped other) -> bool
|
82
|
-
|
83
|
-
# Returns an integer identifier for `obj`.
|
84
|
-
#
|
85
|
-
# The same number will be returned on all calls to `object_id` for a given
|
86
|
-
# object, and no two active objects will share an id.
|
87
|
-
#
|
88
|
-
# Note: that some objects of builtin classes are reused for optimization. This
|
89
|
-
# is the case for immediate values and frozen string literals.
|
90
|
-
#
|
91
|
-
# Immediate values are not passed by reference but are passed by value: `nil`,
|
92
|
-
# `true`, `false`, Fixnums, Symbols, and some Floats.
|
93
|
-
#
|
94
|
-
# Object.new.object_id == Object.new.object_id # => false
|
95
|
-
# (21 * 2).object_id == (21 * 2).object_id # => true
|
96
|
-
# "hello".object_id == "hello".object_id # => false
|
97
|
-
# "hi".freeze.object_id == "hi".freeze.object_id # => true
|
98
|
-
#
|
99
|
-
def __id__: () -> Integer
|
100
|
-
|
101
|
-
# Invokes the method identified by *symbol*, passing it any arguments specified.
|
102
|
-
# You can use `__send__` if the name `send` clashes with an existing method in
|
103
|
-
# *obj*. When the method is identified by a string, the string is converted to a
|
104
|
-
# symbol.
|
105
|
-
#
|
106
|
-
# class Klass
|
107
|
-
# def hello(*args)
|
108
|
-
# "Hello " + args.join(' ')
|
109
|
-
# end
|
110
|
-
# end
|
111
|
-
# k = Klass.new
|
112
|
-
# k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
|
113
|
-
#
|
114
|
-
def __send__: (String | Symbol arg0, *untyped args) -> untyped
|
115
|
-
|
116
|
-
# Equality --- At the `Object` level, `==` returns `true` only if `obj` and
|
117
|
-
# `other` are the same object. Typically, this method is overridden in
|
118
|
-
# descendant classes to provide class-specific meaning.
|
119
|
-
#
|
120
|
-
# Unlike `==`, the `equal?` method should never be overridden by subclasses as
|
121
|
-
# it is used to determine object identity (that is, `a.equal?(b)` if and only if
|
122
|
-
# `a` is the same object as `b`):
|
123
|
-
#
|
124
|
-
# obj = "a"
|
125
|
-
# other = obj.dup
|
126
|
-
#
|
127
|
-
# obj == other #=> true
|
128
|
-
# obj.equal? other #=> false
|
129
|
-
# obj.equal? obj #=> true
|
130
|
-
#
|
131
|
-
# The `eql?` method returns `true` if `obj` and `other` refer to the same hash
|
132
|
-
# key. This is used by Hash to test members for equality. For objects of class
|
133
|
-
# `Object`, `eql?` is synonymous with `==`. Subclasses normally continue this
|
134
|
-
# tradition by aliasing `eql?` to their overridden `==` method, but there are
|
135
|
-
# exceptions. `Numeric` types, for example, perform type conversion across
|
136
|
-
# `==`, but not across `eql?`, so:
|
137
|
-
#
|
138
|
-
# 1 == 1.0 #=> true
|
139
|
-
# 1.eql? 1.0 #=> false
|
140
|
-
#
|
141
|
-
def equal?: (untyped other) -> bool
|
142
|
-
|
143
|
-
# Evaluates a string containing Ruby source code, or the given block, within the
|
144
|
-
# context of the receiver (*obj*). In order to set the context, the variable
|
145
|
-
# `self` is set to *obj* while the code is executing, giving the code access to
|
146
|
-
# *obj*'s instance variables and private methods.
|
147
|
-
#
|
148
|
-
# When `instance_eval` is given a block, *obj* is also passed in as the block's
|
149
|
-
# only argument.
|
150
|
-
#
|
151
|
-
# When `instance_eval` is given a `String`, the optional second and third
|
152
|
-
# parameters supply a filename and starting line number that are used when
|
153
|
-
# reporting compilation errors.
|
154
|
-
#
|
155
|
-
# class KlassWithSecret
|
156
|
-
# def initialize
|
157
|
-
# @secret = 99
|
158
|
-
# end
|
159
|
-
# private
|
160
|
-
# def the_secret
|
161
|
-
# "Ssssh! The secret is #{@secret}."
|
162
|
-
# end
|
163
|
-
# end
|
164
|
-
# k = KlassWithSecret.new
|
165
|
-
# k.instance_eval { @secret } #=> 99
|
166
|
-
# k.instance_eval { the_secret } #=> "Ssssh! The secret is 99."
|
167
|
-
# k.instance_eval {|obj| obj == self } #=> true
|
168
|
-
#
|
169
|
-
def instance_eval: (String, ?String filename, ?Integer lineno) -> untyped
|
170
|
-
| [U] () { (self) -> U } -> U
|
171
|
-
|
172
|
-
# Executes the given block within the context of the receiver (*obj*). In order
|
173
|
-
# to set the context, the variable `self` is set to *obj* while the code is
|
174
|
-
# executing, giving the code access to *obj*'s instance variables. Arguments
|
175
|
-
# are passed as block parameters.
|
176
|
-
#
|
177
|
-
# class KlassWithSecret
|
178
|
-
# def initialize
|
179
|
-
# @secret = 99
|
180
|
-
# end
|
181
|
-
# end
|
182
|
-
# k = KlassWithSecret.new
|
183
|
-
# k.instance_exec(5) {|x| @secret+x } #=> 104
|
184
|
-
#
|
185
|
-
def instance_exec: [U, V] (*V args) { (*V args) -> U } -> U
|
186
|
-
|
187
|
-
# Not documented
|
188
|
-
#
|
189
|
-
def initialize: () -> void
|
190
|
-
|
191
|
-
private
|
192
|
-
|
193
|
-
# Invoked by Ruby when *obj* is sent a message it cannot handle. *symbol* is the
|
194
|
-
# symbol for the method called, and *args* are any arguments that were passed to
|
195
|
-
# it. By default, the interpreter raises an error when this method is called.
|
196
|
-
# However, it is possible to override the method to provide more dynamic
|
197
|
-
# behavior. If it is decided that a particular method should not be handled,
|
198
|
-
# then *super* should be called, so that ancestors can pick up the missing
|
199
|
-
# method. The example below creates a class `Roman`, which responds to methods
|
200
|
-
# with names consisting of roman numerals, returning the corresponding integer
|
201
|
-
# values.
|
202
|
-
#
|
203
|
-
# class Roman
|
204
|
-
# def roman_to_int(str)
|
205
|
-
# # ...
|
206
|
-
# end
|
207
|
-
# def method_missing(methId)
|
208
|
-
# str = methId.id2name
|
209
|
-
# roman_to_int(str)
|
210
|
-
# end
|
211
|
-
# end
|
212
|
-
#
|
213
|
-
# r = Roman.new
|
214
|
-
# r.iv #=> 4
|
215
|
-
# r.xxiii #=> 23
|
216
|
-
# r.mm #=> 2000
|
217
|
-
#
|
218
|
-
def method_missing: (Symbol, *untyped) -> untyped
|
219
|
-
|
220
|
-
# Invoked as a callback whenever a singleton method is added to the receiver.
|
221
|
-
#
|
222
|
-
# module Chatty
|
223
|
-
# def Chatty.singleton_method_added(id)
|
224
|
-
# puts "Adding #{id.id2name}"
|
225
|
-
# end
|
226
|
-
# def self.one() end
|
227
|
-
# def two() end
|
228
|
-
# def Chatty.three() end
|
229
|
-
# end
|
230
|
-
#
|
231
|
-
# *produces:*
|
232
|
-
#
|
233
|
-
# Adding singleton_method_added
|
234
|
-
# Adding one
|
235
|
-
# Adding three
|
236
|
-
#
|
237
|
-
def singleton_method_added: (Symbol) -> void
|
238
|
-
|
239
|
-
# Invoked as a callback whenever a singleton method is removed from the
|
240
|
-
# receiver.
|
241
|
-
#
|
242
|
-
# module Chatty
|
243
|
-
# def Chatty.singleton_method_removed(id)
|
244
|
-
# puts "Removing #{id.id2name}"
|
245
|
-
# end
|
246
|
-
# def self.one() end
|
247
|
-
# def two() end
|
248
|
-
# def Chatty.three() end
|
249
|
-
# class << self
|
250
|
-
# remove_method :three
|
251
|
-
# remove_method :one
|
252
|
-
# end
|
253
|
-
# end
|
254
|
-
#
|
255
|
-
# *produces:*
|
256
|
-
#
|
257
|
-
# Removing three
|
258
|
-
# Removing one
|
259
|
-
#
|
260
|
-
def singleton_method_removed: (Symbol) -> void
|
261
|
-
|
262
|
-
# Invoked as a callback whenever a singleton method is undefined in the
|
263
|
-
# receiver.
|
264
|
-
#
|
265
|
-
# module Chatty
|
266
|
-
# def Chatty.singleton_method_undefined(id)
|
267
|
-
# puts "Undefining #{id.id2name}"
|
268
|
-
# end
|
269
|
-
# def Chatty.one() end
|
270
|
-
# class << self
|
271
|
-
# undef_method(:one)
|
272
|
-
# end
|
273
|
-
# end
|
274
|
-
#
|
275
|
-
# *produces:*
|
276
|
-
#
|
277
|
-
# Undefining one
|
278
|
-
#
|
279
|
-
def singleton_method_undefined: (Symbol) -> void
|
280
|
-
end
|
@@ -1,177 +0,0 @@
|
|
1
|
-
# Objects of class Binding encapsulate the execution context at some particular
|
2
|
-
# place in the code and retain this context for future use. The variables,
|
3
|
-
# methods, value of `self`, and possibly an iterator block that can be accessed
|
4
|
-
# in this context are all retained. Binding objects can be created using
|
5
|
-
# Kernel#binding, and are made available to the callback of
|
6
|
-
# Kernel#set_trace_func and instances of TracePoint.
|
7
|
-
#
|
8
|
-
# These binding objects can be passed as the second argument of the Kernel#eval
|
9
|
-
# method, establishing an environment for the evaluation.
|
10
|
-
#
|
11
|
-
# class Demo
|
12
|
-
# def initialize(n)
|
13
|
-
# @secret = n
|
14
|
-
# end
|
15
|
-
# def get_binding
|
16
|
-
# binding
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# k1 = Demo.new(99)
|
21
|
-
# b1 = k1.get_binding
|
22
|
-
# k2 = Demo.new(-3)
|
23
|
-
# b2 = k2.get_binding
|
24
|
-
#
|
25
|
-
# eval("@secret", b1) #=> 99
|
26
|
-
# eval("@secret", b2) #=> -3
|
27
|
-
# eval("@secret") #=> nil
|
28
|
-
#
|
29
|
-
# Binding objects have no class-specific methods.
|
30
|
-
#
|
31
|
-
class Binding
|
32
|
-
public
|
33
|
-
|
34
|
-
# Evaluates the Ruby expression(s) in *string*, in the *binding*'s context. If
|
35
|
-
# the optional *filename* and *lineno* parameters are present, they will be used
|
36
|
-
# when reporting syntax errors.
|
37
|
-
#
|
38
|
-
# def get_binding(param)
|
39
|
-
# binding
|
40
|
-
# end
|
41
|
-
# b = get_binding("hello")
|
42
|
-
# b.eval("param") #=> "hello"
|
43
|
-
#
|
44
|
-
def eval: (String arg0, ?String filename, ?Integer lineno) -> untyped
|
45
|
-
|
46
|
-
# Opens an IRB session where `binding.irb` is called which allows for
|
47
|
-
# interactive debugging. You can call any methods or variables available in the
|
48
|
-
# current scope, and mutate state if you need to.
|
49
|
-
#
|
50
|
-
# Given a Ruby file called `potato.rb` containing the following code:
|
51
|
-
#
|
52
|
-
# class Potato
|
53
|
-
# def initialize
|
54
|
-
# @cooked = false
|
55
|
-
# binding.irb
|
56
|
-
# puts "Cooked potato: #{@cooked}"
|
57
|
-
# end
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# Potato.new
|
61
|
-
#
|
62
|
-
# Running `ruby potato.rb` will open an IRB session where `binding.irb` is
|
63
|
-
# called, and you will see the following:
|
64
|
-
#
|
65
|
-
# $ ruby potato.rb
|
66
|
-
#
|
67
|
-
# From: potato.rb @ line 4 :
|
68
|
-
#
|
69
|
-
# 1: class Potato
|
70
|
-
# 2: def initialize
|
71
|
-
# 3: @cooked = false
|
72
|
-
# => 4: binding.irb
|
73
|
-
# 5: puts "Cooked potato: #{@cooked}"
|
74
|
-
# 6: end
|
75
|
-
# 7: end
|
76
|
-
# 8:
|
77
|
-
# 9: Potato.new
|
78
|
-
#
|
79
|
-
# irb(#<Potato:0x00007feea1916670>):001:0>
|
80
|
-
#
|
81
|
-
# You can type any valid Ruby code and it will be evaluated in the current
|
82
|
-
# context. This allows you to debug without having to run your code repeatedly:
|
83
|
-
#
|
84
|
-
# irb(#<Potato:0x00007feea1916670>):001:0> @cooked
|
85
|
-
# => false
|
86
|
-
# irb(#<Potato:0x00007feea1916670>):002:0> self.class
|
87
|
-
# => Potato
|
88
|
-
# irb(#<Potato:0x00007feea1916670>):003:0> caller.first
|
89
|
-
# => ".../2.5.1/lib/ruby/2.5.0/irb/workspace.rb:85:in `eval'"
|
90
|
-
# irb(#<Potato:0x00007feea1916670>):004:0> @cooked = true
|
91
|
-
# => true
|
92
|
-
#
|
93
|
-
# You can exit the IRB session with the `exit` command. Note that exiting will
|
94
|
-
# resume execution where `binding.irb` had paused it, as you can see from the
|
95
|
-
# output printed to standard output in this example:
|
96
|
-
#
|
97
|
-
# irb(#<Potato:0x00007feea1916670>):005:0> exit
|
98
|
-
# Cooked potato: true
|
99
|
-
#
|
100
|
-
# See IRB@IRB+Usage for more information.
|
101
|
-
#
|
102
|
-
def irb: () -> void
|
103
|
-
|
104
|
-
# Returns `true` if a local variable `symbol` exists.
|
105
|
-
#
|
106
|
-
# def foo
|
107
|
-
# a = 1
|
108
|
-
# binding.local_variable_defined?(:a) #=> true
|
109
|
-
# binding.local_variable_defined?(:b) #=> false
|
110
|
-
# end
|
111
|
-
#
|
112
|
-
# This method is the short version of the following code:
|
113
|
-
#
|
114
|
-
# binding.eval("defined?(#{symbol}) == 'local-variable'")
|
115
|
-
#
|
116
|
-
def local_variable_defined?: (String | Symbol symbol) -> bool
|
117
|
-
|
118
|
-
# Returns the value of the local variable `symbol`.
|
119
|
-
#
|
120
|
-
# def foo
|
121
|
-
# a = 1
|
122
|
-
# binding.local_variable_get(:a) #=> 1
|
123
|
-
# binding.local_variable_get(:b) #=> NameError
|
124
|
-
# end
|
125
|
-
#
|
126
|
-
# This method is the short version of the following code:
|
127
|
-
#
|
128
|
-
# binding.eval("#{symbol}")
|
129
|
-
#
|
130
|
-
def local_variable_get: (String | Symbol symbol) -> untyped
|
131
|
-
|
132
|
-
# Set local variable named `symbol` as `obj`.
|
133
|
-
#
|
134
|
-
# def foo
|
135
|
-
# a = 1
|
136
|
-
# bind = binding
|
137
|
-
# bind.local_variable_set(:a, 2) # set existing local variable `a'
|
138
|
-
# bind.local_variable_set(:b, 3) # create new local variable `b'
|
139
|
-
# # `b' exists only in binding
|
140
|
-
#
|
141
|
-
# p bind.local_variable_get(:a) #=> 2
|
142
|
-
# p bind.local_variable_get(:b) #=> 3
|
143
|
-
# p a #=> 2
|
144
|
-
# p b #=> NameError
|
145
|
-
# end
|
146
|
-
#
|
147
|
-
# This method behaves similarly to the following code:
|
148
|
-
#
|
149
|
-
# binding.eval("#{symbol} = #{obj}")
|
150
|
-
#
|
151
|
-
# if `obj` can be dumped in Ruby code.
|
152
|
-
#
|
153
|
-
def local_variable_set: [U] (String | Symbol symbol, U obj) -> U
|
154
|
-
|
155
|
-
# Returns the names of the binding's local variables as symbols.
|
156
|
-
#
|
157
|
-
# def foo
|
158
|
-
# a = 1
|
159
|
-
# 2.times do |n|
|
160
|
-
# binding.local_variables #=> [:a, :n]
|
161
|
-
# end
|
162
|
-
# end
|
163
|
-
#
|
164
|
-
# This method is the short version of the following code:
|
165
|
-
#
|
166
|
-
# binding.eval("local_variables")
|
167
|
-
#
|
168
|
-
def local_variables: () -> Array[Symbol]
|
169
|
-
|
170
|
-
# Returns the bound receiver of the binding object.
|
171
|
-
#
|
172
|
-
def receiver: () -> untyped
|
173
|
-
|
174
|
-
# Returns the Ruby source filename and line number of the binding object.
|
175
|
-
#
|
176
|
-
def source_location: () -> [ String, Integer ]
|
177
|
-
end
|