rbs 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +15 -0
- data/BSDL +22 -0
- data/CHANGELOG.md +9 -0
- data/COPYING +56 -0
- data/Gemfile +6 -0
- data/README.md +93 -0
- data/Rakefile +142 -0
- data/bin/annotate-with-rdoc +157 -0
- data/bin/console +14 -0
- data/bin/query-rdoc +103 -0
- data/bin/setup +10 -0
- data/bin/sort +89 -0
- data/bin/test_runner.rb +16 -0
- data/docs/CONTRIBUTING.md +97 -0
- data/docs/sigs.md +148 -0
- data/docs/stdlib.md +152 -0
- data/docs/syntax.md +528 -0
- data/exe/rbs +7 -0
- data/lib/rbs.rb +64 -0
- data/lib/rbs/ast/annotation.rb +27 -0
- data/lib/rbs/ast/comment.rb +27 -0
- data/lib/rbs/ast/declarations.rb +395 -0
- data/lib/rbs/ast/members.rb +362 -0
- data/lib/rbs/buffer.rb +50 -0
- data/lib/rbs/builtin_names.rb +55 -0
- data/lib/rbs/cli.rb +558 -0
- data/lib/rbs/constant.rb +26 -0
- data/lib/rbs/constant_table.rb +150 -0
- data/lib/rbs/definition.rb +170 -0
- data/lib/rbs/definition_builder.rb +919 -0
- data/lib/rbs/environment.rb +281 -0
- data/lib/rbs/environment_loader.rb +136 -0
- data/lib/rbs/environment_walker.rb +124 -0
- data/lib/rbs/errors.rb +187 -0
- data/lib/rbs/location.rb +102 -0
- data/lib/rbs/method_type.rb +123 -0
- data/lib/rbs/namespace.rb +91 -0
- data/lib/rbs/parser.y +1344 -0
- data/lib/rbs/prototype/rb.rb +553 -0
- data/lib/rbs/prototype/rbi.rb +587 -0
- data/lib/rbs/prototype/runtime.rb +381 -0
- data/lib/rbs/substitution.rb +46 -0
- data/lib/rbs/test.rb +26 -0
- data/lib/rbs/test/errors.rb +61 -0
- data/lib/rbs/test/hook.rb +294 -0
- data/lib/rbs/test/setup.rb +58 -0
- data/lib/rbs/test/spy.rb +325 -0
- data/lib/rbs/test/test_helper.rb +183 -0
- data/lib/rbs/test/type_check.rb +254 -0
- data/lib/rbs/type_name.rb +70 -0
- data/lib/rbs/types.rb +936 -0
- data/lib/rbs/variance_calculator.rb +138 -0
- data/lib/rbs/vendorer.rb +47 -0
- data/lib/rbs/version.rb +3 -0
- data/lib/rbs/writer.rb +269 -0
- data/lib/ruby/signature.rb +7 -0
- data/rbs.gemspec +46 -0
- data/stdlib/abbrev/abbrev.rbs +60 -0
- data/stdlib/base64/base64.rbs +71 -0
- data/stdlib/benchmark/benchmark.rbs +372 -0
- data/stdlib/builtin/array.rbs +1997 -0
- data/stdlib/builtin/basic_object.rbs +280 -0
- data/stdlib/builtin/binding.rbs +177 -0
- data/stdlib/builtin/builtin.rbs +45 -0
- data/stdlib/builtin/class.rbs +145 -0
- data/stdlib/builtin/comparable.rbs +116 -0
- data/stdlib/builtin/complex.rbs +400 -0
- data/stdlib/builtin/constants.rbs +37 -0
- data/stdlib/builtin/data.rbs +5 -0
- data/stdlib/builtin/deprecated.rbs +2 -0
- data/stdlib/builtin/dir.rbs +413 -0
- data/stdlib/builtin/encoding.rbs +607 -0
- data/stdlib/builtin/enumerable.rbs +404 -0
- data/stdlib/builtin/enumerator.rbs +260 -0
- data/stdlib/builtin/errno.rbs +781 -0
- data/stdlib/builtin/errors.rbs +582 -0
- data/stdlib/builtin/exception.rbs +194 -0
- data/stdlib/builtin/false_class.rbs +40 -0
- data/stdlib/builtin/fiber.rbs +68 -0
- data/stdlib/builtin/fiber_error.rbs +12 -0
- data/stdlib/builtin/file.rbs +1076 -0
- data/stdlib/builtin/file_test.rbs +59 -0
- data/stdlib/builtin/float.rbs +696 -0
- data/stdlib/builtin/gc.rbs +243 -0
- data/stdlib/builtin/hash.rbs +1029 -0
- data/stdlib/builtin/integer.rbs +707 -0
- data/stdlib/builtin/io.rbs +683 -0
- data/stdlib/builtin/kernel.rbs +576 -0
- data/stdlib/builtin/marshal.rbs +161 -0
- data/stdlib/builtin/match_data.rbs +271 -0
- data/stdlib/builtin/math.rbs +369 -0
- data/stdlib/builtin/method.rbs +185 -0
- data/stdlib/builtin/module.rbs +1104 -0
- data/stdlib/builtin/nil_class.rbs +82 -0
- data/stdlib/builtin/numeric.rbs +409 -0
- data/stdlib/builtin/object.rbs +824 -0
- data/stdlib/builtin/proc.rbs +429 -0
- data/stdlib/builtin/process.rbs +1227 -0
- data/stdlib/builtin/random.rbs +267 -0
- data/stdlib/builtin/range.rbs +226 -0
- data/stdlib/builtin/rational.rbs +424 -0
- data/stdlib/builtin/rb_config.rbs +57 -0
- data/stdlib/builtin/regexp.rbs +1083 -0
- data/stdlib/builtin/ruby_vm.rbs +14 -0
- data/stdlib/builtin/signal.rbs +55 -0
- data/stdlib/builtin/string.rbs +1901 -0
- data/stdlib/builtin/string_io.rbs +284 -0
- data/stdlib/builtin/struct.rbs +40 -0
- data/stdlib/builtin/symbol.rbs +228 -0
- data/stdlib/builtin/thread.rbs +1108 -0
- data/stdlib/builtin/thread_group.rbs +23 -0
- data/stdlib/builtin/time.rbs +1047 -0
- data/stdlib/builtin/trace_point.rbs +290 -0
- data/stdlib/builtin/true_class.rbs +46 -0
- data/stdlib/builtin/unbound_method.rbs +153 -0
- data/stdlib/builtin/warning.rbs +17 -0
- data/stdlib/coverage/coverage.rbs +62 -0
- data/stdlib/csv/csv.rbs +773 -0
- data/stdlib/erb/erb.rbs +392 -0
- data/stdlib/find/find.rbs +40 -0
- data/stdlib/ipaddr/ipaddr.rbs +247 -0
- data/stdlib/json/json.rbs +335 -0
- data/stdlib/pathname/pathname.rbs +1093 -0
- data/stdlib/prime/integer-extension.rbs +23 -0
- data/stdlib/prime/prime.rbs +188 -0
- data/stdlib/securerandom/securerandom.rbs +9 -0
- data/stdlib/set/set.rbs +301 -0
- data/stdlib/tmpdir/tmpdir.rbs +53 -0
- metadata +292 -0
@@ -0,0 +1,243 @@
|
|
1
|
+
# The GC module provides an interface to Ruby's mark and sweep garbage
|
2
|
+
# collection mechanism.
|
3
|
+
#
|
4
|
+
# Some of the underlying methods are also available via the ObjectSpace module.
|
5
|
+
#
|
6
|
+
# You may obtain information about the operation of the GC through GC::Profiler.
|
7
|
+
#
|
8
|
+
module GC
|
9
|
+
# The number of times GC occurred.
|
10
|
+
#
|
11
|
+
# It returns the number of times GC occurred since the process started.
|
12
|
+
#
|
13
|
+
def self.count: () -> Integer
|
14
|
+
|
15
|
+
# Disables garbage collection, returning `true` if garbage collection was
|
16
|
+
# already disabled.
|
17
|
+
#
|
18
|
+
# GC.disable #=> false
|
19
|
+
# GC.disable #=> true
|
20
|
+
#
|
21
|
+
def self.disable: () -> bool
|
22
|
+
|
23
|
+
# Enables garbage collection, returning `true` if garbage collection was
|
24
|
+
# previously disabled.
|
25
|
+
#
|
26
|
+
# GC.disable #=> false
|
27
|
+
# GC.enable #=> true
|
28
|
+
# GC.enable #=> false
|
29
|
+
#
|
30
|
+
def self.enable: () -> bool
|
31
|
+
|
32
|
+
# Initiates garbage collection, even if manually disabled.
|
33
|
+
#
|
34
|
+
# This method is defined with keyword arguments that default to true:
|
35
|
+
#
|
36
|
+
# def GC.start(full_mark: true, immediate_sweep: true); end
|
37
|
+
#
|
38
|
+
# Use full_mark: false to perform a minor GC. Use immediate_sweep: false to
|
39
|
+
# defer sweeping (use lazy sweep).
|
40
|
+
#
|
41
|
+
# Note: These keyword arguments are implementation and version dependent. They
|
42
|
+
# are not guaranteed to be future-compatible, and may be ignored if the
|
43
|
+
# underlying implementation does not support them.
|
44
|
+
#
|
45
|
+
def self.start: (?immediate_sweep: bool immediate_sweep, ?immediate_mark: bool immediate_mark, ?full_mark: bool full_mark) -> nil
|
46
|
+
|
47
|
+
# Returns a Hash containing information about the GC.
|
48
|
+
#
|
49
|
+
# The hash includes information about internal statistics about GC such as:
|
50
|
+
#
|
51
|
+
# {
|
52
|
+
# :count=>0,
|
53
|
+
# :heap_allocated_pages=>24,
|
54
|
+
# :heap_sorted_length=>24,
|
55
|
+
# :heap_allocatable_pages=>0,
|
56
|
+
# :heap_available_slots=>9783,
|
57
|
+
# :heap_live_slots=>7713,
|
58
|
+
# :heap_free_slots=>2070,
|
59
|
+
# :heap_final_slots=>0,
|
60
|
+
# :heap_marked_slots=>0,
|
61
|
+
# :heap_eden_pages=>24,
|
62
|
+
# :heap_tomb_pages=>0,
|
63
|
+
# :total_allocated_pages=>24,
|
64
|
+
# :total_freed_pages=>0,
|
65
|
+
# :total_allocated_objects=>7796,
|
66
|
+
# :total_freed_objects=>83,
|
67
|
+
# :malloc_increase_bytes=>2389312,
|
68
|
+
# :malloc_increase_bytes_limit=>16777216,
|
69
|
+
# :minor_gc_count=>0,
|
70
|
+
# :major_gc_count=>0,
|
71
|
+
# :remembered_wb_unprotected_objects=>0,
|
72
|
+
# :remembered_wb_unprotected_objects_limit=>0,
|
73
|
+
# :old_objects=>0,
|
74
|
+
# :old_objects_limit=>0,
|
75
|
+
# :oldmalloc_increase_bytes=>2389760,
|
76
|
+
# :oldmalloc_increase_bytes_limit=>16777216
|
77
|
+
# }
|
78
|
+
#
|
79
|
+
# The contents of the hash are implementation specific and may be changed in the
|
80
|
+
# future.
|
81
|
+
#
|
82
|
+
# This method is only expected to work on C Ruby.
|
83
|
+
#
|
84
|
+
def self.stat: (?::Hash[Symbol, Integer] arg0) -> ::Hash[Symbol, Integer]
|
85
|
+
| (?Symbol arg0) -> Integer
|
86
|
+
|
87
|
+
# Returns current status of GC stress mode.
|
88
|
+
#
|
89
|
+
def self.stress: () -> (Integer | TrueClass | FalseClass)
|
90
|
+
|
91
|
+
# Updates the GC stress mode.
|
92
|
+
#
|
93
|
+
# When stress mode is enabled, the GC is invoked at every GC opportunity: all
|
94
|
+
# memory and object allocations.
|
95
|
+
#
|
96
|
+
# Enabling stress mode will degrade performance, it is only for debugging.
|
97
|
+
#
|
98
|
+
# flag can be true, false, or an integer bit-ORed following flags.
|
99
|
+
# 0x01:: no major GC
|
100
|
+
# 0x02:: no immediate sweep
|
101
|
+
# 0x04:: full mark after malloc/calloc/realloc
|
102
|
+
#
|
103
|
+
def self.stress=: (Integer | TrueClass | FalseClass flag) -> (Integer | TrueClass | FalseClass)
|
104
|
+
|
105
|
+
def self.compact: () -> ::Hash[:considered | :moved, Hash[Symbol | Integer, Integer]]
|
106
|
+
|
107
|
+
# Verify compaction reference consistency.
|
108
|
+
#
|
109
|
+
# This method is implementation specific. During compaction, objects that were
|
110
|
+
# moved are replaced with T_MOVED objects. No object should have a reference to
|
111
|
+
# a T_MOVED object after compaction.
|
112
|
+
#
|
113
|
+
# This function doubles the heap to ensure room to move all objects, compacts
|
114
|
+
# the heap to make sure everything moves, updates all references, then performs
|
115
|
+
# a full GC. If any object contains a reference to a T_MOVED object, that
|
116
|
+
# object should be pushed on the mark stack, and will make a SEGV.
|
117
|
+
#
|
118
|
+
def self.verify_compaction_references: () -> ::Hash[:considered | :moved, Hash[Symbol | Integer, Integer]]
|
119
|
+
|
120
|
+
# Verify internal consistency.
|
121
|
+
#
|
122
|
+
# This method is implementation specific. Now this method checks generational
|
123
|
+
# consistency if RGenGC is supported.
|
124
|
+
#
|
125
|
+
def self.verify_internal_consistency: () -> nil
|
126
|
+
|
127
|
+
def self.verify_transient_heap_internal_consistency: () -> nil
|
128
|
+
|
129
|
+
# Returns information about the most recent garbage collection.
|
130
|
+
#
|
131
|
+
def self.latest_gc_info: () -> ::Hash[::Symbol, untyped]
|
132
|
+
| [K] (?Hash[K, untyped] hash) -> ::Hash[::Symbol | K, untyped]
|
133
|
+
| (Symbol key) -> untyped
|
134
|
+
|
135
|
+
def garbage_collect: (?immediate_sweep: bool immediate_sweep, ?immediate_mark: bool immediate_mark, ?full_mark: bool full_mark) -> nil
|
136
|
+
end
|
137
|
+
|
138
|
+
# internal constants
|
139
|
+
#
|
140
|
+
#
|
141
|
+
GC::INTERNAL_CONSTANTS: Hash[Symbol, Integer]
|
142
|
+
|
143
|
+
# GC build options
|
144
|
+
#
|
145
|
+
#
|
146
|
+
GC::OPTS: Array[String]
|
147
|
+
|
148
|
+
# The GC profiler provides access to information on GC runs including time,
|
149
|
+
# length and object space size.
|
150
|
+
#
|
151
|
+
# Example:
|
152
|
+
#
|
153
|
+
# GC::Profiler.enable
|
154
|
+
#
|
155
|
+
# require 'rdoc/rdoc'
|
156
|
+
#
|
157
|
+
# GC::Profiler.report
|
158
|
+
#
|
159
|
+
# GC::Profiler.disable
|
160
|
+
#
|
161
|
+
# See also GC.count, GC.malloc_allocated_size and GC.malloc_allocations
|
162
|
+
#
|
163
|
+
module GC::Profiler
|
164
|
+
# Clears the GC profiler data.
|
165
|
+
#
|
166
|
+
def self.clear: () -> void
|
167
|
+
|
168
|
+
# Stops the GC profiler.
|
169
|
+
#
|
170
|
+
def self.disable: () -> void
|
171
|
+
|
172
|
+
# Starts the GC profiler.
|
173
|
+
#
|
174
|
+
def self.enable: () -> void
|
175
|
+
|
176
|
+
# The current status of GC profile mode.
|
177
|
+
#
|
178
|
+
def self.enabled?: () -> bool
|
179
|
+
|
180
|
+
# Returns an Array of individual raw profile data Hashes ordered from earliest
|
181
|
+
# to latest by `:GC_INVOKE_TIME`.
|
182
|
+
#
|
183
|
+
# For example:
|
184
|
+
#
|
185
|
+
# [
|
186
|
+
# {
|
187
|
+
# :GC_TIME=>1.3000000000000858e-05,
|
188
|
+
# :GC_INVOKE_TIME=>0.010634999999999999,
|
189
|
+
# :HEAP_USE_SIZE=>289640,
|
190
|
+
# :HEAP_TOTAL_SIZE=>588960,
|
191
|
+
# :HEAP_TOTAL_OBJECTS=>14724,
|
192
|
+
# :GC_IS_MARKED=>false
|
193
|
+
# },
|
194
|
+
# # ...
|
195
|
+
# ]
|
196
|
+
#
|
197
|
+
# The keys mean:
|
198
|
+
#
|
199
|
+
# `:GC_TIME`
|
200
|
+
# : Time elapsed in seconds for this GC run
|
201
|
+
# `:GC_INVOKE_TIME`
|
202
|
+
# : Time elapsed in seconds from startup to when the GC was invoked
|
203
|
+
# `:HEAP_USE_SIZE`
|
204
|
+
# : Total bytes of heap used
|
205
|
+
# `:HEAP_TOTAL_SIZE`
|
206
|
+
# : Total size of heap in bytes
|
207
|
+
# `:HEAP_TOTAL_OBJECTS`
|
208
|
+
# : Total number of objects
|
209
|
+
# `:GC_IS_MARKED`
|
210
|
+
# : Returns `true` if the GC is in mark phase
|
211
|
+
#
|
212
|
+
#
|
213
|
+
# If ruby was built with `GC_PROFILE_MORE_DETAIL`, you will also have access to
|
214
|
+
# the following hash keys:
|
215
|
+
#
|
216
|
+
# `:GC_MARK_TIME`
|
217
|
+
# `:GC_SWEEP_TIME`
|
218
|
+
# `:ALLOCATE_INCREASE`
|
219
|
+
# `:ALLOCATE_LIMIT`
|
220
|
+
# `:HEAP_USE_PAGES`
|
221
|
+
# `:HEAP_LIVE_OBJECTS`
|
222
|
+
# `:HEAP_FREE_OBJECTS`
|
223
|
+
# `:HAVE_FINALIZE`
|
224
|
+
# :
|
225
|
+
#
|
226
|
+
def self.raw_data: () -> ::Array[::Hash[Symbol, untyped]]
|
227
|
+
|
228
|
+
# Writes the GC::Profiler.result to `$stdout` or the given IO object.
|
229
|
+
#
|
230
|
+
def self.report: (?IO io) -> void
|
231
|
+
|
232
|
+
# Returns a profile data report such as:
|
233
|
+
#
|
234
|
+
# GC 1 invokes.
|
235
|
+
# Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC time(ms)
|
236
|
+
# 1 0.012 159240 212940 10647 0.00000000000001530000
|
237
|
+
#
|
238
|
+
def self.result: () -> String
|
239
|
+
|
240
|
+
# The total time used for garbage collection in seconds
|
241
|
+
#
|
242
|
+
def self.total_time: () -> Float
|
243
|
+
end
|
@@ -0,0 +1,1029 @@
|
|
1
|
+
# A Hash is a dictionary-like collection of unique keys and their values. Also
|
2
|
+
# called associative arrays, they are similar to Arrays, but where an Array uses
|
3
|
+
# integers as its index, a Hash allows you to use any object type.
|
4
|
+
#
|
5
|
+
# Hashes enumerate their values in the order that the corresponding keys were
|
6
|
+
# inserted.
|
7
|
+
#
|
8
|
+
# A Hash can be easily created by using its implicit form:
|
9
|
+
#
|
10
|
+
# grades = { "Jane Doe" => 10, "Jim Doe" => 6 }
|
11
|
+
#
|
12
|
+
# Hashes allow an alternate syntax for keys that are symbols. Instead of
|
13
|
+
#
|
14
|
+
# options = { :font_size => 10, :font_family => "Arial" }
|
15
|
+
#
|
16
|
+
# You could write it as:
|
17
|
+
#
|
18
|
+
# options = { font_size: 10, font_family: "Arial" }
|
19
|
+
#
|
20
|
+
# Each named key is a symbol you can access in hash:
|
21
|
+
#
|
22
|
+
# options[:font_size] # => 10
|
23
|
+
#
|
24
|
+
# A Hash can also be created through its ::new method:
|
25
|
+
#
|
26
|
+
# grades = Hash.new
|
27
|
+
# grades["Dorothy Doe"] = 9
|
28
|
+
#
|
29
|
+
# Hashes have a *default value* that is returned when accessing keys that do not
|
30
|
+
# exist in the hash. If no default is set `nil` is used. You can set the default
|
31
|
+
# value by sending it as an argument to Hash.new:
|
32
|
+
#
|
33
|
+
# grades = Hash.new(0)
|
34
|
+
#
|
35
|
+
# Or by using the #default= method:
|
36
|
+
#
|
37
|
+
# grades = {"Timmy Doe" => 8}
|
38
|
+
# grades.default = 0
|
39
|
+
#
|
40
|
+
# Accessing a value in a Hash requires using its key:
|
41
|
+
#
|
42
|
+
# puts grades["Jane Doe"] # => 0
|
43
|
+
#
|
44
|
+
# ### Common Uses
|
45
|
+
#
|
46
|
+
# Hashes are an easy way to represent data structures, such as
|
47
|
+
#
|
48
|
+
# books = {}
|
49
|
+
# books[:matz] = "The Ruby Programming Language"
|
50
|
+
# books[:black] = "The Well-Grounded Rubyist"
|
51
|
+
#
|
52
|
+
# Hashes are also commonly used as a way to have named parameters in functions.
|
53
|
+
# Note that no brackets are used below. If a hash is the last argument on a
|
54
|
+
# method call, no braces are needed, thus creating a really clean interface:
|
55
|
+
#
|
56
|
+
# Person.create(name: "John Doe", age: 27)
|
57
|
+
#
|
58
|
+
# def self.create(params)
|
59
|
+
# @name = params[:name]
|
60
|
+
# @age = params[:age]
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# ### Hash Keys
|
64
|
+
#
|
65
|
+
# Two objects refer to the same hash key when their `hash` value is identical
|
66
|
+
# and the two objects are `eql?` to each other.
|
67
|
+
#
|
68
|
+
# A user-defined class may be used as a hash key if the `hash` and `eql?`
|
69
|
+
# methods are overridden to provide meaningful behavior. By default, separate
|
70
|
+
# instances refer to separate hash keys.
|
71
|
+
#
|
72
|
+
# A typical implementation of `hash` is based on the object's data while `eql?`
|
73
|
+
# is usually aliased to the overridden `==` method:
|
74
|
+
#
|
75
|
+
# class Book
|
76
|
+
# attr_reader :author, :title
|
77
|
+
#
|
78
|
+
# def initialize(author, title)
|
79
|
+
# @author = author
|
80
|
+
# @title = title
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# def ==(other)
|
84
|
+
# self.class === other and
|
85
|
+
# other.author == @author and
|
86
|
+
# other.title == @title
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# alias eql? ==
|
90
|
+
#
|
91
|
+
# def hash
|
92
|
+
# @author.hash ^ @title.hash # XOR
|
93
|
+
# end
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# book1 = Book.new 'matz', 'Ruby in a Nutshell'
|
97
|
+
# book2 = Book.new 'matz', 'Ruby in a Nutshell'
|
98
|
+
#
|
99
|
+
# reviews = {}
|
100
|
+
#
|
101
|
+
# reviews[book1] = 'Great reference!'
|
102
|
+
# reviews[book2] = 'Nice and compact!'
|
103
|
+
#
|
104
|
+
# reviews.length #=> 1
|
105
|
+
#
|
106
|
+
# See also Object#hash and Object#eql?
|
107
|
+
#
|
108
|
+
class Hash[unchecked out K, unchecked out V] < Object
|
109
|
+
include Enumerable[[K, V], Hash[K, V]]
|
110
|
+
|
111
|
+
# Creates a new hash populated with the given objects.
|
112
|
+
#
|
113
|
+
# Similar to the literal `{ *key* => *value*, ... }`. In the first form, keys
|
114
|
+
# and values occur in pairs, so there must be an even number of arguments.
|
115
|
+
#
|
116
|
+
# The second and third form take a single argument which is either an array of
|
117
|
+
# key-value pairs or an object convertible to a hash.
|
118
|
+
#
|
119
|
+
# Hash["a", 100, "b", 200] #=> {"a"=>100, "b"=>200}
|
120
|
+
# Hash[ [ ["a", 100], ["b", 200] ] ] #=> {"a"=>100, "b"=>200}
|
121
|
+
# Hash["a" => 100, "b" => 200] #=> {"a"=>100, "b"=>200}
|
122
|
+
#
|
123
|
+
def self.[]: [U, V] (_ToHash[U, V]) -> ::Hash[U, V]
|
124
|
+
| [U, V] (Array[[ U, V ]]) -> ::Hash[U, V]
|
125
|
+
| (*untyped) -> ::Hash[untyped, untyped]
|
126
|
+
|
127
|
+
# Try to convert *obj* into a hash, using to_hash method. Returns converted hash
|
128
|
+
# or nil if *obj* cannot be converted for any reason.
|
129
|
+
#
|
130
|
+
# Hash.try_convert({1=>2}) # => {1=>2}
|
131
|
+
# Hash.try_convert("1=>2") # => nil
|
132
|
+
#
|
133
|
+
def self.try_convert: [U, V] (_ToHash[U, V]) -> ::Hash[U, V]
|
134
|
+
| (untyped) -> (::Hash[untyped, untyped] | nil)
|
135
|
+
|
136
|
+
public
|
137
|
+
|
138
|
+
# Returns `true` if *hash* is subset of *other*.
|
139
|
+
#
|
140
|
+
# h1 = {a:1, b:2}
|
141
|
+
# h2 = {a:1, b:2, c:3}
|
142
|
+
# h1 < h2 #=> true
|
143
|
+
# h2 < h1 #=> false
|
144
|
+
# h1 < h1 #=> false
|
145
|
+
#
|
146
|
+
def <: (::Hash[K, V]) -> bool
|
147
|
+
|
148
|
+
# Returns `true` if *hash* is subset of *other* or equals to *other*.
|
149
|
+
#
|
150
|
+
# h1 = {a:1, b:2}
|
151
|
+
# h2 = {a:1, b:2, c:3}
|
152
|
+
# h1 <= h2 #=> true
|
153
|
+
# h2 <= h1 #=> false
|
154
|
+
# h1 <= h1 #=> true
|
155
|
+
#
|
156
|
+
def <=: (::Hash[K, V]) -> bool
|
157
|
+
|
158
|
+
# Equality---Two hashes are equal if they each contain the same number of keys
|
159
|
+
# and if each key-value pair is equal to (according to Object#==) the
|
160
|
+
# corresponding elements in the other hash.
|
161
|
+
#
|
162
|
+
# h1 = { "a" => 1, "c" => 2 }
|
163
|
+
# h2 = { 7 => 35, "c" => 2, "a" => 1 }
|
164
|
+
# h3 = { "a" => 1, "c" => 2, 7 => 35 }
|
165
|
+
# h4 = { "a" => 1, "d" => 2, "f" => 35 }
|
166
|
+
# h1 == h2 #=> false
|
167
|
+
# h2 == h3 #=> true
|
168
|
+
# h3 == h4 #=> false
|
169
|
+
#
|
170
|
+
# The orders of each hashes are not compared.
|
171
|
+
#
|
172
|
+
# h1 = { "a" => 1, "c" => 2 }
|
173
|
+
# h2 = { "c" => 2, "a" => 1 }
|
174
|
+
# h1 == h2 #=> true
|
175
|
+
#
|
176
|
+
def ==: (untyped other) -> bool
|
177
|
+
|
178
|
+
# Returns `true` if *other* is subset of *hash*.
|
179
|
+
#
|
180
|
+
# h1 = {a:1, b:2}
|
181
|
+
# h2 = {a:1, b:2, c:3}
|
182
|
+
# h1 > h2 #=> false
|
183
|
+
# h2 > h1 #=> true
|
184
|
+
# h1 > h1 #=> false
|
185
|
+
#
|
186
|
+
def >: (::Hash[K, V]) -> bool
|
187
|
+
|
188
|
+
# Returns `true` if *other* is subset of *hash* or equals to *hash*.
|
189
|
+
#
|
190
|
+
# h1 = {a:1, b:2}
|
191
|
+
# h2 = {a:1, b:2, c:3}
|
192
|
+
# h1 >= h2 #=> false
|
193
|
+
# h2 >= h1 #=> true
|
194
|
+
# h1 >= h1 #=> true
|
195
|
+
#
|
196
|
+
def >=: (::Hash[K, V]) -> bool
|
197
|
+
|
198
|
+
# Element Reference---Retrieves the *value* object corresponding to the *key*
|
199
|
+
# object. If not found, returns the default value (see Hash::new for details).
|
200
|
+
#
|
201
|
+
# h = { "a" => 100, "b" => 200 }
|
202
|
+
# h["a"] #=> 100
|
203
|
+
# h["c"] #=> nil
|
204
|
+
#
|
205
|
+
def []: (K arg0) -> V
|
206
|
+
|
207
|
+
# ## Element Assignment
|
208
|
+
#
|
209
|
+
# Associates the value given by `value` with the key given by `key`.
|
210
|
+
#
|
211
|
+
# h = { "a" => 100, "b" => 200 }
|
212
|
+
# h["a"] = 9
|
213
|
+
# h["c"] = 4
|
214
|
+
# h #=> {"a"=>9, "b"=>200, "c"=>4}
|
215
|
+
# h.store("d", 42) #=> 42
|
216
|
+
# h #=> {"a"=>9, "b"=>200, "c"=>4, "d"=>42}
|
217
|
+
#
|
218
|
+
# `key` should not have its value changed while it is in use as a key (an
|
219
|
+
# `unfrozen String` passed as a key will be duplicated and frozen).
|
220
|
+
#
|
221
|
+
# a = "a"
|
222
|
+
# b = "b".freeze
|
223
|
+
# h = { a => 100, b => 200 }
|
224
|
+
# h.key(100).equal? a #=> false
|
225
|
+
# h.key(200).equal? b #=> true
|
226
|
+
#
|
227
|
+
def []=: (K arg0, V arg1) -> V
|
228
|
+
|
229
|
+
# See also Enumerable#any?
|
230
|
+
#
|
231
|
+
def any?: () -> bool
|
232
|
+
| (untyped pattern) -> bool
|
233
|
+
| () { (K, V) -> bool } -> bool
|
234
|
+
|
235
|
+
# Searches through the hash comparing *obj* with the key using `==`. Returns the
|
236
|
+
# key-value pair (two elements array) or `nil` if no match is found. See
|
237
|
+
# Array#assoc.
|
238
|
+
#
|
239
|
+
# h = {"colors" => ["red", "blue", "green"],
|
240
|
+
# "letters" => ["a", "b", "c" ]}
|
241
|
+
# h.assoc("letters") #=> ["letters", ["a", "b", "c"]]
|
242
|
+
# h.assoc("foo") #=> nil
|
243
|
+
#
|
244
|
+
def assoc: (K arg0) -> [K, V]?
|
245
|
+
|
246
|
+
# Removes all key-value pairs from *hsh*.
|
247
|
+
#
|
248
|
+
# h = { "a" => 100, "b" => 200 } #=> {"a"=>100, "b"=>200}
|
249
|
+
# h.clear #=> {}
|
250
|
+
#
|
251
|
+
def clear: () -> self
|
252
|
+
|
253
|
+
# Returns a new hash with the nil values/key pairs removed
|
254
|
+
#
|
255
|
+
# h = { a: 1, b: false, c: nil }
|
256
|
+
# h.compact #=> { a: 1, b: false }
|
257
|
+
# h #=> { a: 1, b: false, c: nil }
|
258
|
+
#
|
259
|
+
def compact: () -> self
|
260
|
+
|
261
|
+
# Removes all nil values from the hash. Returns nil if no changes were made,
|
262
|
+
# otherwise returns the hash.
|
263
|
+
#
|
264
|
+
# h = { a: 1, b: false, c: nil }
|
265
|
+
# h.compact! #=> { a: 1, b: false }
|
266
|
+
#
|
267
|
+
def compact!: () -> self?
|
268
|
+
|
269
|
+
# Makes *hsh* compare its keys by their identity, i.e. it will consider exact
|
270
|
+
# same objects as same keys.
|
271
|
+
#
|
272
|
+
# h1 = { "a" => 100, "b" => 200, :c => "c" }
|
273
|
+
# h1["a"] #=> 100
|
274
|
+
# h1.compare_by_identity
|
275
|
+
# h1.compare_by_identity? #=> true
|
276
|
+
# h1["a".dup] #=> nil # different objects.
|
277
|
+
# h1[:c] #=> "c" # same symbols are all same.
|
278
|
+
#
|
279
|
+
def compare_by_identity: () -> self
|
280
|
+
|
281
|
+
# Returns `true` if *hsh* will compare its keys by their identity. Also see
|
282
|
+
# Hash#compare_by_identity.
|
283
|
+
#
|
284
|
+
def compare_by_identity?: () -> bool
|
285
|
+
|
286
|
+
def deconstruct_keys: (Array[K] | nil) -> self
|
287
|
+
|
288
|
+
# Returns the default value, the value that would be returned by *[hsh](key)* if
|
289
|
+
# *key* did not exist in *hsh*. See also Hash::new and Hash#default=.
|
290
|
+
#
|
291
|
+
# h = Hash.new #=> {}
|
292
|
+
# h.default #=> nil
|
293
|
+
# h.default(2) #=> nil
|
294
|
+
#
|
295
|
+
# h = Hash.new("cat") #=> {}
|
296
|
+
# h.default #=> "cat"
|
297
|
+
# h.default(2) #=> "cat"
|
298
|
+
#
|
299
|
+
# h = Hash.new {|h,k| h[k] = k.to_i*10} #=> {}
|
300
|
+
# h.default #=> nil
|
301
|
+
# h.default(2) #=> 20
|
302
|
+
#
|
303
|
+
def default: (?K arg0) -> V?
|
304
|
+
|
305
|
+
# Sets the default value, the value returned for a key that does not exist in
|
306
|
+
# the hash. It is not possible to set the default to a Proc that will be
|
307
|
+
# executed on each key lookup.
|
308
|
+
#
|
309
|
+
# h = { "a" => 100, "b" => 200 }
|
310
|
+
# h.default = "Go fish"
|
311
|
+
# h["a"] #=> 100
|
312
|
+
# h["z"] #=> "Go fish"
|
313
|
+
# # This doesn't do what you might hope...
|
314
|
+
# h.default = proc do |hash, key|
|
315
|
+
# hash[key] = key + key
|
316
|
+
# end
|
317
|
+
# h[2] #=> #<Proc:0x401b3948@-:6>
|
318
|
+
# h["cat"] #=> #<Proc:0x401b3948@-:6>
|
319
|
+
#
|
320
|
+
def default=: (V arg0) -> V
|
321
|
+
|
322
|
+
# If Hash::new was invoked with a block, return that block, otherwise return
|
323
|
+
# `nil`.
|
324
|
+
#
|
325
|
+
# h = Hash.new {|h,k| h[k] = k*k } #=> {}
|
326
|
+
# p = h.default_proc #=> #<Proc:0x401b3d08@-:1>
|
327
|
+
# a = [] #=> []
|
328
|
+
# p.call(a, 2)
|
329
|
+
# a #=> [nil, nil, 4]
|
330
|
+
#
|
331
|
+
def default_proc: () -> (Proc | nil)
|
332
|
+
|
333
|
+
# Sets the default proc to be executed on each failed key lookup.
|
334
|
+
#
|
335
|
+
# h.default_proc = proc do |hash, key|
|
336
|
+
# hash[key] = key + key
|
337
|
+
# end
|
338
|
+
# h[2] #=> 4
|
339
|
+
# h["cat"] #=> "catcat"
|
340
|
+
#
|
341
|
+
def default_proc=: (Proc | _ToProc | nil) -> (Proc | _ToProc | nil)
|
342
|
+
|
343
|
+
# Deletes the key-value pair and returns the value from *hsh* whose key is equal
|
344
|
+
# to *key*. If the key is not found, it returns *nil*. If the optional code
|
345
|
+
# block is given and the key is not found, pass in the key and return the result
|
346
|
+
# of *block*.
|
347
|
+
#
|
348
|
+
# h = { "a" => 100, "b" => 200 }
|
349
|
+
# h.delete("a") #=> 100
|
350
|
+
# h.delete("z") #=> nil
|
351
|
+
# h.delete("z") { |el| "#{el} not found" } #=> "z not found"
|
352
|
+
#
|
353
|
+
def delete: (K arg0) -> V?
|
354
|
+
| [U] (K arg0) { (K arg0) -> U } -> (U | V)
|
355
|
+
|
356
|
+
# Deletes every key-value pair from *hsh* for which *block* evaluates to `true`.
|
357
|
+
#
|
358
|
+
# If no block is given, an enumerator is returned instead.
|
359
|
+
#
|
360
|
+
# h = { "a" => 100, "b" => 200, "c" => 300 }
|
361
|
+
# h.delete_if {|key, value| key >= "b" } #=> {"a"=>100}
|
362
|
+
#
|
363
|
+
def delete_if: () { (K arg0, V arg1) -> bool } -> self
|
364
|
+
| () -> ::Enumerator[[ K, V ], self]
|
365
|
+
|
366
|
+
# Extracts the nested value specified by the sequence of *key* objects by
|
367
|
+
# calling `dig` at each step, returning `nil` if any intermediate step is `nil`.
|
368
|
+
#
|
369
|
+
# h = { foo: {bar: {baz: 1}}}
|
370
|
+
#
|
371
|
+
# h.dig(:foo, :bar, :baz) #=> 1
|
372
|
+
# h.dig(:foo, :zot, :xyz) #=> nil
|
373
|
+
#
|
374
|
+
# g = { foo: [10, 11, 12] }
|
375
|
+
# g.dig(:foo, 1) #=> 11
|
376
|
+
# g.dig(:foo, 1, 0) #=> TypeError: Integer does not have #dig method
|
377
|
+
# g.dig(:foo, :bar) #=> TypeError: no implicit conversion of Symbol into Integer
|
378
|
+
#
|
379
|
+
def dig: (*untyped) -> untyped
|
380
|
+
|
381
|
+
# Calls *block* once for each key in *hsh*, passing the key-value pair as
|
382
|
+
# parameters.
|
383
|
+
#
|
384
|
+
# If no block is given, an enumerator is returned instead.
|
385
|
+
#
|
386
|
+
# h = { "a" => 100, "b" => 200 }
|
387
|
+
# h.each {|key, value| puts "#{key} is #{value}" }
|
388
|
+
#
|
389
|
+
# *produces:*
|
390
|
+
#
|
391
|
+
# a is 100
|
392
|
+
# b is 200
|
393
|
+
#
|
394
|
+
def each: () { ([ K, V ] arg0) -> untyped } -> self
|
395
|
+
| () -> ::Enumerator[[ K, V ], self]
|
396
|
+
|
397
|
+
# Calls *block* once for each key in *hsh*, passing the key as a parameter.
|
398
|
+
#
|
399
|
+
# If no block is given, an enumerator is returned instead.
|
400
|
+
#
|
401
|
+
# h = { "a" => 100, "b" => 200 }
|
402
|
+
# h.each_key {|key| puts key }
|
403
|
+
#
|
404
|
+
# *produces:*
|
405
|
+
#
|
406
|
+
# a
|
407
|
+
# b
|
408
|
+
#
|
409
|
+
def each_key: () { (K arg0) -> untyped } -> ::Hash[K, V]
|
410
|
+
| () -> ::Enumerator[K, self]
|
411
|
+
|
412
|
+
# Calls *block* once for each key in *hsh*, passing the key-value pair as
|
413
|
+
# parameters.
|
414
|
+
#
|
415
|
+
# If no block is given, an enumerator is returned instead.
|
416
|
+
#
|
417
|
+
# h = { "a" => 100, "b" => 200 }
|
418
|
+
# h.each {|key, value| puts "#{key} is #{value}" }
|
419
|
+
#
|
420
|
+
# *produces:*
|
421
|
+
#
|
422
|
+
# a is 100
|
423
|
+
# b is 200
|
424
|
+
#
|
425
|
+
alias each_pair each
|
426
|
+
|
427
|
+
# Calls *block* once for each key in *hsh*, passing the value as a parameter.
|
428
|
+
#
|
429
|
+
# If no block is given, an enumerator is returned instead.
|
430
|
+
#
|
431
|
+
# h = { "a" => 100, "b" => 200 }
|
432
|
+
# h.each_value {|value| puts value }
|
433
|
+
#
|
434
|
+
# *produces:*
|
435
|
+
#
|
436
|
+
# 100
|
437
|
+
# 200
|
438
|
+
#
|
439
|
+
def each_value: () { (V arg0) -> untyped } -> self
|
440
|
+
| () -> ::Enumerator[V, self]
|
441
|
+
|
442
|
+
# Returns `true` if *hsh* contains no key-value pairs.
|
443
|
+
#
|
444
|
+
# {}.empty? #=> true
|
445
|
+
#
|
446
|
+
def empty?: () -> bool
|
447
|
+
|
448
|
+
# Returns `true` if *hash* and *other* are both hashes with the same content.
|
449
|
+
# The orders of each hashes are not compared.
|
450
|
+
#
|
451
|
+
def eql?: (untyped) -> bool
|
452
|
+
|
453
|
+
# Returns a value from the hash for the given key. If the key can't be found,
|
454
|
+
# there are several options: With no other arguments, it will raise a KeyError
|
455
|
+
# exception; if *default* is given, then that will be returned; if the optional
|
456
|
+
# code block is specified, then that will be run and its result returned.
|
457
|
+
#
|
458
|
+
# h = { "a" => 100, "b" => 200 }
|
459
|
+
# h.fetch("a") #=> 100
|
460
|
+
# h.fetch("z", "go fish") #=> "go fish"
|
461
|
+
# h.fetch("z") { |el| "go fish, #{el}"} #=> "go fish, z"
|
462
|
+
#
|
463
|
+
# The following example shows that an exception is raised if the key is not
|
464
|
+
# found and a default value is not supplied.
|
465
|
+
#
|
466
|
+
# h = { "a" => 100, "b" => 200 }
|
467
|
+
# h.fetch("z")
|
468
|
+
#
|
469
|
+
# *produces:*
|
470
|
+
#
|
471
|
+
# prog.rb:2:in `fetch': key not found (KeyError)
|
472
|
+
# from prog.rb:2
|
473
|
+
#
|
474
|
+
def fetch: (K arg0) -> V
|
475
|
+
| [X] (K arg0, X arg1) -> (V | X)
|
476
|
+
| [X] (K arg0) { (K arg0) -> X } -> (V | X)
|
477
|
+
|
478
|
+
# Returns an array containing the values associated with the given keys but also
|
479
|
+
# raises KeyError when one of keys can't be found. Also see Hash#values_at and
|
480
|
+
# Hash#fetch.
|
481
|
+
#
|
482
|
+
# h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
|
483
|
+
#
|
484
|
+
# h.fetch_values("cow", "cat") #=> ["bovine", "feline"]
|
485
|
+
# h.fetch_values("cow", "bird") # raises KeyError
|
486
|
+
# h.fetch_values("cow", "bird") { |k| k.upcase } #=> ["bovine", "BIRD"]
|
487
|
+
#
|
488
|
+
def fetch_values: (*K) -> Array[V]
|
489
|
+
| [X] (*K) { (K) -> X } -> (V | X)
|
490
|
+
|
491
|
+
# Returns a new hash consisting of entries for which the block returns true.
|
492
|
+
#
|
493
|
+
# If no block is given, an enumerator is returned instead.
|
494
|
+
#
|
495
|
+
# h = { "a" => 100, "b" => 200, "c" => 300 }
|
496
|
+
# h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300}
|
497
|
+
# h.select {|k,v| v < 200} #=> {"a" => 100}
|
498
|
+
#
|
499
|
+
# Hash#filter is an alias for Hash#select.
|
500
|
+
#
|
501
|
+
def filter: () { (K arg0, V arg1) -> bool } -> self
|
502
|
+
| () -> ::Enumerator[[ K, V ], self]
|
503
|
+
|
504
|
+
# Equivalent to Hash#keep_if, but returns `nil` if no changes were made.
|
505
|
+
#
|
506
|
+
# Hash#filter! is an alias for Hash#select!.
|
507
|
+
#
|
508
|
+
def filter!: () { (K arg0, V arg1) -> bool } -> self?
|
509
|
+
| () -> ::Enumerator[[ K, V ], self?]
|
510
|
+
|
511
|
+
# Returns a new array that is a one-dimensional flattening of this hash. That
|
512
|
+
# is, for every key or value that is an array, extract its elements into the new
|
513
|
+
# array. Unlike Array#flatten, this method does not flatten recursively by
|
514
|
+
# default. The optional *level* argument determines the level of recursion to
|
515
|
+
# flatten.
|
516
|
+
#
|
517
|
+
# a = {1=> "one", 2 => [2,"two"], 3 => "three"}
|
518
|
+
# a.flatten # => [1, "one", 2, [2, "two"], 3, "three"]
|
519
|
+
# a.flatten(2) # => [1, "one", 2, 2, "two", 3, "three"]
|
520
|
+
#
|
521
|
+
def flatten: () -> ::Array[K | V]
|
522
|
+
| (1 level) -> ::Array[K | V]
|
523
|
+
| (Integer level) -> Array[untyped]
|
524
|
+
|
525
|
+
# Returns `true` if the given key is present in *hsh*.
|
526
|
+
#
|
527
|
+
# h = { "a" => 100, "b" => 200 }
|
528
|
+
# h.has_key?("a") #=> true
|
529
|
+
# h.has_key?("z") #=> false
|
530
|
+
#
|
531
|
+
# Note that #include? and #member? do not test member equality using `==` as do
|
532
|
+
# other Enumerables.
|
533
|
+
#
|
534
|
+
# See also Enumerable#include?
|
535
|
+
#
|
536
|
+
def has_key?: (K arg0) -> bool
|
537
|
+
|
538
|
+
# Returns `true` if the given value is present for some key in *hsh*.
|
539
|
+
#
|
540
|
+
# h = { "a" => 100, "b" => 200 }
|
541
|
+
# h.value?(100) #=> true
|
542
|
+
# h.value?(999) #=> false
|
543
|
+
#
|
544
|
+
def has_value?: (V arg0) -> bool
|
545
|
+
|
546
|
+
# Compute a hash-code for this hash. Two hashes with the same content will have
|
547
|
+
# the same hash code (and will compare using `eql?`).
|
548
|
+
#
|
549
|
+
# See also Object#hash.
|
550
|
+
#
|
551
|
+
def hash: () -> Integer
|
552
|
+
|
553
|
+
# Returns `true` if the given key is present in *hsh*.
|
554
|
+
#
|
555
|
+
# h = { "a" => 100, "b" => 200 }
|
556
|
+
# h.has_key?("a") #=> true
|
557
|
+
# h.has_key?("z") #=> false
|
558
|
+
#
|
559
|
+
# Note that #include? and #member? do not test member equality using `==` as do
|
560
|
+
# other Enumerables.
|
561
|
+
#
|
562
|
+
# See also Enumerable#include?
|
563
|
+
#
|
564
|
+
alias include? has_key?
|
565
|
+
|
566
|
+
def index: (V) -> K?
|
567
|
+
|
568
|
+
# Return the contents of this hash as a string.
|
569
|
+
#
|
570
|
+
# h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
|
571
|
+
# h.to_s #=> "{\"c\"=>300, \"a\"=>100, \"d\"=>400}"
|
572
|
+
#
|
573
|
+
def inspect: () -> String
|
574
|
+
|
575
|
+
# Returns a new hash created by using *hsh*'s values as keys, and the keys as
|
576
|
+
# values. If a key with the same value already exists in the *hsh*, then the
|
577
|
+
# last one defined will be used, the earlier value(s) will be discarded.
|
578
|
+
#
|
579
|
+
# h = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 }
|
580
|
+
# h.invert #=> {0=>"a", 100=>"m", 200=>"d", 300=>"y"}
|
581
|
+
#
|
582
|
+
# If there is no key with the same value, Hash#invert is involutive.
|
583
|
+
#
|
584
|
+
# h = { a: 1, b: 3, c: 4 }
|
585
|
+
# h.invert.invert == h #=> true
|
586
|
+
#
|
587
|
+
# The condition, no key with the same value, can be tested by comparing the size
|
588
|
+
# of inverted hash.
|
589
|
+
#
|
590
|
+
# # no key with the same value
|
591
|
+
# h = { a: 1, b: 3, c: 4 }
|
592
|
+
# h.size == h.invert.size #=> true
|
593
|
+
#
|
594
|
+
# # two (or more) keys has the same value
|
595
|
+
# h = { a: 1, b: 3, c: 1 }
|
596
|
+
# h.size == h.invert.size #=> false
|
597
|
+
#
|
598
|
+
def invert: () -> ::Hash[V, K]
|
599
|
+
|
600
|
+
# Deletes every key-value pair from *hsh* for which *block* evaluates to
|
601
|
+
# `false`.
|
602
|
+
#
|
603
|
+
# If no block is given, an enumerator is returned instead.
|
604
|
+
#
|
605
|
+
# See also Hash#select!.
|
606
|
+
#
|
607
|
+
def keep_if: () { (K, V) -> bool } -> self
|
608
|
+
| () -> ::Enumerator[[ K, V ], self]
|
609
|
+
|
610
|
+
# Returns the key of an occurrence of a given value. If the value is not found,
|
611
|
+
# returns `nil`.
|
612
|
+
#
|
613
|
+
# h = { "a" => 100, "b" => 200, "c" => 300, "d" => 300 }
|
614
|
+
# h.key(200) #=> "b"
|
615
|
+
# h.key(300) #=> "c"
|
616
|
+
# h.key(999) #=> nil
|
617
|
+
#
|
618
|
+
alias key index
|
619
|
+
|
620
|
+
# Returns `true` if the given key is present in *hsh*.
|
621
|
+
#
|
622
|
+
# h = { "a" => 100, "b" => 200 }
|
623
|
+
# h.has_key?("a") #=> true
|
624
|
+
# h.has_key?("z") #=> false
|
625
|
+
#
|
626
|
+
# Note that #include? and #member? do not test member equality using `==` as do
|
627
|
+
# other Enumerables.
|
628
|
+
#
|
629
|
+
# See also Enumerable#include?
|
630
|
+
#
|
631
|
+
alias key? has_key?
|
632
|
+
|
633
|
+
# Returns a new array populated with the keys from this hash. See also
|
634
|
+
# Hash#values.
|
635
|
+
#
|
636
|
+
# h = { "a" => 100, "b" => 200, "c" => 300, "d" => 400 }
|
637
|
+
# h.keys #=> ["a", "b", "c", "d"]
|
638
|
+
#
|
639
|
+
def keys: () -> ::Array[K]
|
640
|
+
|
641
|
+
# Returns the number of key-value pairs in the hash.
|
642
|
+
#
|
643
|
+
# h = { "d" => 100, "a" => 200, "v" => 300, "e" => 400 }
|
644
|
+
# h.size #=> 4
|
645
|
+
# h.delete("a") #=> 200
|
646
|
+
# h.size #=> 3
|
647
|
+
# h.length #=> 3
|
648
|
+
#
|
649
|
+
# Hash#length is an alias for Hash#size.
|
650
|
+
#
|
651
|
+
def length: () -> Integer
|
652
|
+
|
653
|
+
# Returns `true` if the given key is present in *hsh*.
|
654
|
+
#
|
655
|
+
# h = { "a" => 100, "b" => 200 }
|
656
|
+
# h.has_key?("a") #=> true
|
657
|
+
# h.has_key?("z") #=> false
|
658
|
+
#
|
659
|
+
# Note that #include? and #member? do not test member equality using `==` as do
|
660
|
+
# other Enumerables.
|
661
|
+
#
|
662
|
+
# See also Enumerable#include?
|
663
|
+
#
|
664
|
+
alias member? has_key?
|
665
|
+
|
666
|
+
# Returns a new hash that combines the contents of the receiver and the contents
|
667
|
+
# of the given hashes.
|
668
|
+
#
|
669
|
+
# If no block is given, entries with duplicate keys are overwritten with the
|
670
|
+
# values from each `other_hash` successively, otherwise the value for each
|
671
|
+
# duplicate key is determined by calling the block with the key, its value in
|
672
|
+
# the receiver and its value in each `other_hash`.
|
673
|
+
#
|
674
|
+
# When called without any argument, returns a copy of the receiver.
|
675
|
+
#
|
676
|
+
# h1 = { "a" => 100, "b" => 200 }
|
677
|
+
# h2 = { "b" => 246, "c" => 300 }
|
678
|
+
# h3 = { "b" => 357, "d" => 400 }
|
679
|
+
# h1.merge #=> {"a"=>100, "b"=>200}
|
680
|
+
# h1.merge(h2) #=> {"a"=>100, "b"=>246, "c"=>300}
|
681
|
+
# h1.merge(h2, h3) #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
|
682
|
+
# h1.merge(h2) {|key, oldval, newval| newval - oldval}
|
683
|
+
# #=> {"a"=>100, "b"=>46, "c"=>300}
|
684
|
+
# h1.merge(h2, h3) {|key, oldval, newval| newval - oldval}
|
685
|
+
# #=> {"a"=>100, "b"=>311, "c"=>300, "d"=>400}
|
686
|
+
# h1 #=> {"a"=>100, "b"=>200}
|
687
|
+
#
|
688
|
+
def merge: [A, B] (*::Hash[A, B] other_hashes) -> ::Hash[A | K, B | V]
|
689
|
+
| [A, B, C] (*::Hash[A, B] other_hashes) { (K key, V oldval, B newval) -> (C) } -> ::Hash[A | K, B | V | C]
|
690
|
+
|
691
|
+
# Adds the contents of the given hashes to the receiver.
|
692
|
+
#
|
693
|
+
# If no block is given, entries with duplicate keys are overwritten with the
|
694
|
+
# values from each `other_hash` successively, otherwise the value for each
|
695
|
+
# duplicate key is determined by calling the block with the key, its value in
|
696
|
+
# the receiver and its value in each `other_hash`.
|
697
|
+
#
|
698
|
+
# h1 = { "a" => 100, "b" => 200 }
|
699
|
+
# h1.merge! #=> {"a"=>100, "b"=>200}
|
700
|
+
# h1 #=> {"a"=>100, "b"=>200}
|
701
|
+
#
|
702
|
+
# h1 = { "a" => 100, "b" => 200 }
|
703
|
+
# h2 = { "b" => 246, "c" => 300 }
|
704
|
+
# h1.merge!(h2) #=> {"a"=>100, "b"=>246, "c"=>300}
|
705
|
+
# h1 #=> {"a"=>100, "b"=>246, "c"=>300}
|
706
|
+
#
|
707
|
+
# h1 = { "a" => 100, "b" => 200 }
|
708
|
+
# h2 = { "b" => 246, "c" => 300 }
|
709
|
+
# h3 = { "b" => 357, "d" => 400 }
|
710
|
+
# h1.merge!(h2, h3)
|
711
|
+
# #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
|
712
|
+
# h1 #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
|
713
|
+
#
|
714
|
+
# h1 = { "a" => 100, "b" => 200 }
|
715
|
+
# h2 = { "b" => 246, "c" => 300 }
|
716
|
+
# h3 = { "b" => 357, "d" => 400 }
|
717
|
+
# h1.merge!(h2, h3) {|key, v1, v2| v1 }
|
718
|
+
# #=> {"a"=>100, "b"=>200, "c"=>300, "d"=>400}
|
719
|
+
# h1 #=> {"a"=>100, "b"=>200, "c"=>300, "d"=>400}
|
720
|
+
#
|
721
|
+
# Hash#update is an alias for Hash#merge!.
|
722
|
+
#
|
723
|
+
def merge!: [A, B] (*::Hash[A, B] other_hashes) -> ::Hash[A | K, B | V]
|
724
|
+
| [A, B, C] (*::Hash[A, B] other_hashes) { (K key, V oldval, B newval) -> (C) } -> ::Hash[A | K, B | V | C]
|
725
|
+
|
726
|
+
# Searches through the hash comparing *obj* with the value using `==`. Returns
|
727
|
+
# the first key-value pair (two-element array) that matches. See also
|
728
|
+
# Array#rassoc.
|
729
|
+
#
|
730
|
+
# a = {1=> "one", 2 => "two", 3 => "three", "ii" => "two"}
|
731
|
+
# a.rassoc("two") #=> [2, "two"]
|
732
|
+
# a.rassoc("four") #=> nil
|
733
|
+
#
|
734
|
+
def rassoc: (V) -> [K, V]?
|
735
|
+
|
736
|
+
# Rebuilds the hash based on the current hash values for each key. If values of
|
737
|
+
# key objects have changed since they were inserted, this method will reindex
|
738
|
+
# *hsh*. If Hash#rehash is called while an iterator is traversing the hash, a
|
739
|
+
# RuntimeError will be raised in the iterator.
|
740
|
+
#
|
741
|
+
# a = [ "a", "b" ]
|
742
|
+
# c = [ "c", "d" ]
|
743
|
+
# h = { a => 100, c => 300 }
|
744
|
+
# h[a] #=> 100
|
745
|
+
# a[0] = "z"
|
746
|
+
# h[a] #=> nil
|
747
|
+
# h.rehash #=> {["z", "b"]=>100, ["c", "d"]=>300}
|
748
|
+
# h[a] #=> 100
|
749
|
+
#
|
750
|
+
def rehash: () -> self
|
751
|
+
|
752
|
+
# Returns a new hash consisting of entries for which the block returns false.
|
753
|
+
#
|
754
|
+
# If no block is given, an enumerator is returned instead.
|
755
|
+
#
|
756
|
+
# h = { "a" => 100, "b" => 200, "c" => 300 }
|
757
|
+
# h.reject {|k,v| k < "b"} #=> {"b" => 200, "c" => 300}
|
758
|
+
# h.reject {|k,v| v > 100} #=> {"a" => 100}
|
759
|
+
#
|
760
|
+
def reject: () -> ::Enumerator[[ K, V ], self]
|
761
|
+
| () { (K arg0, V arg1) -> bool } -> self
|
762
|
+
|
763
|
+
# Equivalent to Hash#delete_if, but returns `nil` if no changes were made.
|
764
|
+
#
|
765
|
+
def reject!: () -> ::Enumerator[[ K, V ], self?]
|
766
|
+
| () { (K arg0, V arg1) -> bool } -> self?
|
767
|
+
|
768
|
+
# Replaces the contents of *hsh* with the contents of *other_hash*.
|
769
|
+
#
|
770
|
+
# h = { "a" => 100, "b" => 200 }
|
771
|
+
# h.replace({ "c" => 300, "d" => 400 }) #=> {"c"=>300, "d"=>400}
|
772
|
+
#
|
773
|
+
def replace: [A, B] (Hash[A, B] | _ToHash[A, B]) -> Hash[A, B]
|
774
|
+
|
775
|
+
# Returns a new hash consisting of entries for which the block returns true.
|
776
|
+
#
|
777
|
+
# If no block is given, an enumerator is returned instead.
|
778
|
+
#
|
779
|
+
# h = { "a" => 100, "b" => 200, "c" => 300 }
|
780
|
+
# h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300}
|
781
|
+
# h.select {|k,v| v < 200} #=> {"a" => 100}
|
782
|
+
#
|
783
|
+
# Hash#filter is an alias for Hash#select.
|
784
|
+
#
|
785
|
+
alias select filter
|
786
|
+
|
787
|
+
# Equivalent to Hash#keep_if, but returns `nil` if no changes were made.
|
788
|
+
#
|
789
|
+
# Hash#filter! is an alias for Hash#select!.
|
790
|
+
#
|
791
|
+
alias select! filter!
|
792
|
+
|
793
|
+
# Removes a key-value pair from *hsh* and returns it as the two-item array `[`
|
794
|
+
# *key, value* `]`, or the hash's default value if the hash is empty.
|
795
|
+
#
|
796
|
+
# h = { 1 => "a", 2 => "b", 3 => "c" }
|
797
|
+
# h.shift #=> [1, "a"]
|
798
|
+
# h #=> {2=>"b", 3=>"c"}
|
799
|
+
#
|
800
|
+
def shift: () -> [ K, V ]?
|
801
|
+
|
802
|
+
# Returns the number of key-value pairs in the hash.
|
803
|
+
#
|
804
|
+
# h = { "d" => 100, "a" => 200, "v" => 300, "e" => 400 }
|
805
|
+
# h.size #=> 4
|
806
|
+
# h.delete("a") #=> 200
|
807
|
+
# h.size #=> 3
|
808
|
+
# h.length #=> 3
|
809
|
+
#
|
810
|
+
# Hash#length is an alias for Hash#size.
|
811
|
+
#
|
812
|
+
alias size length
|
813
|
+
|
814
|
+
# Returns a hash containing only the given keys and their values.
|
815
|
+
#
|
816
|
+
# h = { a: 100, b: 200, c: 300 }
|
817
|
+
# h.slice(:a) #=> {:a=>100}
|
818
|
+
# h.slice(:b, :c, :d) #=> {:b=>200, :c=>300}
|
819
|
+
#
|
820
|
+
def slice: (*K) -> self
|
821
|
+
|
822
|
+
# ## Element Assignment
|
823
|
+
#
|
824
|
+
# Associates the value given by `value` with the key given by `key`.
|
825
|
+
#
|
826
|
+
# h = { "a" => 100, "b" => 200 }
|
827
|
+
# h["a"] = 9
|
828
|
+
# h["c"] = 4
|
829
|
+
# h #=> {"a"=>9, "b"=>200, "c"=>4}
|
830
|
+
# h.store("d", 42) #=> 42
|
831
|
+
# h #=> {"a"=>9, "b"=>200, "c"=>4, "d"=>42}
|
832
|
+
#
|
833
|
+
# `key` should not have its value changed while it is in use as a key (an
|
834
|
+
# `unfrozen String` passed as a key will be duplicated and frozen).
|
835
|
+
#
|
836
|
+
# a = "a"
|
837
|
+
# b = "b".freeze
|
838
|
+
# h = { a => 100, b => 200 }
|
839
|
+
# h.key(100).equal? a #=> false
|
840
|
+
# h.key(200).equal? b #=> true
|
841
|
+
#
|
842
|
+
alias store []=
|
843
|
+
|
844
|
+
# Converts *hsh* to a nested array of `[` *key, value* `]` arrays.
|
845
|
+
#
|
846
|
+
# h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
|
847
|
+
# h.to_a #=> [["c", 300], ["a", 100], ["d", 400]]
|
848
|
+
#
|
849
|
+
def to_a: () -> ::Array[[ K, V ]]
|
850
|
+
|
851
|
+
# Returns `self`. If called on a subclass of Hash, converts the receiver to a
|
852
|
+
# Hash object.
|
853
|
+
#
|
854
|
+
# If a block is given, the results of the block on each pair of the receiver
|
855
|
+
# will be used as pairs.
|
856
|
+
#
|
857
|
+
def to_h: () -> Hash[K, V]
|
858
|
+
| [A, B] () { (K, V) -> [ A, B ] } -> Hash[A, B]
|
859
|
+
|
860
|
+
# Returns `self`.
|
861
|
+
#
|
862
|
+
def to_hash: () -> ::Hash[K, V]
|
863
|
+
|
864
|
+
# Returns a Proc which maps keys to values.
|
865
|
+
#
|
866
|
+
# h = {a:1, b:2}
|
867
|
+
# hp = h.to_proc
|
868
|
+
# hp.call(:a) #=> 1
|
869
|
+
# hp.call(:b) #=> 2
|
870
|
+
# hp.call(:c) #=> nil
|
871
|
+
# [:a, :b, :c].map(&h) #=> [1, 2, nil]
|
872
|
+
#
|
873
|
+
def to_proc: () -> ^(K) -> V?
|
874
|
+
|
875
|
+
alias to_s inspect
|
876
|
+
|
877
|
+
# Returns a new hash with the results of running the block once for every key.
|
878
|
+
# This method does not change the values.
|
879
|
+
#
|
880
|
+
# h = { a: 1, b: 2, c: 3 }
|
881
|
+
# h.transform_keys {|k| k.to_s } #=> { "a" => 1, "b" => 2, "c" => 3 }
|
882
|
+
# h.transform_keys(&:to_s) #=> { "a" => 1, "b" => 2, "c" => 3 }
|
883
|
+
# h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
|
884
|
+
# #=> { "a.0" => 1, "b.1" => 2, "c.2" => 3 }
|
885
|
+
#
|
886
|
+
# If no block is given, an enumerator is returned instead.
|
887
|
+
#
|
888
|
+
def transform_keys: () -> Enumerator[K, Hash[untyped, V]]
|
889
|
+
| [A] () { (K) -> A } -> Hash[A, V]
|
890
|
+
|
891
|
+
# Invokes the given block once for each key in *hsh*, replacing it with the new
|
892
|
+
# key returned by the block, and then returns *hsh*. This method does not change
|
893
|
+
# the values.
|
894
|
+
#
|
895
|
+
# h = { a: 1, b: 2, c: 3 }
|
896
|
+
# h.transform_keys! {|k| k.to_s } #=> { "a" => 1, "b" => 2, "c" => 3 }
|
897
|
+
# h.transform_keys!(&:to_sym) #=> { a: 1, b: 2, c: 3 }
|
898
|
+
# h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }
|
899
|
+
# #=> { "a.0" => 1, "b.1" => 2, "c.2" => 3 }
|
900
|
+
#
|
901
|
+
# If no block is given, an enumerator is returned instead.
|
902
|
+
#
|
903
|
+
def transform_keys!: () -> Enumerator[K, Hash[untyped, V]]
|
904
|
+
| () { (K) -> K } -> Hash[K, V]
|
905
|
+
|
906
|
+
# Returns a new hash with the results of running the block once for every value.
|
907
|
+
# This method does not change the keys.
|
908
|
+
#
|
909
|
+
# h = { a: 1, b: 2, c: 3 }
|
910
|
+
# h.transform_values {|v| v * v + 1 } #=> { a: 2, b: 5, c: 10 }
|
911
|
+
# h.transform_values(&:to_s) #=> { a: "1", b: "2", c: "3" }
|
912
|
+
# h.transform_values.with_index {|v, i| "#{v}.#{i}" }
|
913
|
+
# #=> { a: "1.0", b: "2.1", c: "3.2" }
|
914
|
+
#
|
915
|
+
# If no block is given, an enumerator is returned instead.
|
916
|
+
#
|
917
|
+
def transform_values: () -> Enumerator[K, Hash[K, untyped]]
|
918
|
+
| [A] () { (V) -> A } -> Hash[K, A]
|
919
|
+
|
920
|
+
# Invokes the given block once for each value in *hsh*, replacing it with the
|
921
|
+
# new value returned by the block, and then returns *hsh*. This method does not
|
922
|
+
# change the keys.
|
923
|
+
#
|
924
|
+
# h = { a: 1, b: 2, c: 3 }
|
925
|
+
# h.transform_values! {|v| v * v + 1 } #=> { a: 2, b: 5, c: 10 }
|
926
|
+
# h.transform_values!(&:to_s) #=> { a: "2", b: "5", c: "10" }
|
927
|
+
# h.transform_values!.with_index {|v, i| "#{v}.#{i}" }
|
928
|
+
# #=> { a: "2.0", b: "5.1", c: "10.2" }
|
929
|
+
#
|
930
|
+
# If no block is given, an enumerator is returned instead.
|
931
|
+
#
|
932
|
+
def transform_values!: () -> Enumerator[K, Hash[K, untyped]]
|
933
|
+
| () { (V) -> V } -> Hash[K, V]
|
934
|
+
|
935
|
+
# Adds the contents of the given hashes to the receiver.
|
936
|
+
#
|
937
|
+
# If no block is given, entries with duplicate keys are overwritten with the
|
938
|
+
# values from each `other_hash` successively, otherwise the value for each
|
939
|
+
# duplicate key is determined by calling the block with the key, its value in
|
940
|
+
# the receiver and its value in each `other_hash`.
|
941
|
+
#
|
942
|
+
# h1 = { "a" => 100, "b" => 200 }
|
943
|
+
# h1.merge! #=> {"a"=>100, "b"=>200}
|
944
|
+
# h1 #=> {"a"=>100, "b"=>200}
|
945
|
+
#
|
946
|
+
# h1 = { "a" => 100, "b" => 200 }
|
947
|
+
# h2 = { "b" => 246, "c" => 300 }
|
948
|
+
# h1.merge!(h2) #=> {"a"=>100, "b"=>246, "c"=>300}
|
949
|
+
# h1 #=> {"a"=>100, "b"=>246, "c"=>300}
|
950
|
+
#
|
951
|
+
# h1 = { "a" => 100, "b" => 200 }
|
952
|
+
# h2 = { "b" => 246, "c" => 300 }
|
953
|
+
# h3 = { "b" => 357, "d" => 400 }
|
954
|
+
# h1.merge!(h2, h3)
|
955
|
+
# #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
|
956
|
+
# h1 #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
|
957
|
+
#
|
958
|
+
# h1 = { "a" => 100, "b" => 200 }
|
959
|
+
# h2 = { "b" => 246, "c" => 300 }
|
960
|
+
# h3 = { "b" => 357, "d" => 400 }
|
961
|
+
# h1.merge!(h2, h3) {|key, v1, v2| v1 }
|
962
|
+
# #=> {"a"=>100, "b"=>200, "c"=>300, "d"=>400}
|
963
|
+
# h1 #=> {"a"=>100, "b"=>200, "c"=>300, "d"=>400}
|
964
|
+
#
|
965
|
+
# Hash#update is an alias for Hash#merge!.
|
966
|
+
#
|
967
|
+
alias update merge!
|
968
|
+
|
969
|
+
# Returns `true` if the given value is present for some key in *hsh*.
|
970
|
+
#
|
971
|
+
# h = { "a" => 100, "b" => 200 }
|
972
|
+
# h.value?(100) #=> true
|
973
|
+
# h.value?(999) #=> false
|
974
|
+
#
|
975
|
+
alias value? has_value?
|
976
|
+
|
977
|
+
# Returns a new array populated with the values from *hsh*. See also Hash#keys.
|
978
|
+
#
|
979
|
+
# h = { "a" => 100, "b" => 200, "c" => 300 }
|
980
|
+
# h.values #=> [100, 200, 300]
|
981
|
+
#
|
982
|
+
def values: () -> ::Array[V]
|
983
|
+
|
984
|
+
# Return an array containing the values associated with the given keys. Also see
|
985
|
+
# Hash.select.
|
986
|
+
#
|
987
|
+
# h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
|
988
|
+
# h.values_at("cow", "cat") #=> ["bovine", "feline"]
|
989
|
+
#
|
990
|
+
def values_at: (*K arg0) -> ::Array[V?]
|
991
|
+
|
992
|
+
private
|
993
|
+
|
994
|
+
# Returns a new, empty hash. If this hash is subsequently accessed by a key that
|
995
|
+
# doesn't correspond to a hash entry, the value returned depends on the style of
|
996
|
+
# `new` used to create the hash. In the first form, the access returns `nil`. If
|
997
|
+
# *obj* is specified, this single object will be used for all *default values*.
|
998
|
+
# If a block is specified, it will be called with the hash object and the key,
|
999
|
+
# and should return the default value. It is the block's responsibility to store
|
1000
|
+
# the value in the hash if required.
|
1001
|
+
#
|
1002
|
+
# h = Hash.new("Go Fish")
|
1003
|
+
# h["a"] = 100
|
1004
|
+
# h["b"] = 200
|
1005
|
+
# h["a"] #=> 100
|
1006
|
+
# h["c"] #=> "Go Fish"
|
1007
|
+
# # The following alters the single default object
|
1008
|
+
# h["c"].upcase! #=> "GO FISH"
|
1009
|
+
# h["d"] #=> "GO FISH"
|
1010
|
+
# h.keys #=> ["a", "b"]
|
1011
|
+
#
|
1012
|
+
# # While this creates a new default object each time
|
1013
|
+
# h = Hash.new { |hash, key| hash[key] = "Go Fish: #{key}" }
|
1014
|
+
# h["c"] #=> "Go Fish: c"
|
1015
|
+
# h["c"].upcase! #=> "GO FISH: C"
|
1016
|
+
# h["d"] #=> "Go Fish: d"
|
1017
|
+
# h.keys #=> ["c", "d"]
|
1018
|
+
#
|
1019
|
+
incompatible def initialize: () -> void
|
1020
|
+
| (untyped default) -> void
|
1021
|
+
| [A, B] () { (Hash[A, B] hash, A key) -> B } -> void
|
1022
|
+
|
1023
|
+
# Replaces the contents of *hsh* with the contents of *other_hash*.
|
1024
|
+
#
|
1025
|
+
# h = { "a" => 100, "b" => 200 }
|
1026
|
+
# h.replace({ "c" => 300, "d" => 400 }) #=> {"c"=>300, "d"=>400}
|
1027
|
+
#
|
1028
|
+
def initialize_copy: (self object) -> self
|
1029
|
+
end
|