rbs-relaxed 3.9.0.1
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/dependabot.yml +22 -0
- data/.github/workflows/comments.yml +35 -0
- data/.github/workflows/dependabot.yml +30 -0
- data/.github/workflows/ruby.yml +82 -0
- data/.github/workflows/typecheck.yml +38 -0
- data/.github/workflows/windows.yml +43 -0
- data/.gitignore +23 -0
- data/.rubocop.yml +68 -0
- data/BSDL +22 -0
- data/CHANGELOG.md +1868 -0
- data/COPYING +56 -0
- data/README.md +203 -0
- data/Rakefile +417 -0
- data/Steepfile +44 -0
- data/config.yml +313 -0
- data/core/array.rbs +4062 -0
- data/core/basic_object.rbs +375 -0
- data/core/binding.rbs +150 -0
- data/core/builtin.rbs +277 -0
- data/core/class.rbs +220 -0
- data/core/comparable.rbs +171 -0
- data/core/complex.rbs +786 -0
- data/core/constants.rbs +96 -0
- data/core/data.rbs +415 -0
- data/core/dir.rbs +981 -0
- data/core/encoding.rbs +1371 -0
- data/core/enumerable.rbs +2405 -0
- data/core/enumerator/product.rbs +92 -0
- data/core/enumerator.rbs +630 -0
- data/core/env.rbs +6 -0
- data/core/errno.rbs +673 -0
- data/core/errors.rbs +760 -0
- data/core/exception.rbs +485 -0
- data/core/false_class.rbs +82 -0
- data/core/fiber.rbs +550 -0
- data/core/fiber_error.rbs +11 -0
- data/core/file.rbs +2936 -0
- data/core/file_test.rbs +331 -0
- data/core/float.rbs +1151 -0
- data/core/gc.rbs +644 -0
- data/core/global_variables.rbs +184 -0
- data/core/hash.rbs +1861 -0
- data/core/integer.rbs +1413 -0
- data/core/io/buffer.rbs +984 -0
- data/core/io/wait.rbs +70 -0
- data/core/io.rbs +3406 -0
- data/core/kernel.rbs +3096 -0
- data/core/marshal.rbs +207 -0
- data/core/match_data.rbs +635 -0
- data/core/math.rbs +729 -0
- data/core/method.rbs +386 -0
- data/core/module.rbs +1704 -0
- data/core/nil_class.rbs +209 -0
- data/core/numeric.rbs +818 -0
- data/core/object.rbs +110 -0
- data/core/object_space/weak_key_map.rbs +166 -0
- data/core/object_space.rbs +190 -0
- data/core/proc.rbs +868 -0
- data/core/process.rbs +2296 -0
- data/core/ractor.rbs +1068 -0
- data/core/random.rbs +237 -0
- data/core/range.rbs +1107 -0
- data/core/rational.rbs +531 -0
- data/core/rb_config.rbs +88 -0
- data/core/rbs/unnamed/argf.rbs +1229 -0
- data/core/rbs/unnamed/env_class.rbs +1209 -0
- data/core/rbs/unnamed/random.rbs +293 -0
- data/core/refinement.rbs +59 -0
- data/core/regexp.rbs +1930 -0
- data/core/ruby_vm.rbs +765 -0
- data/core/rubygems/basic_specification.rbs +6 -0
- data/core/rubygems/config_file.rbs +38 -0
- data/core/rubygems/dependency_installer.rbs +6 -0
- data/core/rubygems/errors.rbs +176 -0
- data/core/rubygems/installer.rbs +15 -0
- data/core/rubygems/path_support.rbs +6 -0
- data/core/rubygems/platform.rbs +7 -0
- data/core/rubygems/request_set.rbs +49 -0
- data/core/rubygems/requirement.rbs +148 -0
- data/core/rubygems/rubygems.rbs +1171 -0
- data/core/rubygems/source_list.rbs +15 -0
- data/core/rubygems/specification.rbs +23 -0
- data/core/rubygems/stream_ui.rbs +5 -0
- data/core/rubygems/uninstaller.rbs +10 -0
- data/core/rubygems/version.rbs +294 -0
- data/core/set.rbs +621 -0
- data/core/signal.rbs +100 -0
- data/core/string.rbs +3583 -0
- data/core/struct.rbs +667 -0
- data/core/symbol.rbs +475 -0
- data/core/thread.rbs +1765 -0
- data/core/thread_group.rbs +79 -0
- data/core/time.rbs +1762 -0
- data/core/trace_point.rbs +477 -0
- data/core/true_class.rbs +98 -0
- data/core/unbound_method.rbs +329 -0
- data/core/warning.rbs +87 -0
- data/docs/CONTRIBUTING.md +106 -0
- data/docs/architecture.md +110 -0
- data/docs/collection.md +192 -0
- data/docs/data_and_struct.md +86 -0
- data/docs/gem.md +57 -0
- data/docs/rbs_by_example.md +309 -0
- data/docs/repo.md +125 -0
- data/docs/sigs.md +167 -0
- data/docs/stdlib.md +147 -0
- data/docs/syntax.md +910 -0
- data/docs/tools.md +17 -0
- data/exe/rbs +7 -0
- data/ext/rbs_extension/extconf.rb +15 -0
- data/ext/rbs_extension/lexer.c +2728 -0
- data/ext/rbs_extension/lexer.h +179 -0
- data/ext/rbs_extension/lexer.re +147 -0
- data/ext/rbs_extension/lexstate.c +175 -0
- data/ext/rbs_extension/location.c +325 -0
- data/ext/rbs_extension/location.h +85 -0
- data/ext/rbs_extension/main.c +33 -0
- data/ext/rbs_extension/parser.c +2973 -0
- data/ext/rbs_extension/parser.h +18 -0
- data/ext/rbs_extension/parserstate.c +397 -0
- data/ext/rbs_extension/parserstate.h +163 -0
- data/ext/rbs_extension/rbs_extension.h +31 -0
- data/ext/rbs_extension/unescape.c +32 -0
- data/goodcheck.yml +91 -0
- data/include/rbs/constants.h +82 -0
- data/include/rbs/ruby_objs.h +72 -0
- data/include/rbs/util/rbs_constant_pool.h +219 -0
- data/include/rbs.h +7 -0
- data/lib/rbs/ancestor_graph.rb +92 -0
- data/lib/rbs/annotate/annotations.rb +199 -0
- data/lib/rbs/annotate/formatter.rb +92 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +400 -0
- data/lib/rbs/annotate/rdoc_source.rb +131 -0
- data/lib/rbs/annotate.rb +8 -0
- data/lib/rbs/ast/annotation.rb +29 -0
- data/lib/rbs/ast/comment.rb +29 -0
- data/lib/rbs/ast/declarations.rb +467 -0
- data/lib/rbs/ast/directives.rb +49 -0
- data/lib/rbs/ast/members.rb +451 -0
- data/lib/rbs/ast/type_param.rb +225 -0
- data/lib/rbs/ast/visitor.rb +137 -0
- data/lib/rbs/buffer.rb +67 -0
- data/lib/rbs/builtin_names.rb +58 -0
- data/lib/rbs/cli/colored_io.rb +48 -0
- data/lib/rbs/cli/diff.rb +83 -0
- data/lib/rbs/cli/validate.rb +357 -0
- data/lib/rbs/cli.rb +1223 -0
- data/lib/rbs/collection/cleaner.rb +38 -0
- data/lib/rbs/collection/config/lockfile.rb +92 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +218 -0
- data/lib/rbs/collection/config.rb +81 -0
- data/lib/rbs/collection/installer.rb +32 -0
- data/lib/rbs/collection/sources/base.rb +14 -0
- data/lib/rbs/collection/sources/git.rb +258 -0
- data/lib/rbs/collection/sources/local.rb +81 -0
- data/lib/rbs/collection/sources/rubygems.rb +48 -0
- data/lib/rbs/collection/sources/stdlib.rb +50 -0
- data/lib/rbs/collection/sources.rb +38 -0
- data/lib/rbs/collection.rb +16 -0
- data/lib/rbs/constant.rb +28 -0
- data/lib/rbs/definition.rb +401 -0
- data/lib/rbs/definition_builder/ancestor_builder.rb +620 -0
- data/lib/rbs/definition_builder/method_builder.rb +254 -0
- data/lib/rbs/definition_builder.rb +845 -0
- data/lib/rbs/diff.rb +125 -0
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +829 -0
- data/lib/rbs/environment_loader.rb +173 -0
- data/lib/rbs/environment_walker.rb +155 -0
- data/lib/rbs/errors.rb +645 -0
- data/lib/rbs/factory.rb +18 -0
- data/lib/rbs/file_finder.rb +28 -0
- data/lib/rbs/location_aux.rb +138 -0
- data/lib/rbs/locator.rb +243 -0
- data/lib/rbs/method_type.rb +143 -0
- data/lib/rbs/namespace.rb +125 -0
- data/lib/rbs/parser/lex_result.rb +15 -0
- data/lib/rbs/parser/token.rb +23 -0
- data/lib/rbs/parser_aux.rb +114 -0
- data/lib/rbs/prototype/helpers.rb +140 -0
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +840 -0
- data/lib/rbs/prototype/rbi.rb +641 -0
- data/lib/rbs/prototype/runtime/helpers.rb +59 -0
- data/lib/rbs/prototype/runtime/reflection.rb +19 -0
- data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
- data/lib/rbs/prototype/runtime.rb +667 -0
- data/lib/rbs/repository.rb +127 -0
- data/lib/rbs/resolver/constant_resolver.rb +219 -0
- data/lib/rbs/resolver/type_name_resolver.rb +91 -0
- data/lib/rbs/sorter.rb +198 -0
- data/lib/rbs/substitution.rb +83 -0
- data/lib/rbs/subtractor.rb +201 -0
- data/lib/rbs/test/errors.rb +80 -0
- data/lib/rbs/test/guaranteed.rb +30 -0
- data/lib/rbs/test/hook.rb +212 -0
- data/lib/rbs/test/observer.rb +19 -0
- data/lib/rbs/test/setup.rb +84 -0
- data/lib/rbs/test/setup_helper.rb +50 -0
- data/lib/rbs/test/tester.rb +167 -0
- data/lib/rbs/test/type_check.rb +435 -0
- data/lib/rbs/test.rb +112 -0
- data/lib/rbs/type_alias_dependency.rb +100 -0
- data/lib/rbs/type_alias_regularity.rb +126 -0
- data/lib/rbs/type_name.rb +109 -0
- data/lib/rbs/types.rb +1596 -0
- data/lib/rbs/unit_test/convertibles.rb +176 -0
- data/lib/rbs/unit_test/spy.rb +138 -0
- data/lib/rbs/unit_test/type_assertions.rb +347 -0
- data/lib/rbs/unit_test/with_aliases.rb +143 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/validator.rb +186 -0
- data/lib/rbs/variance_calculator.rb +189 -0
- data/lib/rbs/vendorer.rb +71 -0
- data/lib/rbs/version.rb +5 -0
- data/lib/rbs/writer.rb +424 -0
- data/lib/rbs.rb +94 -0
- data/lib/rdoc/discover.rb +20 -0
- data/lib/rdoc_plugin/parser.rb +163 -0
- data/rbs-relaxed.gemspec +48 -0
- data/schema/annotation.json +14 -0
- data/schema/comment.json +26 -0
- data/schema/decls.json +326 -0
- data/schema/function.json +87 -0
- data/schema/location.json +56 -0
- data/schema/members.json +266 -0
- data/schema/methodType.json +50 -0
- data/schema/typeParam.json +36 -0
- data/schema/types.json +317 -0
- data/sig/ancestor_builder.rbs +163 -0
- data/sig/ancestor_graph.rbs +60 -0
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +82 -0
- data/sig/annotate/rdoc_source.rbs +30 -0
- data/sig/annotation.rbs +27 -0
- data/sig/buffer.rbs +32 -0
- data/sig/builtin_names.rbs +44 -0
- data/sig/cli/colored_io.rbs +15 -0
- data/sig/cli/diff.rbs +21 -0
- data/sig/cli/validate.rbs +43 -0
- data/sig/cli.rbs +87 -0
- data/sig/collection/cleaner.rbs +13 -0
- data/sig/collection/config/lockfile.rbs +74 -0
- data/sig/collection/config/lockfile_generator.rbs +66 -0
- data/sig/collection/config.rbs +46 -0
- data/sig/collection/installer.rbs +17 -0
- data/sig/collection/sources.rbs +214 -0
- data/sig/collection.rbs +4 -0
- data/sig/comment.rbs +26 -0
- data/sig/constant.rbs +21 -0
- data/sig/declarations.rbs +267 -0
- data/sig/definition.rbs +173 -0
- data/sig/definition_builder.rbs +165 -0
- data/sig/diff.rbs +28 -0
- data/sig/directives.rbs +77 -0
- data/sig/environment.rbs +279 -0
- data/sig/environment_loader.rbs +111 -0
- data/sig/environment_walker.rbs +65 -0
- data/sig/errors.rbs +405 -0
- data/sig/factory.rbs +5 -0
- data/sig/file_finder.rbs +28 -0
- data/sig/location.rbs +110 -0
- data/sig/locator.rbs +58 -0
- data/sig/manifest.yaml +7 -0
- data/sig/members.rbs +258 -0
- data/sig/method_builder.rbs +84 -0
- data/sig/method_types.rbs +58 -0
- data/sig/namespace.rbs +146 -0
- data/sig/parser.rbs +100 -0
- data/sig/prototype/helpers.rbs +27 -0
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/prototype/rb.rbs +96 -0
- data/sig/prototype/rbi.rbs +75 -0
- data/sig/prototype/runtime.rbs +182 -0
- data/sig/rbs.rbs +21 -0
- data/sig/rdoc/rbs.rbs +67 -0
- data/sig/repository.rbs +85 -0
- data/sig/resolver/constant_resolver.rbs +92 -0
- data/sig/resolver/context.rbs +34 -0
- data/sig/resolver/type_name_resolver.rbs +35 -0
- data/sig/shims/bundler.rbs +38 -0
- data/sig/shims/enumerable.rbs +5 -0
- data/sig/shims/rubygems.rbs +19 -0
- data/sig/sorter.rbs +41 -0
- data/sig/substitution.rbs +48 -0
- data/sig/subtractor.rbs +37 -0
- data/sig/test/errors.rbs +52 -0
- data/sig/test/guranteed.rbs +9 -0
- data/sig/test/type_check.rbs +19 -0
- data/sig/test.rbs +82 -0
- data/sig/type_alias_dependency.rbs +53 -0
- data/sig/type_alias_regularity.rbs +98 -0
- data/sig/type_param.rbs +110 -0
- data/sig/typename.rbs +79 -0
- data/sig/types.rbs +579 -0
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +30 -0
- data/sig/unit_test/type_assertions.rbs +196 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/sig/use_map.rbs +35 -0
- data/sig/util.rbs +9 -0
- data/sig/validator.rbs +63 -0
- data/sig/variance_calculator.rbs +87 -0
- data/sig/vendorer.rbs +51 -0
- data/sig/version.rbs +3 -0
- data/sig/visitor.rbs +47 -0
- data/sig/writer.rbs +127 -0
- data/src/constants.c +153 -0
- data/src/ruby_objs.c +795 -0
- data/src/util/rbs_constant_pool.c +342 -0
- data/stdlib/abbrev/0/abbrev.rbs +66 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +355 -0
- data/stdlib/benchmark/0/benchmark.rbs +452 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +1629 -0
- data/stdlib/bigdecimal-math/0/big_math.rbs +119 -0
- data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
- data/stdlib/cgi/0/core.rbs +1285 -0
- data/stdlib/cgi/0/manifest.yaml +3 -0
- data/stdlib/coverage/0/coverage.rbs +263 -0
- data/stdlib/csv/0/csv.rbs +3776 -0
- data/stdlib/csv/0/manifest.yaml +3 -0
- data/stdlib/date/0/date.rbs +1585 -0
- data/stdlib/date/0/date_time.rbs +616 -0
- data/stdlib/date/0/time.rbs +26 -0
- data/stdlib/dbm/0/dbm.rbs +421 -0
- data/stdlib/delegate/0/delegator.rbs +184 -0
- data/stdlib/delegate/0/kernel.rbs +47 -0
- data/stdlib/delegate/0/simple_delegator.rbs +96 -0
- data/stdlib/did_you_mean/0/did_you_mean.rbs +343 -0
- data/stdlib/digest/0/digest.rbs +577 -0
- data/stdlib/erb/0/erb.rbs +532 -0
- data/stdlib/etc/0/etc.rbs +865 -0
- data/stdlib/fileutils/0/fileutils.rbs +1734 -0
- data/stdlib/find/0/find.rbs +49 -0
- data/stdlib/forwardable/0/forwardable.rbs +268 -0
- data/stdlib/io-console/0/io-console.rbs +414 -0
- data/stdlib/ipaddr/0/ipaddr.rbs +428 -0
- data/stdlib/json/0/json.rbs +1916 -0
- data/stdlib/kconv/0/kconv.rbs +166 -0
- data/stdlib/logger/0/formatter.rbs +45 -0
- data/stdlib/logger/0/log_device.rbs +100 -0
- data/stdlib/logger/0/logger.rbs +796 -0
- data/stdlib/logger/0/manifest.yaml +2 -0
- data/stdlib/logger/0/period.rbs +17 -0
- data/stdlib/logger/0/severity.rbs +34 -0
- data/stdlib/minitest/0/kernel.rbs +42 -0
- data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
- data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
- data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
- data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
- data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
- data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
- data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
- data/stdlib/minitest/0/minitest/compress.rbs +13 -0
- data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
- data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
- data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
- data/stdlib/minitest/0/minitest/guard.rbs +64 -0
- data/stdlib/minitest/0/minitest/mock.rbs +64 -0
- data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
- data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
- data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
- data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
- data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
- data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
- data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
- data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
- data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
- data/stdlib/minitest/0/minitest/result.rbs +28 -0
- data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
- data/stdlib/minitest/0/minitest/skip.rbs +6 -0
- data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
- data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
- data/stdlib/minitest/0/minitest/spec.rbs +11 -0
- data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
- data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
- data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
- data/stdlib/minitest/0/minitest/test.rbs +69 -0
- data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
- data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
- data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
- data/stdlib/minitest/0/minitest/unit.rbs +4 -0
- data/stdlib/minitest/0/minitest.rbs +115 -0
- data/stdlib/monitor/0/monitor.rbs +363 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
- data/stdlib/net-http/0/manifest.yaml +3 -0
- data/stdlib/net-http/0/net-http.rbs +5552 -0
- data/stdlib/net-protocol/0/manifest.yaml +2 -0
- data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
- data/stdlib/net-smtp/0/manifest.yaml +2 -0
- data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
- data/stdlib/nkf/0/nkf.rbs +402 -0
- data/stdlib/objspace/0/objspace.rbs +487 -0
- data/stdlib/observable/0/observable.rbs +217 -0
- data/stdlib/open-uri/0/manifest.yaml +4 -0
- data/stdlib/open-uri/0/open-uri.rbs +393 -0
- data/stdlib/open3/0/open3.rbs +147 -0
- data/stdlib/openssl/0/manifest.yaml +3 -0
- data/stdlib/openssl/0/openssl.rbs +12113 -0
- data/stdlib/optparse/0/optparse.rbs +1725 -0
- data/stdlib/pathname/0/pathname.rbs +1406 -0
- data/stdlib/pp/0/manifest.yaml +2 -0
- data/stdlib/pp/0/pp.rbs +300 -0
- data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
- data/stdlib/pstore/0/pstore.rbs +603 -0
- data/stdlib/psych/0/core_ext.rbs +12 -0
- data/stdlib/psych/0/dbm.rbs +237 -0
- data/stdlib/psych/0/manifest.yaml +3 -0
- data/stdlib/psych/0/psych.rbs +402 -0
- data/stdlib/psych/0/store.rbs +59 -0
- data/stdlib/pty/0/pty.rbs +237 -0
- data/stdlib/rdoc/0/code_object.rbs +51 -0
- data/stdlib/rdoc/0/comment.rbs +59 -0
- data/stdlib/rdoc/0/context.rbs +153 -0
- data/stdlib/rdoc/0/markup.rbs +117 -0
- data/stdlib/rdoc/0/parser.rbs +56 -0
- data/stdlib/rdoc/0/rdoc.rbs +391 -0
- data/stdlib/rdoc/0/ri.rbs +17 -0
- data/stdlib/rdoc/0/store.rbs +48 -0
- data/stdlib/rdoc/0/top_level.rbs +97 -0
- data/stdlib/resolv/0/manifest.yaml +3 -0
- data/stdlib/resolv/0/resolv.rbs +1830 -0
- data/stdlib/ripper/0/ripper.rbs +1648 -0
- data/stdlib/securerandom/0/securerandom.rbs +62 -0
- data/stdlib/shellwords/0/shellwords.rbs +229 -0
- data/stdlib/singleton/0/singleton.rbs +131 -0
- data/stdlib/socket/0/addrinfo.rbs +666 -0
- data/stdlib/socket/0/basic_socket.rbs +590 -0
- data/stdlib/socket/0/constants.rbs +2295 -0
- data/stdlib/socket/0/ip_socket.rbs +92 -0
- data/stdlib/socket/0/socket.rbs +4157 -0
- data/stdlib/socket/0/socket_error.rbs +5 -0
- data/stdlib/socket/0/tcp_server.rbs +192 -0
- data/stdlib/socket/0/tcp_socket.rbs +79 -0
- data/stdlib/socket/0/udp_socket.rbs +133 -0
- data/stdlib/socket/0/unix_server.rbs +169 -0
- data/stdlib/socket/0/unix_socket.rbs +172 -0
- data/stdlib/stringio/0/stringio.rbs +567 -0
- data/stdlib/strscan/0/string_scanner.rbs +1627 -0
- data/stdlib/tempfile/0/tempfile.rbs +479 -0
- data/stdlib/time/0/time.rbs +432 -0
- data/stdlib/timeout/0/timeout.rbs +81 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
- data/stdlib/tsort/0/cyclic.rbs +5 -0
- data/stdlib/tsort/0/interfaces.rbs +20 -0
- data/stdlib/tsort/0/tsort.rbs +409 -0
- data/stdlib/uri/0/common.rbs +582 -0
- data/stdlib/uri/0/file.rbs +118 -0
- data/stdlib/uri/0/ftp.rbs +13 -0
- data/stdlib/uri/0/generic.rbs +1108 -0
- data/stdlib/uri/0/http.rbs +104 -0
- data/stdlib/uri/0/https.rbs +14 -0
- data/stdlib/uri/0/ldap.rbs +230 -0
- data/stdlib/uri/0/ldaps.rbs +14 -0
- data/stdlib/uri/0/mailto.rbs +92 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
- data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
- data/stdlib/uri/0/ws.rbs +13 -0
- data/stdlib/uri/0/wss.rbs +9 -0
- data/stdlib/yaml/0/manifest.yaml +2 -0
- data/stdlib/yaml/0/yaml.rbs +1 -0
- data/stdlib/zlib/0/buf_error.rbs +10 -0
- data/stdlib/zlib/0/data_error.rbs +10 -0
- data/stdlib/zlib/0/deflate.rbs +210 -0
- data/stdlib/zlib/0/error.rbs +20 -0
- data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
- data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
- data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
- data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
- data/stdlib/zlib/0/gzip_file.rbs +156 -0
- data/stdlib/zlib/0/gzip_reader.rbs +293 -0
- data/stdlib/zlib/0/gzip_writer.rbs +166 -0
- data/stdlib/zlib/0/inflate.rbs +180 -0
- data/stdlib/zlib/0/mem_error.rbs +10 -0
- data/stdlib/zlib/0/need_dict.rbs +13 -0
- data/stdlib/zlib/0/stream_end.rbs +11 -0
- data/stdlib/zlib/0/stream_error.rbs +11 -0
- data/stdlib/zlib/0/version_error.rbs +11 -0
- data/stdlib/zlib/0/zlib.rbs +449 -0
- data/stdlib/zlib/0/zstream.rbs +200 -0
- metadata +532 -0
data/core/hash.rbs
ADDED
@@ -0,0 +1,1861 @@
|
|
1
|
+
# <!-- rdoc-file=hash.c -->
|
2
|
+
# A `Hash` maps each of its unique keys to a specific value.
|
3
|
+
#
|
4
|
+
# A `Hash` has certain similarities to an Array, but:
|
5
|
+
# * An Array index is always an Integer.
|
6
|
+
# * A `Hash` key can be (almost) any object.
|
7
|
+
#
|
8
|
+
# ### `Hash` Data Syntax
|
9
|
+
#
|
10
|
+
# The older syntax for `Hash` data uses the "hash rocket," `=>`:
|
11
|
+
#
|
12
|
+
# h = {:foo => 0, :bar => 1, :baz => 2}
|
13
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2}
|
14
|
+
#
|
15
|
+
# Alternatively, but only for a `Hash` key that's a Symbol, you can use a newer
|
16
|
+
# JSON-style syntax, where each bareword becomes a Symbol:
|
17
|
+
#
|
18
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
19
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2}
|
20
|
+
#
|
21
|
+
# You can also use a String in place of a bareword:
|
22
|
+
#
|
23
|
+
# h = {'foo': 0, 'bar': 1, 'baz': 2}
|
24
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2}
|
25
|
+
#
|
26
|
+
# And you can mix the styles:
|
27
|
+
#
|
28
|
+
# h = {foo: 0, :bar => 1, 'baz': 2}
|
29
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2}
|
30
|
+
#
|
31
|
+
# But it's an error to try the JSON-style syntax for a key that's not a bareword
|
32
|
+
# or a String:
|
33
|
+
#
|
34
|
+
# # Raises SyntaxError (syntax error, unexpected ':', expecting =>):
|
35
|
+
# h = {0: 'zero'}
|
36
|
+
#
|
37
|
+
# `Hash` value can be omitted, meaning that value will be fetched from the
|
38
|
+
# context by the name of the key:
|
39
|
+
#
|
40
|
+
# x = 0
|
41
|
+
# y = 100
|
42
|
+
# h = {x:, y:}
|
43
|
+
# h # => {:x=>0, :y=>100}
|
44
|
+
#
|
45
|
+
# ### Common Uses
|
46
|
+
#
|
47
|
+
# You can use a `Hash` to give names to objects:
|
48
|
+
#
|
49
|
+
# person = {name: 'Matz', language: 'Ruby'}
|
50
|
+
# person # => {:name=>"Matz", :language=>"Ruby"}
|
51
|
+
#
|
52
|
+
# You can use a `Hash` to give names to method arguments:
|
53
|
+
#
|
54
|
+
# def some_method(hash)
|
55
|
+
# p hash
|
56
|
+
# end
|
57
|
+
# some_method({foo: 0, bar: 1, baz: 2}) # => {:foo=>0, :bar=>1, :baz=>2}
|
58
|
+
#
|
59
|
+
# Note: when the last argument in a method call is a `Hash`, the curly braces
|
60
|
+
# may be omitted:
|
61
|
+
#
|
62
|
+
# some_method(foo: 0, bar: 1, baz: 2) # => {:foo=>0, :bar=>1, :baz=>2}
|
63
|
+
#
|
64
|
+
# You can use a `Hash` to initialize an object:
|
65
|
+
#
|
66
|
+
# class Dev
|
67
|
+
# attr_accessor :name, :language
|
68
|
+
# def initialize(hash)
|
69
|
+
# self.name = hash[:name]
|
70
|
+
# self.language = hash[:language]
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
# matz = Dev.new(name: 'Matz', language: 'Ruby')
|
74
|
+
# matz # => #<Dev: @name="Matz", @language="Ruby">
|
75
|
+
#
|
76
|
+
# ### Creating a `Hash`
|
77
|
+
#
|
78
|
+
# You can create a `Hash` object explicitly with:
|
79
|
+
#
|
80
|
+
# * A [hash literal](rdoc-ref:syntax/literals.rdoc@Hash+Literals).
|
81
|
+
#
|
82
|
+
# You can convert certain objects to Hashes with:
|
83
|
+
#
|
84
|
+
# * Method #Hash.
|
85
|
+
#
|
86
|
+
# You can create a `Hash` by calling method Hash.new.
|
87
|
+
#
|
88
|
+
# Create an empty `Hash`:
|
89
|
+
#
|
90
|
+
# h = Hash.new
|
91
|
+
# h # => {}
|
92
|
+
# h.class # => Hash
|
93
|
+
#
|
94
|
+
# You can create a `Hash` by calling method Hash.[].
|
95
|
+
#
|
96
|
+
# Create an empty `Hash`:
|
97
|
+
#
|
98
|
+
# h = Hash[]
|
99
|
+
# h # => {}
|
100
|
+
#
|
101
|
+
# Create a `Hash` with initial entries:
|
102
|
+
#
|
103
|
+
# h = Hash[foo: 0, bar: 1, baz: 2]
|
104
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2}
|
105
|
+
#
|
106
|
+
# You can create a `Hash` by using its literal form (curly braces).
|
107
|
+
#
|
108
|
+
# Create an empty `Hash`:
|
109
|
+
#
|
110
|
+
# h = {}
|
111
|
+
# h # => {}
|
112
|
+
#
|
113
|
+
# Create a `Hash` with initial entries:
|
114
|
+
#
|
115
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
116
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2}
|
117
|
+
#
|
118
|
+
# ### `Hash` Value Basics
|
119
|
+
#
|
120
|
+
# The simplest way to retrieve a `Hash` value (instance method #[]):
|
121
|
+
#
|
122
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
123
|
+
# h[:foo] # => 0
|
124
|
+
#
|
125
|
+
# The simplest way to create or update a `Hash` value (instance method #[]=):
|
126
|
+
#
|
127
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
128
|
+
# h[:bat] = 3 # => 3
|
129
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2, :bat=>3}
|
130
|
+
# h[:foo] = 4 # => 4
|
131
|
+
# h # => {:foo=>4, :bar=>1, :baz=>2, :bat=>3}
|
132
|
+
#
|
133
|
+
# The simplest way to delete a `Hash` entry (instance method #delete):
|
134
|
+
#
|
135
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
136
|
+
# h.delete(:bar) # => 1
|
137
|
+
# h # => {:foo=>0, :baz=>2}
|
138
|
+
#
|
139
|
+
# ### Entry Order
|
140
|
+
#
|
141
|
+
# A `Hash` object presents its entries in the order of their creation. This is
|
142
|
+
# seen in:
|
143
|
+
#
|
144
|
+
# * Iterative methods such as `each`, `each_key`, `each_pair`, `each_value`.
|
145
|
+
# * Other order-sensitive methods such as `shift`, `keys`, `values`.
|
146
|
+
# * The String returned by method `inspect`.
|
147
|
+
#
|
148
|
+
# A new `Hash` has its initial ordering per the given entries:
|
149
|
+
#
|
150
|
+
# h = Hash[foo: 0, bar: 1]
|
151
|
+
# h # => {:foo=>0, :bar=>1}
|
152
|
+
#
|
153
|
+
# New entries are added at the end:
|
154
|
+
#
|
155
|
+
# h[:baz] = 2
|
156
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2}
|
157
|
+
#
|
158
|
+
# Updating a value does not affect the order:
|
159
|
+
#
|
160
|
+
# h[:baz] = 3
|
161
|
+
# h # => {:foo=>0, :bar=>1, :baz=>3}
|
162
|
+
#
|
163
|
+
# But re-creating a deleted entry can affect the order:
|
164
|
+
#
|
165
|
+
# h.delete(:foo)
|
166
|
+
# h[:foo] = 5
|
167
|
+
# h # => {:bar=>1, :baz=>3, :foo=>5}
|
168
|
+
#
|
169
|
+
# ### `Hash` Keys
|
170
|
+
#
|
171
|
+
# #### `Hash` Key Equivalence
|
172
|
+
#
|
173
|
+
# Two objects are treated as the same hash key when their `hash` value is
|
174
|
+
# identical and the two objects are `eql?` to each other.
|
175
|
+
#
|
176
|
+
# #### Modifying an Active `Hash` Key
|
177
|
+
#
|
178
|
+
# Modifying a `Hash` key while it is in use damages the hash's index.
|
179
|
+
#
|
180
|
+
# This `Hash` has keys that are Arrays:
|
181
|
+
#
|
182
|
+
# a0 = [ :foo, :bar ]
|
183
|
+
# a1 = [ :baz, :bat ]
|
184
|
+
# h = {a0 => 0, a1 => 1}
|
185
|
+
# h.include?(a0) # => true
|
186
|
+
# h[a0] # => 0
|
187
|
+
# a0.hash # => 110002110
|
188
|
+
#
|
189
|
+
# Modifying array element `a0[0]` changes its hash value:
|
190
|
+
#
|
191
|
+
# a0[0] = :bam
|
192
|
+
# a0.hash # => 1069447059
|
193
|
+
#
|
194
|
+
# And damages the `Hash` index:
|
195
|
+
#
|
196
|
+
# h.include?(a0) # => false
|
197
|
+
# h[a0] # => nil
|
198
|
+
#
|
199
|
+
# You can repair the hash index using method `rehash`:
|
200
|
+
#
|
201
|
+
# h.rehash # => {[:bam, :bar]=>0, [:baz, :bat]=>1}
|
202
|
+
# h.include?(a0) # => true
|
203
|
+
# h[a0] # => 0
|
204
|
+
#
|
205
|
+
# A String key is always safe. That's because an unfrozen String passed as a key
|
206
|
+
# will be replaced by a duplicated and frozen String:
|
207
|
+
#
|
208
|
+
# s = 'foo'
|
209
|
+
# s.frozen? # => false
|
210
|
+
# h = {s => 0}
|
211
|
+
# first_key = h.keys.first
|
212
|
+
# first_key.frozen? # => true
|
213
|
+
#
|
214
|
+
# #### User-Defined `Hash` Keys
|
215
|
+
#
|
216
|
+
# To be usable as a `Hash` key, objects must implement the methods `hash` and
|
217
|
+
# `eql?`. Note: this requirement does not apply if the `Hash` uses
|
218
|
+
# #compare_by_identity since comparison will then rely on the keys' object id
|
219
|
+
# instead of `hash` and `eql?`.
|
220
|
+
#
|
221
|
+
# Object defines basic implementation for `hash` and `eq?` that makes each
|
222
|
+
# object a distinct key. Typically, user-defined classes will want to override
|
223
|
+
# these methods to provide meaningful behavior, or for example inherit Struct
|
224
|
+
# that has useful definitions for these.
|
225
|
+
#
|
226
|
+
# A typical implementation of `hash` is based on the object's data while `eql?`
|
227
|
+
# is usually aliased to the overridden `==` method:
|
228
|
+
#
|
229
|
+
# class Book
|
230
|
+
# attr_reader :author, :title
|
231
|
+
#
|
232
|
+
# def initialize(author, title)
|
233
|
+
# @author = author
|
234
|
+
# @title = title
|
235
|
+
# end
|
236
|
+
#
|
237
|
+
# def ==(other)
|
238
|
+
# self.class === other &&
|
239
|
+
# other.author == @author &&
|
240
|
+
# other.title == @title
|
241
|
+
# end
|
242
|
+
#
|
243
|
+
# alias eql? ==
|
244
|
+
#
|
245
|
+
# def hash
|
246
|
+
# [self.class, @author, @title].hash
|
247
|
+
# end
|
248
|
+
# end
|
249
|
+
#
|
250
|
+
# book1 = Book.new 'matz', 'Ruby in a Nutshell'
|
251
|
+
# book2 = Book.new 'matz', 'Ruby in a Nutshell'
|
252
|
+
#
|
253
|
+
# reviews = {}
|
254
|
+
#
|
255
|
+
# reviews[book1] = 'Great reference!'
|
256
|
+
# reviews[book2] = 'Nice and compact!'
|
257
|
+
#
|
258
|
+
# reviews.length #=> 1
|
259
|
+
#
|
260
|
+
# ### Default Values
|
261
|
+
#
|
262
|
+
# The methods #[], #values_at and #dig need to return the value associated to a
|
263
|
+
# certain key. When that key is not found, that value will be determined by its
|
264
|
+
# default proc (if any) or else its default (initially `nil`).
|
265
|
+
#
|
266
|
+
# You can retrieve the default value with method #default:
|
267
|
+
#
|
268
|
+
# h = Hash.new
|
269
|
+
# h.default # => nil
|
270
|
+
#
|
271
|
+
# You can set the default value by passing an argument to method Hash.new or
|
272
|
+
# with method #default=
|
273
|
+
#
|
274
|
+
# h = Hash.new(-1)
|
275
|
+
# h.default # => -1
|
276
|
+
# h.default = 0
|
277
|
+
# h.default # => 0
|
278
|
+
#
|
279
|
+
# This default value is returned for #[], #values_at and #dig when a key is not
|
280
|
+
# found:
|
281
|
+
#
|
282
|
+
# counts = {foo: 42}
|
283
|
+
# counts.default # => nil (default)
|
284
|
+
# counts[:foo] = 42
|
285
|
+
# counts[:bar] # => nil
|
286
|
+
# counts.default = 0
|
287
|
+
# counts[:bar] # => 0
|
288
|
+
# counts.values_at(:foo, :bar, :baz) # => [42, 0, 0]
|
289
|
+
# counts.dig(:bar) # => 0
|
290
|
+
#
|
291
|
+
# Note that the default value is used without being duplicated. It is not
|
292
|
+
# advised to set the default value to a mutable object:
|
293
|
+
#
|
294
|
+
# synonyms = Hash.new([])
|
295
|
+
# synonyms[:hello] # => []
|
296
|
+
# synonyms[:hello] << :hi # => [:hi], but this mutates the default!
|
297
|
+
# synonyms.default # => [:hi]
|
298
|
+
# synonyms[:world] << :universe
|
299
|
+
# synonyms[:world] # => [:hi, :universe], oops
|
300
|
+
# synonyms.keys # => [], oops
|
301
|
+
#
|
302
|
+
# To use a mutable object as default, it is recommended to use a default proc
|
303
|
+
#
|
304
|
+
# #### Default Proc
|
305
|
+
#
|
306
|
+
# When the default proc for a `Hash` is set (i.e., not `nil`), the default value
|
307
|
+
# returned by method #[] is determined by the default proc alone.
|
308
|
+
#
|
309
|
+
# You can retrieve the default proc with method #default_proc:
|
310
|
+
#
|
311
|
+
# h = Hash.new
|
312
|
+
# h.default_proc # => nil
|
313
|
+
#
|
314
|
+
# You can set the default proc by calling Hash.new with a block or calling the
|
315
|
+
# method #default_proc=
|
316
|
+
#
|
317
|
+
# h = Hash.new { |hash, key| "Default value for #{key}" }
|
318
|
+
# h.default_proc.class # => Proc
|
319
|
+
# h.default_proc = proc { |hash, key| "Default value for #{key.inspect}" }
|
320
|
+
# h.default_proc.class # => Proc
|
321
|
+
#
|
322
|
+
# When the default proc is set (i.e., not `nil`) and method #[] is called with
|
323
|
+
# with a non-existent key, #[] calls the default proc with both the `Hash`
|
324
|
+
# object itself and the missing key, then returns the proc's return value:
|
325
|
+
#
|
326
|
+
# h = Hash.new { |hash, key| "Default value for #{key}" }
|
327
|
+
# h[:nosuch] # => "Default value for nosuch"
|
328
|
+
#
|
329
|
+
# Note that in the example above no entry for key `:nosuch` is created:
|
330
|
+
#
|
331
|
+
# h.include?(:nosuch) # => false
|
332
|
+
#
|
333
|
+
# However, the proc itself can add a new entry:
|
334
|
+
#
|
335
|
+
# synonyms = Hash.new { |hash, key| hash[key] = [] }
|
336
|
+
# synonyms.include?(:hello) # => false
|
337
|
+
# synonyms[:hello] << :hi # => [:hi]
|
338
|
+
# synonyms[:world] << :universe # => [:universe]
|
339
|
+
# synonyms.keys # => [:hello, :world]
|
340
|
+
#
|
341
|
+
# Note that setting the default proc will clear the default value and vice
|
342
|
+
# versa.
|
343
|
+
#
|
344
|
+
# Be aware that a default proc that modifies the hash is not thread-safe in the
|
345
|
+
# sense that multiple threads can call into the default proc concurrently for
|
346
|
+
# the same key.
|
347
|
+
#
|
348
|
+
# ### What's Here
|
349
|
+
#
|
350
|
+
# First, what's elsewhere. Class `Hash`:
|
351
|
+
#
|
352
|
+
# * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
|
353
|
+
# * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
|
354
|
+
# provides dozens of additional methods.
|
355
|
+
#
|
356
|
+
# Here, class `Hash` provides methods that are useful for:
|
357
|
+
#
|
358
|
+
# * [Creating a Hash](rdoc-ref:Hash@Methods+for+Creating+a+Hash)
|
359
|
+
# * [Setting Hash State](rdoc-ref:Hash@Methods+for+Setting+Hash+State)
|
360
|
+
# * [Querying](rdoc-ref:Hash@Methods+for+Querying)
|
361
|
+
# * [Comparing](rdoc-ref:Hash@Methods+for+Comparing)
|
362
|
+
# * [Fetching](rdoc-ref:Hash@Methods+for+Fetching)
|
363
|
+
# * [Assigning](rdoc-ref:Hash@Methods+for+Assigning)
|
364
|
+
# * [Deleting](rdoc-ref:Hash@Methods+for+Deleting)
|
365
|
+
# * [Iterating](rdoc-ref:Hash@Methods+for+Iterating)
|
366
|
+
# * [Converting](rdoc-ref:Hash@Methods+for+Converting)
|
367
|
+
# * [Transforming Keys and
|
368
|
+
# Values](rdoc-ref:Hash@Methods+for+Transforming+Keys+and+Values)
|
369
|
+
# * [And more....](rdoc-ref:Hash@Other+Methods)
|
370
|
+
#
|
371
|
+
# Class `Hash` also includes methods from module Enumerable.
|
372
|
+
#
|
373
|
+
# #### Methods for Creating a `Hash`
|
374
|
+
#
|
375
|
+
# * ::[]: Returns a new hash populated with given objects.
|
376
|
+
# * ::new: Returns a new empty hash.
|
377
|
+
# * ::try_convert: Returns a new hash created from a given object.
|
378
|
+
#
|
379
|
+
# #### Methods for Setting `Hash` State
|
380
|
+
#
|
381
|
+
# * #compare_by_identity: Sets `self` to consider only identity in comparing
|
382
|
+
# keys.
|
383
|
+
# * #default=: Sets the default to a given value.
|
384
|
+
# * #default_proc=: Sets the default proc to a given proc.
|
385
|
+
# * #rehash: Rebuilds the hash table by recomputing the hash index for each
|
386
|
+
# key.
|
387
|
+
#
|
388
|
+
# #### Methods for Querying
|
389
|
+
#
|
390
|
+
# * #any?: Returns whether any element satisfies a given criterion.
|
391
|
+
# * #compare_by_identity?: Returns whether the hash considers only identity
|
392
|
+
# when comparing keys.
|
393
|
+
# * #default: Returns the default value, or the default value for a given key.
|
394
|
+
# * #default_proc: Returns the default proc.
|
395
|
+
# * #empty?: Returns whether there are no entries.
|
396
|
+
# * #eql?: Returns whether a given object is equal to `self`.
|
397
|
+
# * #hash: Returns the integer hash code.
|
398
|
+
# * #has_value? (aliased as #value?): Returns whether a given object is a
|
399
|
+
# value in `self`.
|
400
|
+
# * #include? (aliased as #has_key?, #member?, #key?): Returns whether a given
|
401
|
+
# object is a key in `self`.
|
402
|
+
# * #size (aliased as #length): Returns the count of entries.
|
403
|
+
#
|
404
|
+
# #### Methods for Comparing
|
405
|
+
#
|
406
|
+
# * #<: Returns whether `self` is a proper subset of a given object.
|
407
|
+
# * #<=: Returns whether `self` is a subset of a given object.
|
408
|
+
# * #==: Returns whether a given object is equal to `self`.
|
409
|
+
# * #>: Returns whether `self` is a proper superset of a given object
|
410
|
+
# * #>=: Returns whether `self` is a superset of a given object.
|
411
|
+
#
|
412
|
+
# #### Methods for Fetching
|
413
|
+
#
|
414
|
+
# * #[]: Returns the value associated with a given key.
|
415
|
+
# * #assoc: Returns a 2-element array containing a given key and its value.
|
416
|
+
# * #dig: Returns the object in nested objects that is specified by a given
|
417
|
+
# key and additional arguments.
|
418
|
+
# * #fetch: Returns the value for a given key.
|
419
|
+
# * #fetch_values: Returns array containing the values associated with given
|
420
|
+
# keys.
|
421
|
+
# * #key: Returns the key for the first-found entry with a given value.
|
422
|
+
# * #keys: Returns an array containing all keys in `self`.
|
423
|
+
# * #rassoc: Returns a 2-element array consisting of the key and value of the
|
424
|
+
# first-found entry having a given value.
|
425
|
+
# * #values: Returns an array containing all values in `self`/
|
426
|
+
# * #values_at: Returns an array containing values for given keys.
|
427
|
+
#
|
428
|
+
# #### Methods for Assigning
|
429
|
+
#
|
430
|
+
# * #[]= (aliased as #store): Associates a given key with a given value.
|
431
|
+
# * #merge: Returns the hash formed by merging each given hash into a copy of
|
432
|
+
# `self`.
|
433
|
+
# * #update (aliased as #merge!): Merges each given hash into `self`.
|
434
|
+
# * #replace (aliased as #initialize_copy): Replaces the entire contents of
|
435
|
+
# `self` with the contents of a given hash.
|
436
|
+
#
|
437
|
+
# #### Methods for Deleting
|
438
|
+
#
|
439
|
+
# These methods remove entries from `self`:
|
440
|
+
#
|
441
|
+
# * #clear: Removes all entries from `self`.
|
442
|
+
# * #compact!: Removes all `nil`-valued entries from `self`.
|
443
|
+
# * #delete: Removes the entry for a given key.
|
444
|
+
# * #delete_if: Removes entries selected by a given block.
|
445
|
+
# * #select! (aliased as #filter!): Keep only those entries selected by a
|
446
|
+
# given block.
|
447
|
+
# * #keep_if: Keep only those entries selected by a given block.
|
448
|
+
# * #reject!: Removes entries selected by a given block.
|
449
|
+
# * #shift: Removes and returns the first entry.
|
450
|
+
#
|
451
|
+
# These methods return a copy of `self` with some entries removed:
|
452
|
+
#
|
453
|
+
# * #compact: Returns a copy of `self` with all `nil`-valued entries removed.
|
454
|
+
# * #except: Returns a copy of `self` with entries removed for specified keys.
|
455
|
+
# * #select (aliased as #filter): Returns a copy of `self` with only those
|
456
|
+
# entries selected by a given block.
|
457
|
+
# * #reject: Returns a copy of `self` with entries removed as specified by a
|
458
|
+
# given block.
|
459
|
+
# * #slice: Returns a hash containing the entries for given keys.
|
460
|
+
#
|
461
|
+
# #### Methods for Iterating
|
462
|
+
# * #each_pair (aliased as #each): Calls a given block with each key-value
|
463
|
+
# pair.
|
464
|
+
# * #each_key: Calls a given block with each key.
|
465
|
+
# * #each_value: Calls a given block with each value.
|
466
|
+
#
|
467
|
+
# #### Methods for Converting
|
468
|
+
#
|
469
|
+
# * #inspect (aliased as #to_s): Returns a new String containing the hash
|
470
|
+
# entries.
|
471
|
+
# * #to_a: Returns a new array of 2-element arrays; each nested array contains
|
472
|
+
# a key-value pair from `self`.
|
473
|
+
# * #to_h: Returns `self` if a `Hash`; if a subclass of `Hash`, returns a
|
474
|
+
# `Hash` containing the entries from `self`.
|
475
|
+
# * #to_hash: Returns `self`.
|
476
|
+
# * #to_proc: Returns a proc that maps a given key to its value.
|
477
|
+
#
|
478
|
+
# #### Methods for Transforming Keys and Values
|
479
|
+
#
|
480
|
+
# * #transform_keys: Returns a copy of `self` with modified keys.
|
481
|
+
# * #transform_keys!: Modifies keys in `self`
|
482
|
+
# * #transform_values: Returns a copy of `self` with modified values.
|
483
|
+
# * #transform_values!: Modifies values in `self`.
|
484
|
+
#
|
485
|
+
# #### Other Methods
|
486
|
+
# * #flatten: Returns an array that is a 1-dimensional flattening of `self`.
|
487
|
+
# * #invert: Returns a hash with the each key-value pair inverted.
|
488
|
+
#
|
489
|
+
class Hash[unchecked out K, unchecked out V] < Object
|
490
|
+
include Enumerable[[ K, V ]]
|
491
|
+
|
492
|
+
interface _Key
|
493
|
+
def hash: () -> Integer
|
494
|
+
|
495
|
+
def eql?: (untyped rhs) -> boolish
|
496
|
+
end
|
497
|
+
|
498
|
+
# <!--
|
499
|
+
# rdoc-file=hash.c
|
500
|
+
# - Hash[] -> new_empty_hash
|
501
|
+
# - Hash[hash] -> new_hash
|
502
|
+
# - Hash[ [*2_element_arrays] ] -> new_hash
|
503
|
+
# - Hash[*objects] -> new_hash
|
504
|
+
# -->
|
505
|
+
# Returns a new `Hash` object populated with the given objects, if any. See
|
506
|
+
# Hash::new.
|
507
|
+
#
|
508
|
+
# With no argument, returns a new empty `Hash`.
|
509
|
+
#
|
510
|
+
# When the single given argument is a `Hash`, returns a new `Hash` populated
|
511
|
+
# with the entries from the given `Hash`, excluding the default value or proc.
|
512
|
+
#
|
513
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
514
|
+
# Hash[h] # => {:foo=>0, :bar=>1, :baz=>2}
|
515
|
+
#
|
516
|
+
# When the single given argument is an Array of 2-element Arrays, returns a new
|
517
|
+
# `Hash` object wherein each 2-element array forms a key-value entry:
|
518
|
+
#
|
519
|
+
# Hash[ [ [:foo, 0], [:bar, 1] ] ] # => {:foo=>0, :bar=>1}
|
520
|
+
#
|
521
|
+
# When the argument count is an even number; returns a new `Hash` object wherein
|
522
|
+
# each successive pair of arguments has become a key-value entry:
|
523
|
+
#
|
524
|
+
# Hash[:foo, 0, :bar, 1] # => {:foo=>0, :bar=>1}
|
525
|
+
#
|
526
|
+
# Raises an exception if the argument list does not conform to any of the above.
|
527
|
+
#
|
528
|
+
def self.[]: [U, V] (_ToHash[U, V]) -> ::Hash[U, V]
|
529
|
+
| [U, V] (Array[[ U, V ]]) -> ::Hash[U, V]
|
530
|
+
| (*untyped) -> ::Hash[untyped, untyped]
|
531
|
+
|
532
|
+
# <!--
|
533
|
+
# rdoc-file=hash.c
|
534
|
+
# - Hash.try_convert(obj) -> obj, new_hash, or nil
|
535
|
+
# -->
|
536
|
+
# If `obj` is a `Hash` object, returns `obj`.
|
537
|
+
#
|
538
|
+
# Otherwise if `obj` responds to `:to_hash`, calls `obj.to_hash` and returns the
|
539
|
+
# result.
|
540
|
+
#
|
541
|
+
# Returns `nil` if `obj` does not respond to `:to_hash`
|
542
|
+
#
|
543
|
+
# Raises an exception unless `obj.to_hash` returns a `Hash` object.
|
544
|
+
#
|
545
|
+
def self.try_convert: [U, V] (_ToHash[U, V]) -> ::Hash[U, V]
|
546
|
+
| (untyped) -> (::Hash[untyped, untyped] | nil)
|
547
|
+
|
548
|
+
# <!--
|
549
|
+
# rdoc-file=hash.c
|
550
|
+
# - hash < other_hash -> true or false
|
551
|
+
# -->
|
552
|
+
# Returns `true` if `hash` is a proper subset of `other_hash`, `false`
|
553
|
+
# otherwise:
|
554
|
+
# h1 = {foo: 0, bar: 1}
|
555
|
+
# h2 = {foo: 0, bar: 1, baz: 2}
|
556
|
+
# h1 < h2 # => true
|
557
|
+
# h2 < h1 # => false
|
558
|
+
# h1 < h1 # => false
|
559
|
+
#
|
560
|
+
def <: [A, B] (::Hash[A, B]) -> bool
|
561
|
+
|
562
|
+
# <!--
|
563
|
+
# rdoc-file=hash.c
|
564
|
+
# - hash <= other_hash -> true or false
|
565
|
+
# -->
|
566
|
+
# Returns `true` if `hash` is a subset of `other_hash`, `false` otherwise:
|
567
|
+
# h1 = {foo: 0, bar: 1}
|
568
|
+
# h2 = {foo: 0, bar: 1, baz: 2}
|
569
|
+
# h1 <= h2 # => true
|
570
|
+
# h2 <= h1 # => false
|
571
|
+
# h1 <= h1 # => true
|
572
|
+
#
|
573
|
+
def <=: [A, B] (::Hash[A, B]) -> bool
|
574
|
+
|
575
|
+
# <!--
|
576
|
+
# rdoc-file=hash.c
|
577
|
+
# - hash == object -> true or false
|
578
|
+
# -->
|
579
|
+
# Returns `true` if all of the following are true:
|
580
|
+
# * `object` is a `Hash` object.
|
581
|
+
# * `hash` and `object` have the same keys (regardless of order).
|
582
|
+
# * For each key `key`, `hash[key] == object[key]`.
|
583
|
+
#
|
584
|
+
# Otherwise, returns `false`.
|
585
|
+
#
|
586
|
+
# Equal:
|
587
|
+
# h1 = {foo: 0, bar: 1, baz: 2}
|
588
|
+
# h2 = {foo: 0, bar: 1, baz: 2}
|
589
|
+
# h1 == h2 # => true
|
590
|
+
# h3 = {baz: 2, bar: 1, foo: 0}
|
591
|
+
# h1 == h3 # => true
|
592
|
+
#
|
593
|
+
def ==: (untyped other) -> bool
|
594
|
+
|
595
|
+
# <!--
|
596
|
+
# rdoc-file=hash.c
|
597
|
+
# - hash > other_hash -> true or false
|
598
|
+
# -->
|
599
|
+
# Returns `true` if `hash` is a proper superset of `other_hash`, `false`
|
600
|
+
# otherwise:
|
601
|
+
# h1 = {foo: 0, bar: 1, baz: 2}
|
602
|
+
# h2 = {foo: 0, bar: 1}
|
603
|
+
# h1 > h2 # => true
|
604
|
+
# h2 > h1 # => false
|
605
|
+
# h1 > h1 # => false
|
606
|
+
#
|
607
|
+
def >: [A, B] (::Hash[A, B]) -> bool
|
608
|
+
|
609
|
+
# <!--
|
610
|
+
# rdoc-file=hash.c
|
611
|
+
# - hash >= other_hash -> true or false
|
612
|
+
# -->
|
613
|
+
# Returns `true` if `hash` is a superset of `other_hash`, `false` otherwise:
|
614
|
+
# h1 = {foo: 0, bar: 1, baz: 2}
|
615
|
+
# h2 = {foo: 0, bar: 1}
|
616
|
+
# h1 >= h2 # => true
|
617
|
+
# h2 >= h1 # => false
|
618
|
+
# h1 >= h1 # => true
|
619
|
+
#
|
620
|
+
def >=: [A, B] (::Hash[A, B]) -> bool
|
621
|
+
|
622
|
+
# <!--
|
623
|
+
# rdoc-file=hash.c
|
624
|
+
# - hash[key] -> value
|
625
|
+
# -->
|
626
|
+
# Returns the value associated with the given `key`, if found:
|
627
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
628
|
+
# h[:foo] # => 0
|
629
|
+
#
|
630
|
+
# If `key` is not found, returns a default value (see [Default
|
631
|
+
# Values](rdoc-ref:Hash@Default+Values)):
|
632
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
633
|
+
# h[:nosuch] # => nil
|
634
|
+
#
|
635
|
+
def []: %a{implicitly-returns-nil} (K arg0) -> V
|
636
|
+
|
637
|
+
# <!--
|
638
|
+
# rdoc-file=hash.c
|
639
|
+
# - hash[key] = value -> value
|
640
|
+
# - hash.store(key, value)
|
641
|
+
# -->
|
642
|
+
# Associates the given `value` with the given `key`; returns `value`.
|
643
|
+
#
|
644
|
+
# If the given `key` exists, replaces its value with the given `value`; the
|
645
|
+
# ordering is not affected (see [Entry Order](rdoc-ref:Hash@Entry+Order)):
|
646
|
+
# h = {foo: 0, bar: 1}
|
647
|
+
# h[:foo] = 2 # => 2
|
648
|
+
# h.store(:bar, 3) # => 3
|
649
|
+
# h # => {:foo=>2, :bar=>3}
|
650
|
+
#
|
651
|
+
# If `key` does not exist, adds the `key` and `value`; the new entry is last in
|
652
|
+
# the order (see [Entry Order](rdoc-ref:Hash@Entry+Order)):
|
653
|
+
# h = {foo: 0, bar: 1}
|
654
|
+
# h[:baz] = 2 # => 2
|
655
|
+
# h.store(:bat, 3) # => 3
|
656
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2, :bat=>3}
|
657
|
+
#
|
658
|
+
def []=: (K arg0, V arg1) -> V
|
659
|
+
|
660
|
+
# <!--
|
661
|
+
# rdoc-file=hash.c
|
662
|
+
# - hash.any? -> true or false
|
663
|
+
# - hash.any?(object) -> true or false
|
664
|
+
# - hash.any? {|key, value| ... } -> true or false
|
665
|
+
# -->
|
666
|
+
# Returns `true` if any element satisfies a given criterion; `false` otherwise.
|
667
|
+
#
|
668
|
+
# If `self` has no element, returns `false` and argument or block are not used.
|
669
|
+
#
|
670
|
+
# With no argument and no block, returns `true` if `self` is non-empty; `false`
|
671
|
+
# if empty.
|
672
|
+
#
|
673
|
+
# With argument `object` and no block, returns `true` if for any key `key`
|
674
|
+
# `h.assoc(key) == object`:
|
675
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
676
|
+
# h.any?([:bar, 1]) # => true
|
677
|
+
# h.any?([:bar, 0]) # => false
|
678
|
+
# h.any?([:baz, 1]) # => false
|
679
|
+
#
|
680
|
+
# With no argument and a block, calls the block with each key-value pair;
|
681
|
+
# returns `true` if the block returns any truthy value, `false` otherwise:
|
682
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
683
|
+
# h.any? {|key, value| value < 3 } # => true
|
684
|
+
# h.any? {|key, value| value > 3 } # => false
|
685
|
+
#
|
686
|
+
# Related: Enumerable#any?
|
687
|
+
#
|
688
|
+
def any?: () -> bool
|
689
|
+
| (untyped pattern) -> bool
|
690
|
+
| () { (K, V) -> boolish } -> bool
|
691
|
+
|
692
|
+
# <!--
|
693
|
+
# rdoc-file=hash.c
|
694
|
+
# - hash.assoc(key) -> new_array or nil
|
695
|
+
# -->
|
696
|
+
# If the given `key` is found, returns a 2-element Array containing that key and
|
697
|
+
# its value:
|
698
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
699
|
+
# h.assoc(:bar) # => [:bar, 1]
|
700
|
+
#
|
701
|
+
# Returns `nil` if key `key` is not found.
|
702
|
+
#
|
703
|
+
def assoc: (K arg0) -> [ K, V ]?
|
704
|
+
|
705
|
+
# <!--
|
706
|
+
# rdoc-file=hash.c
|
707
|
+
# - hash.clear -> self
|
708
|
+
# -->
|
709
|
+
# Removes all hash entries; returns `self`.
|
710
|
+
#
|
711
|
+
def clear: () -> self
|
712
|
+
|
713
|
+
# <!--
|
714
|
+
# rdoc-file=hash.c
|
715
|
+
# - hash.compact -> new_hash
|
716
|
+
# -->
|
717
|
+
# Returns a copy of `self` with all `nil`-valued entries removed:
|
718
|
+
# h = {foo: 0, bar: nil, baz: 2, bat: nil}
|
719
|
+
# h1 = h.compact
|
720
|
+
# h1 # => {:foo=>0, :baz=>2}
|
721
|
+
#
|
722
|
+
def compact: () -> ::Hash[K, V]
|
723
|
+
|
724
|
+
# <!--
|
725
|
+
# rdoc-file=hash.c
|
726
|
+
# - hash.compact! -> self or nil
|
727
|
+
# -->
|
728
|
+
# Returns `self` with all its `nil`-valued entries removed (in place):
|
729
|
+
# h = {foo: 0, bar: nil, baz: 2, bat: nil}
|
730
|
+
# h.compact! # => {:foo=>0, :baz=>2}
|
731
|
+
#
|
732
|
+
# Returns `nil` if no entries were removed.
|
733
|
+
#
|
734
|
+
def compact!: () -> self?
|
735
|
+
|
736
|
+
# <!--
|
737
|
+
# rdoc-file=hash.c
|
738
|
+
# - hash.compare_by_identity -> self
|
739
|
+
# -->
|
740
|
+
# Sets `self` to consider only identity in comparing keys; two keys are
|
741
|
+
# considered the same only if they are the same object; returns `self`.
|
742
|
+
#
|
743
|
+
# By default, these two object are considered to be the same key, so `s1` will
|
744
|
+
# overwrite `s0`:
|
745
|
+
# s0 = 'x'
|
746
|
+
# s1 = 'x'
|
747
|
+
# h = {}
|
748
|
+
# h.compare_by_identity? # => false
|
749
|
+
# h[s0] = 0
|
750
|
+
# h[s1] = 1
|
751
|
+
# h # => {"x"=>1}
|
752
|
+
#
|
753
|
+
# After calling #compare_by_identity, the keys are considered to be different,
|
754
|
+
# and therefore do not overwrite each other:
|
755
|
+
# h = {}
|
756
|
+
# h.compare_by_identity # => {}
|
757
|
+
# h.compare_by_identity? # => true
|
758
|
+
# h[s0] = 0
|
759
|
+
# h[s1] = 1
|
760
|
+
# h # => {"x"=>0, "x"=>1}
|
761
|
+
#
|
762
|
+
def compare_by_identity: () -> self
|
763
|
+
|
764
|
+
# <!--
|
765
|
+
# rdoc-file=hash.c
|
766
|
+
# - hash.compare_by_identity? -> true or false
|
767
|
+
# -->
|
768
|
+
# Returns `true` if #compare_by_identity has been called, `false` otherwise.
|
769
|
+
#
|
770
|
+
def compare_by_identity?: () -> bool
|
771
|
+
|
772
|
+
# <!--
|
773
|
+
# rdoc-file=hash.c
|
774
|
+
# - deconstruct_keys(p1)
|
775
|
+
# -->
|
776
|
+
#
|
777
|
+
def deconstruct_keys: (Array[K] | nil) -> self
|
778
|
+
|
779
|
+
# <!--
|
780
|
+
# rdoc-file=hash.c
|
781
|
+
# - hash.default -> object
|
782
|
+
# - hash.default(key) -> object
|
783
|
+
# -->
|
784
|
+
# Returns the default value for the given `key`. The returned value will be
|
785
|
+
# determined either by the default proc or by the default value. See [Default
|
786
|
+
# Values](rdoc-ref:Hash@Default+Values).
|
787
|
+
#
|
788
|
+
# With no argument, returns the current default value:
|
789
|
+
# h = {}
|
790
|
+
# h.default # => nil
|
791
|
+
#
|
792
|
+
# If `key` is given, returns the default value for `key`, regardless of whether
|
793
|
+
# that key exists:
|
794
|
+
# h = Hash.new { |hash, key| hash[key] = "No key #{key}"}
|
795
|
+
# h[:foo] = "Hello"
|
796
|
+
# h.default(:foo) # => "No key foo"
|
797
|
+
#
|
798
|
+
def default: (?K arg0) -> V?
|
799
|
+
|
800
|
+
# <!--
|
801
|
+
# rdoc-file=hash.c
|
802
|
+
# - hash.default = value -> object
|
803
|
+
# -->
|
804
|
+
# Sets the default value to `value`; returns `value`:
|
805
|
+
# h = {}
|
806
|
+
# h.default # => nil
|
807
|
+
# h.default = false # => false
|
808
|
+
# h.default # => false
|
809
|
+
#
|
810
|
+
# See [Default Values](rdoc-ref:Hash@Default+Values).
|
811
|
+
#
|
812
|
+
def default=: (V arg0) -> V
|
813
|
+
|
814
|
+
# <!--
|
815
|
+
# rdoc-file=hash.c
|
816
|
+
# - hash.default_proc -> proc or nil
|
817
|
+
# -->
|
818
|
+
# Returns the default proc for `self` (see [Default
|
819
|
+
# Values](rdoc-ref:Hash@Default+Values)):
|
820
|
+
# h = {}
|
821
|
+
# h.default_proc # => nil
|
822
|
+
# h.default_proc = proc {|hash, key| "Default value for #{key}" }
|
823
|
+
# h.default_proc.class # => Proc
|
824
|
+
#
|
825
|
+
def default_proc: () -> (Proc | nil)
|
826
|
+
|
827
|
+
# <!--
|
828
|
+
# rdoc-file=hash.c
|
829
|
+
# - hash.default_proc = proc -> proc
|
830
|
+
# -->
|
831
|
+
# Sets the default proc for `self` to `proc` (see [Default
|
832
|
+
# Values](rdoc-ref:Hash@Default+Values)):
|
833
|
+
# h = {}
|
834
|
+
# h.default_proc # => nil
|
835
|
+
# h.default_proc = proc { |hash, key| "Default value for #{key}" }
|
836
|
+
# h.default_proc.class # => Proc
|
837
|
+
# h.default_proc = nil
|
838
|
+
# h.default_proc # => nil
|
839
|
+
#
|
840
|
+
def default_proc=: (Proc | _ToProc | nil) -> (Proc | _ToProc | nil)
|
841
|
+
|
842
|
+
# <!--
|
843
|
+
# rdoc-file=hash.c
|
844
|
+
# - hash.delete(key) -> value or nil
|
845
|
+
# - hash.delete(key) {|key| ... } -> object
|
846
|
+
# -->
|
847
|
+
# Deletes the entry for the given `key` and returns its associated value.
|
848
|
+
#
|
849
|
+
# If no block is given and `key` is found, deletes the entry and returns the
|
850
|
+
# associated value:
|
851
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
852
|
+
# h.delete(:bar) # => 1
|
853
|
+
# h # => {:foo=>0, :baz=>2}
|
854
|
+
#
|
855
|
+
# If no block given and `key` is not found, returns `nil`.
|
856
|
+
#
|
857
|
+
# If a block is given and `key` is found, ignores the block, deletes the entry,
|
858
|
+
# and returns the associated value:
|
859
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
860
|
+
# h.delete(:baz) { |key| raise 'Will never happen'} # => 2
|
861
|
+
# h # => {:foo=>0, :bar=>1}
|
862
|
+
#
|
863
|
+
# If a block is given and `key` is not found, calls the block and returns the
|
864
|
+
# block's return value:
|
865
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
866
|
+
# h.delete(:nosuch) { |key| "Key #{key} not found" } # => "Key nosuch not found"
|
867
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2}
|
868
|
+
#
|
869
|
+
def delete: (K arg0) -> V?
|
870
|
+
| [U] (K arg0) { (K arg0) -> U } -> (U | V)
|
871
|
+
|
872
|
+
# <!--
|
873
|
+
# rdoc-file=hash.c
|
874
|
+
# - hash.delete_if {|key, value| ... } -> self
|
875
|
+
# - hash.delete_if -> new_enumerator
|
876
|
+
# -->
|
877
|
+
# If a block given, calls the block with each key-value pair; deletes each entry
|
878
|
+
# for which the block returns a truthy value; returns `self`:
|
879
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
880
|
+
# h.delete_if {|key, value| value > 0 } # => {:foo=>0}
|
881
|
+
#
|
882
|
+
# If no block given, returns a new Enumerator:
|
883
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
884
|
+
# e = h.delete_if # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:delete_if>
|
885
|
+
# e.each { |key, value| value > 0 } # => {:foo=>0}
|
886
|
+
#
|
887
|
+
def delete_if: () { (K, V) -> boolish } -> self
|
888
|
+
| () -> ::Enumerator[[ K, V ], self]
|
889
|
+
|
890
|
+
# <!--
|
891
|
+
# rdoc-file=hash.c
|
892
|
+
# - hash.dig(key, *identifiers) -> object
|
893
|
+
# -->
|
894
|
+
# Finds and returns the object in nested objects that is specified by `key` and
|
895
|
+
# `identifiers`. The nested objects may be instances of various classes. See
|
896
|
+
# [Dig Methods](rdoc-ref:dig_methods.rdoc).
|
897
|
+
#
|
898
|
+
# Nested Hashes:
|
899
|
+
# h = {foo: {bar: {baz: 2}}}
|
900
|
+
# h.dig(:foo) # => {:bar=>{:baz=>2}}
|
901
|
+
# h.dig(:foo, :bar) # => {:baz=>2}
|
902
|
+
# h.dig(:foo, :bar, :baz) # => 2
|
903
|
+
# h.dig(:foo, :bar, :BAZ) # => nil
|
904
|
+
#
|
905
|
+
# Nested Hashes and Arrays:
|
906
|
+
# h = {foo: {bar: [:a, :b, :c]}}
|
907
|
+
# h.dig(:foo, :bar, 2) # => :c
|
908
|
+
#
|
909
|
+
# This method will use the [default values](rdoc-ref:Hash@Default+Values) for
|
910
|
+
# keys that are not present:
|
911
|
+
# h = {foo: {bar: [:a, :b, :c]}}
|
912
|
+
# h.dig(:hello) # => nil
|
913
|
+
# h.default_proc = -> (hash, _key) { hash }
|
914
|
+
# h.dig(:hello, :world) # => h
|
915
|
+
# h.dig(:hello, :world, :foo, :bar, 2) # => :c
|
916
|
+
#
|
917
|
+
def dig: (K, *untyped) -> untyped
|
918
|
+
|
919
|
+
# <!-- rdoc-file=hash.c -->
|
920
|
+
# Calls the given block with each key-value pair; returns `self`:
|
921
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
922
|
+
# h.each_pair {|key, value| puts "#{key}: #{value}"} # => {:foo=>0, :bar=>1, :baz=>2}
|
923
|
+
#
|
924
|
+
# Output:
|
925
|
+
# foo: 0
|
926
|
+
# bar: 1
|
927
|
+
# baz: 2
|
928
|
+
#
|
929
|
+
# Returns a new Enumerator if no block given:
|
930
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
931
|
+
# e = h.each_pair # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:each_pair>
|
932
|
+
# h1 = e.each {|key, value| puts "#{key}: #{value}"}
|
933
|
+
# h1 # => {:foo=>0, :bar=>1, :baz=>2}
|
934
|
+
#
|
935
|
+
# Output:
|
936
|
+
# foo: 0
|
937
|
+
# bar: 1
|
938
|
+
# baz: 2
|
939
|
+
#
|
940
|
+
def each: () { ([ K, V ] arg0) -> untyped } -> self
|
941
|
+
| () -> ::Enumerator[[ K, V ], self]
|
942
|
+
|
943
|
+
# <!--
|
944
|
+
# rdoc-file=hash.c
|
945
|
+
# - hash.each_key {|key| ... } -> self
|
946
|
+
# - hash.each_key -> new_enumerator
|
947
|
+
# -->
|
948
|
+
# Calls the given block with each key; returns `self`:
|
949
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
950
|
+
# h.each_key {|key| puts key } # => {:foo=>0, :bar=>1, :baz=>2}
|
951
|
+
#
|
952
|
+
# Output:
|
953
|
+
# foo
|
954
|
+
# bar
|
955
|
+
# baz
|
956
|
+
#
|
957
|
+
# Returns a new Enumerator if no block given:
|
958
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
959
|
+
# e = h.each_key # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:each_key>
|
960
|
+
# h1 = e.each {|key| puts key }
|
961
|
+
# h1 # => {:foo=>0, :bar=>1, :baz=>2}
|
962
|
+
#
|
963
|
+
# Output:
|
964
|
+
# foo
|
965
|
+
# bar
|
966
|
+
# baz
|
967
|
+
#
|
968
|
+
def each_key: () { (K arg0) -> untyped } -> ::Hash[K, V]
|
969
|
+
| () -> ::Enumerator[K, self]
|
970
|
+
|
971
|
+
# <!--
|
972
|
+
# rdoc-file=hash.c
|
973
|
+
# - hash.each {|key, value| ... } -> self
|
974
|
+
# - hash.each_pair {|key, value| ... } -> self
|
975
|
+
# - hash.each -> new_enumerator
|
976
|
+
# - hash.each_pair -> new_enumerator
|
977
|
+
# -->
|
978
|
+
# Calls the given block with each key-value pair; returns `self`:
|
979
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
980
|
+
# h.each_pair {|key, value| puts "#{key}: #{value}"} # => {:foo=>0, :bar=>1, :baz=>2}
|
981
|
+
#
|
982
|
+
# Output:
|
983
|
+
# foo: 0
|
984
|
+
# bar: 1
|
985
|
+
# baz: 2
|
986
|
+
#
|
987
|
+
# Returns a new Enumerator if no block given:
|
988
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
989
|
+
# e = h.each_pair # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:each_pair>
|
990
|
+
# h1 = e.each {|key, value| puts "#{key}: #{value}"}
|
991
|
+
# h1 # => {:foo=>0, :bar=>1, :baz=>2}
|
992
|
+
#
|
993
|
+
# Output:
|
994
|
+
# foo: 0
|
995
|
+
# bar: 1
|
996
|
+
# baz: 2
|
997
|
+
#
|
998
|
+
alias each_pair each
|
999
|
+
|
1000
|
+
# <!--
|
1001
|
+
# rdoc-file=hash.c
|
1002
|
+
# - hash.each_value {|value| ... } -> self
|
1003
|
+
# - hash.each_value -> new_enumerator
|
1004
|
+
# -->
|
1005
|
+
# Calls the given block with each value; returns `self`:
|
1006
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1007
|
+
# h.each_value {|value| puts value } # => {:foo=>0, :bar=>1, :baz=>2}
|
1008
|
+
#
|
1009
|
+
# Output:
|
1010
|
+
# 0
|
1011
|
+
# 1
|
1012
|
+
# 2
|
1013
|
+
#
|
1014
|
+
# Returns a new Enumerator if no block given:
|
1015
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1016
|
+
# e = h.each_value # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:each_value>
|
1017
|
+
# h1 = e.each {|value| puts value }
|
1018
|
+
# h1 # => {:foo=>0, :bar=>1, :baz=>2}
|
1019
|
+
#
|
1020
|
+
# Output:
|
1021
|
+
# 0
|
1022
|
+
# 1
|
1023
|
+
# 2
|
1024
|
+
#
|
1025
|
+
def each_value: () { (V arg0) -> untyped } -> self
|
1026
|
+
| () -> ::Enumerator[V, self]
|
1027
|
+
|
1028
|
+
# <!--
|
1029
|
+
# rdoc-file=hash.c
|
1030
|
+
# - hash.empty? -> true or false
|
1031
|
+
# -->
|
1032
|
+
# Returns `true` if there are no hash entries, `false` otherwise:
|
1033
|
+
# {}.empty? # => true
|
1034
|
+
# {foo: 0, bar: 1, baz: 2}.empty? # => false
|
1035
|
+
#
|
1036
|
+
def empty?: () -> bool
|
1037
|
+
|
1038
|
+
# <!--
|
1039
|
+
# rdoc-file=hash.c
|
1040
|
+
# - hash.eql?(object) -> true or false
|
1041
|
+
# -->
|
1042
|
+
# Returns `true` if all of the following are true:
|
1043
|
+
# * `object` is a `Hash` object.
|
1044
|
+
# * `hash` and `object` have the same keys (regardless of order).
|
1045
|
+
# * For each key `key`, `h[key].eql?(object[key])`.
|
1046
|
+
#
|
1047
|
+
# Otherwise, returns `false`.
|
1048
|
+
#
|
1049
|
+
# h1 = {foo: 0, bar: 1, baz: 2}
|
1050
|
+
# h2 = {foo: 0, bar: 1, baz: 2}
|
1051
|
+
# h1.eql? h2 # => true
|
1052
|
+
# h3 = {baz: 2, bar: 1, foo: 0}
|
1053
|
+
# h1.eql? h3 # => true
|
1054
|
+
#
|
1055
|
+
def eql?: (untyped) -> bool
|
1056
|
+
|
1057
|
+
# <!--
|
1058
|
+
# rdoc-file=hash.c
|
1059
|
+
# - hsh.except(*keys) -> a_hash
|
1060
|
+
# -->
|
1061
|
+
# Returns a new `Hash` excluding entries for the given `keys`:
|
1062
|
+
# h = { a: 100, b: 200, c: 300 }
|
1063
|
+
# h.except(:a) #=> {:b=>200, :c=>300}
|
1064
|
+
#
|
1065
|
+
# Any given `keys` that are not found are ignored.
|
1066
|
+
#
|
1067
|
+
def except: (*K) -> ::Hash[K, V]
|
1068
|
+
|
1069
|
+
# <!--
|
1070
|
+
# rdoc-file=hash.c
|
1071
|
+
# - hash.fetch(key) -> object
|
1072
|
+
# - hash.fetch(key, default_value) -> object
|
1073
|
+
# - hash.fetch(key) {|key| ... } -> object
|
1074
|
+
# -->
|
1075
|
+
# Returns the value for the given `key`, if found.
|
1076
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1077
|
+
# h.fetch(:bar) # => 1
|
1078
|
+
#
|
1079
|
+
# If `key` is not found and no block was given, returns `default_value`:
|
1080
|
+
# {}.fetch(:nosuch, :default) # => :default
|
1081
|
+
#
|
1082
|
+
# If `key` is not found and a block was given, yields `key` to the block and
|
1083
|
+
# returns the block's return value:
|
1084
|
+
# {}.fetch(:nosuch) {|key| "No key #{key}"} # => "No key nosuch"
|
1085
|
+
#
|
1086
|
+
# Raises KeyError if neither `default_value` nor a block was given.
|
1087
|
+
#
|
1088
|
+
# Note that this method does not use the values of either #default or
|
1089
|
+
# #default_proc.
|
1090
|
+
#
|
1091
|
+
def fetch: (K arg0) -> V
|
1092
|
+
| [X] (K arg0, X arg1) -> (V | X)
|
1093
|
+
| [X] (K arg0) { (K arg0) -> X } -> (V | X)
|
1094
|
+
|
1095
|
+
# <!--
|
1096
|
+
# rdoc-file=hash.c
|
1097
|
+
# - hash.fetch_values(*keys) -> new_array
|
1098
|
+
# - hash.fetch_values(*keys) {|key| ... } -> new_array
|
1099
|
+
# -->
|
1100
|
+
# Returns a new Array containing the values associated with the given keys
|
1101
|
+
# *keys:
|
1102
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1103
|
+
# h.fetch_values(:baz, :foo) # => [2, 0]
|
1104
|
+
#
|
1105
|
+
# Returns a new empty Array if no arguments given.
|
1106
|
+
#
|
1107
|
+
# When a block is given, calls the block with each missing key, treating the
|
1108
|
+
# block's return value as the value for that key:
|
1109
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1110
|
+
# values = h.fetch_values(:bar, :foo, :bad, :bam) {|key| key.to_s}
|
1111
|
+
# values # => [1, 0, "bad", "bam"]
|
1112
|
+
#
|
1113
|
+
# When no block is given, raises an exception if any given key is not found.
|
1114
|
+
#
|
1115
|
+
def fetch_values: (*K) -> ::Array[V]
|
1116
|
+
| [X] (*K) { (K) -> X } -> ::Array[V | X]
|
1117
|
+
|
1118
|
+
# <!-- rdoc-file=hash.c -->
|
1119
|
+
# Returns a new `Hash` object whose entries are those for which the block
|
1120
|
+
# returns a truthy value:
|
1121
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1122
|
+
# h.select {|key, value| value < 2 } # => {:foo=>0, :bar=>1}
|
1123
|
+
#
|
1124
|
+
# Returns a new Enumerator if no block given:
|
1125
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1126
|
+
# e = h.select # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:select>
|
1127
|
+
# e.each {|key, value| value < 2 } # => {:foo=>0, :bar=>1}
|
1128
|
+
#
|
1129
|
+
def filter: () { (K, V) -> boolish } -> ::Hash[K, V]
|
1130
|
+
| () -> ::Enumerator[[ K, V ], ::Hash[K, V]]
|
1131
|
+
|
1132
|
+
# <!-- rdoc-file=hash.c -->
|
1133
|
+
# Returns `self`, whose entries are those for which the block returns a truthy
|
1134
|
+
# value:
|
1135
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1136
|
+
# h.select! {|key, value| value < 2 } => {:foo=>0, :bar=>1}
|
1137
|
+
#
|
1138
|
+
# Returns `nil` if no entries were removed.
|
1139
|
+
#
|
1140
|
+
# Returns a new Enumerator if no block given:
|
1141
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1142
|
+
# e = h.select! # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:select!>
|
1143
|
+
# e.each { |key, value| value < 2 } # => {:foo=>0, :bar=>1}
|
1144
|
+
#
|
1145
|
+
def filter!: () { (K, V) -> boolish } -> self?
|
1146
|
+
| () -> ::Enumerator[[ K, V ], self?]
|
1147
|
+
|
1148
|
+
# <!--
|
1149
|
+
# rdoc-file=hash.c
|
1150
|
+
# - hash.flatten -> new_array
|
1151
|
+
# - hash.flatten(level) -> new_array
|
1152
|
+
# -->
|
1153
|
+
# Returns a new Array object that is a 1-dimensional flattening of `self`.
|
1154
|
+
#
|
1155
|
+
# ---
|
1156
|
+
#
|
1157
|
+
# By default, nested Arrays are not flattened:
|
1158
|
+
# h = {foo: 0, bar: [:bat, 3], baz: 2}
|
1159
|
+
# h.flatten # => [:foo, 0, :bar, [:bat, 3], :baz, 2]
|
1160
|
+
#
|
1161
|
+
# Takes the depth of recursive flattening from Integer argument `level`:
|
1162
|
+
# h = {foo: 0, bar: [:bat, [:baz, [:bat, ]]]}
|
1163
|
+
# h.flatten(1) # => [:foo, 0, :bar, [:bat, [:baz, [:bat]]]]
|
1164
|
+
# h.flatten(2) # => [:foo, 0, :bar, :bat, [:baz, [:bat]]]
|
1165
|
+
# h.flatten(3) # => [:foo, 0, :bar, :bat, :baz, [:bat]]
|
1166
|
+
# h.flatten(4) # => [:foo, 0, :bar, :bat, :baz, :bat]
|
1167
|
+
#
|
1168
|
+
# When `level` is negative, flattens all nested Arrays:
|
1169
|
+
# h = {foo: 0, bar: [:bat, [:baz, [:bat, ]]]}
|
1170
|
+
# h.flatten(-1) # => [:foo, 0, :bar, :bat, :baz, :bat]
|
1171
|
+
# h.flatten(-2) # => [:foo, 0, :bar, :bat, :baz, :bat]
|
1172
|
+
#
|
1173
|
+
# When `level` is zero, returns the equivalent of #to_a :
|
1174
|
+
# h = {foo: 0, bar: [:bat, 3], baz: 2}
|
1175
|
+
# h.flatten(0) # => [[:foo, 0], [:bar, [:bat, 3]], [:baz, 2]]
|
1176
|
+
# h.flatten(0) == h.to_a # => true
|
1177
|
+
#
|
1178
|
+
def flatten: () -> ::Array[K | V]
|
1179
|
+
| (1 level) -> ::Array[K | V]
|
1180
|
+
| (Integer level) -> Array[untyped]
|
1181
|
+
|
1182
|
+
# <!-- rdoc-file=hash.c -->
|
1183
|
+
# Returns `true` if `key` is a key in `self`, otherwise `false`.
|
1184
|
+
#
|
1185
|
+
def has_key?: (K arg0) -> bool
|
1186
|
+
|
1187
|
+
# <!--
|
1188
|
+
# rdoc-file=hash.c
|
1189
|
+
# - hash.has_value?(value) -> true or false
|
1190
|
+
# - hash.value?(value) -> true or false
|
1191
|
+
# -->
|
1192
|
+
# Returns `true` if `value` is a value in `self`, otherwise `false`.
|
1193
|
+
#
|
1194
|
+
def has_value?: (V arg0) -> bool
|
1195
|
+
|
1196
|
+
# <!--
|
1197
|
+
# rdoc-file=hash.c
|
1198
|
+
# - hash.hash -> an_integer
|
1199
|
+
# -->
|
1200
|
+
# Returns the Integer hash-code for the hash.
|
1201
|
+
#
|
1202
|
+
# Two `Hash` objects have the same hash-code if their content is the same
|
1203
|
+
# (regardless of order):
|
1204
|
+
# h1 = {foo: 0, bar: 1, baz: 2}
|
1205
|
+
# h2 = {baz: 2, bar: 1, foo: 0}
|
1206
|
+
# h2.hash == h1.hash # => true
|
1207
|
+
# h2.eql? h1 # => true
|
1208
|
+
#
|
1209
|
+
def hash: () -> Integer
|
1210
|
+
|
1211
|
+
# <!--
|
1212
|
+
# rdoc-file=hash.c
|
1213
|
+
# - hash.include?(key) -> true or false
|
1214
|
+
# - hash.has_key?(key) -> true or false
|
1215
|
+
# - hash.key?(key) -> true or false
|
1216
|
+
# - hash.member?(key) -> true or false
|
1217
|
+
# -->
|
1218
|
+
# Returns `true` if `key` is a key in `self`, otherwise `false`.
|
1219
|
+
#
|
1220
|
+
alias include? has_key?
|
1221
|
+
|
1222
|
+
# <!--
|
1223
|
+
# rdoc-file=hash.c
|
1224
|
+
# - hash.inspect -> new_string
|
1225
|
+
# -->
|
1226
|
+
# Returns a new String containing the hash entries:
|
1227
|
+
#
|
1228
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1229
|
+
# h.inspect # => "{foo: 0, bar: 1, baz: 2}"
|
1230
|
+
#
|
1231
|
+
def inspect: () -> String
|
1232
|
+
|
1233
|
+
# <!--
|
1234
|
+
# rdoc-file=hash.c
|
1235
|
+
# - hash.invert -> new_hash
|
1236
|
+
# -->
|
1237
|
+
# Returns a new `Hash` object with the each key-value pair inverted:
|
1238
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1239
|
+
# h1 = h.invert
|
1240
|
+
# h1 # => {0=>:foo, 1=>:bar, 2=>:baz}
|
1241
|
+
#
|
1242
|
+
# Overwrites any repeated new keys: (see [Entry
|
1243
|
+
# Order](rdoc-ref:Hash@Entry+Order)):
|
1244
|
+
# h = {foo: 0, bar: 0, baz: 0}
|
1245
|
+
# h.invert # => {0=>:baz}
|
1246
|
+
#
|
1247
|
+
def invert: () -> ::Hash[V, K]
|
1248
|
+
|
1249
|
+
# <!--
|
1250
|
+
# rdoc-file=hash.c
|
1251
|
+
# - hash.keep_if {|key, value| ... } -> self
|
1252
|
+
# - hash.keep_if -> new_enumerator
|
1253
|
+
# -->
|
1254
|
+
# Calls the block for each key-value pair; retains the entry if the block
|
1255
|
+
# returns a truthy value; otherwise deletes the entry; returns `self`.
|
1256
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1257
|
+
# h.keep_if { |key, value| key.start_with?('b') } # => {:bar=>1, :baz=>2}
|
1258
|
+
#
|
1259
|
+
# Returns a new Enumerator if no block given:
|
1260
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1261
|
+
# e = h.keep_if # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:keep_if>
|
1262
|
+
# e.each { |key, value| key.start_with?('b') } # => {:bar=>1, :baz=>2}
|
1263
|
+
#
|
1264
|
+
def keep_if: () { (K, V) -> boolish } -> self
|
1265
|
+
| () -> ::Enumerator[[ K, V ], self]
|
1266
|
+
|
1267
|
+
# <!--
|
1268
|
+
# rdoc-file=hash.c
|
1269
|
+
# - hash.key(value) -> key or nil
|
1270
|
+
# -->
|
1271
|
+
# Returns the key for the first-found entry with the given `value` (see [Entry
|
1272
|
+
# Order](rdoc-ref:Hash@Entry+Order)):
|
1273
|
+
# h = {foo: 0, bar: 2, baz: 2}
|
1274
|
+
# h.key(0) # => :foo
|
1275
|
+
# h.key(2) # => :bar
|
1276
|
+
#
|
1277
|
+
# Returns `nil` if no such value is found.
|
1278
|
+
#
|
1279
|
+
def key: (V) -> K?
|
1280
|
+
|
1281
|
+
# <!-- rdoc-file=hash.c -->
|
1282
|
+
# Returns `true` if `key` is a key in `self`, otherwise `false`.
|
1283
|
+
#
|
1284
|
+
alias key? has_key?
|
1285
|
+
|
1286
|
+
# <!--
|
1287
|
+
# rdoc-file=hash.c
|
1288
|
+
# - hash.keys -> new_array
|
1289
|
+
# -->
|
1290
|
+
# Returns a new Array containing all keys in `self`:
|
1291
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1292
|
+
# h.keys # => [:foo, :bar, :baz]
|
1293
|
+
#
|
1294
|
+
def keys: () -> ::Array[K]
|
1295
|
+
|
1296
|
+
# <!-- rdoc-file=hash.c -->
|
1297
|
+
# Returns the count of entries in `self`:
|
1298
|
+
#
|
1299
|
+
# {foo: 0, bar: 1, baz: 2}.length # => 3
|
1300
|
+
#
|
1301
|
+
def length: () -> Integer
|
1302
|
+
|
1303
|
+
# <!-- rdoc-file=hash.c -->
|
1304
|
+
# Returns `true` if `key` is a key in `self`, otherwise `false`.
|
1305
|
+
#
|
1306
|
+
alias member? has_key?
|
1307
|
+
|
1308
|
+
# <!--
|
1309
|
+
# rdoc-file=hash.c
|
1310
|
+
# - hash.merge -> copy_of_self
|
1311
|
+
# - hash.merge(*other_hashes) -> new_hash
|
1312
|
+
# - hash.merge(*other_hashes) { |key, old_value, new_value| ... } -> new_hash
|
1313
|
+
# -->
|
1314
|
+
# Returns the new `Hash` formed by merging each of `other_hashes` into a copy of
|
1315
|
+
# `self`.
|
1316
|
+
#
|
1317
|
+
# Each argument in `other_hashes` must be a `Hash`.
|
1318
|
+
#
|
1319
|
+
# ---
|
1320
|
+
#
|
1321
|
+
# With arguments and no block:
|
1322
|
+
# * Returns the new `Hash` object formed by merging each successive `Hash` in
|
1323
|
+
# `other_hashes` into `self`.
|
1324
|
+
# * Each new-key entry is added at the end.
|
1325
|
+
# * Each duplicate-key entry's value overwrites the previous value.
|
1326
|
+
#
|
1327
|
+
# Example:
|
1328
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1329
|
+
# h1 = {bat: 3, bar: 4}
|
1330
|
+
# h2 = {bam: 5, bat:6}
|
1331
|
+
# h.merge(h1, h2) # => {:foo=>0, :bar=>4, :baz=>2, :bat=>6, :bam=>5}
|
1332
|
+
#
|
1333
|
+
# With arguments and a block:
|
1334
|
+
# * Returns a new `Hash` object that is the merge of `self` and each given
|
1335
|
+
# hash.
|
1336
|
+
# * The given hashes are merged left to right.
|
1337
|
+
# * Each new-key entry is added at the end.
|
1338
|
+
# * For each duplicate key:
|
1339
|
+
# * Calls the block with the key and the old and new values.
|
1340
|
+
# * The block's return value becomes the new value for the entry.
|
1341
|
+
#
|
1342
|
+
# Example:
|
1343
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1344
|
+
# h1 = {bat: 3, bar: 4}
|
1345
|
+
# h2 = {bam: 5, bat:6}
|
1346
|
+
# h3 = h.merge(h1, h2) { |key, old_value, new_value| old_value + new_value }
|
1347
|
+
# h3 # => {:foo=>0, :bar=>5, :baz=>2, :bat=>9, :bam=>5}
|
1348
|
+
#
|
1349
|
+
# With no arguments:
|
1350
|
+
# * Returns a copy of `self`.
|
1351
|
+
# * The block, if given, is ignored.
|
1352
|
+
#
|
1353
|
+
# Example:
|
1354
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1355
|
+
# h.merge # => {:foo=>0, :bar=>1, :baz=>2}
|
1356
|
+
# h1 = h.merge { |key, old_value, new_value| raise 'Cannot happen' }
|
1357
|
+
# h1 # => {:foo=>0, :bar=>1, :baz=>2}
|
1358
|
+
#
|
1359
|
+
def merge: [A, B] (*::Hash[A, B] other_hashes) -> ::Hash[A | K, B | V]
|
1360
|
+
| [A, B, C] (*::Hash[A, B] other_hashes) { (K key, V oldval, B newval) -> C } -> ::Hash[A | K, B | V | C]
|
1361
|
+
|
1362
|
+
# <!-- rdoc-file=hash.c -->
|
1363
|
+
# Merges each of `other_hashes` into `self`; returns `self`.
|
1364
|
+
#
|
1365
|
+
# Each argument in `other_hashes` must be a `Hash`.
|
1366
|
+
#
|
1367
|
+
# With arguments and no block:
|
1368
|
+
# * Returns `self`, after the given hashes are merged into it.
|
1369
|
+
# * The given hashes are merged left to right.
|
1370
|
+
# * Each new entry is added at the end.
|
1371
|
+
# * Each duplicate-key entry's value overwrites the previous value.
|
1372
|
+
#
|
1373
|
+
# Example:
|
1374
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1375
|
+
# h1 = {bat: 3, bar: 4}
|
1376
|
+
# h2 = {bam: 5, bat:6}
|
1377
|
+
# h.merge!(h1, h2) # => {:foo=>0, :bar=>4, :baz=>2, :bat=>6, :bam=>5}
|
1378
|
+
#
|
1379
|
+
# With arguments and a block:
|
1380
|
+
# * Returns `self`, after the given hashes are merged.
|
1381
|
+
# * The given hashes are merged left to right.
|
1382
|
+
# * Each new-key entry is added at the end.
|
1383
|
+
# * For each duplicate key:
|
1384
|
+
# * Calls the block with the key and the old and new values.
|
1385
|
+
# * The block's return value becomes the new value for the entry.
|
1386
|
+
#
|
1387
|
+
# Example:
|
1388
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1389
|
+
# h1 = {bat: 3, bar: 4}
|
1390
|
+
# h2 = {bam: 5, bat:6}
|
1391
|
+
# h3 = h.merge!(h1, h2) { |key, old_value, new_value| old_value + new_value }
|
1392
|
+
# h3 # => {:foo=>0, :bar=>5, :baz=>2, :bat=>9, :bam=>5}
|
1393
|
+
#
|
1394
|
+
# With no arguments:
|
1395
|
+
# * Returns `self`, unmodified.
|
1396
|
+
# * The block, if given, is ignored.
|
1397
|
+
#
|
1398
|
+
# Example:
|
1399
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1400
|
+
# h.merge # => {:foo=>0, :bar=>1, :baz=>2}
|
1401
|
+
# h1 = h.merge! { |key, old_value, new_value| raise 'Cannot happen' }
|
1402
|
+
# h1 # => {:foo=>0, :bar=>1, :baz=>2}
|
1403
|
+
#
|
1404
|
+
def merge!: (*::Hash[K, V] other_hashes) -> self
|
1405
|
+
| (*::Hash[K, V] other_hashes) { (K key, V oldval, V newval) -> V } -> self
|
1406
|
+
|
1407
|
+
# <!--
|
1408
|
+
# rdoc-file=hash.c
|
1409
|
+
# - hash.rassoc(value) -> new_array or nil
|
1410
|
+
# -->
|
1411
|
+
# Returns a new 2-element Array consisting of the key and value of the
|
1412
|
+
# first-found entry whose value is `==` to value (see [Entry
|
1413
|
+
# Order](rdoc-ref:Hash@Entry+Order)):
|
1414
|
+
# h = {foo: 0, bar: 1, baz: 1}
|
1415
|
+
# h.rassoc(1) # => [:bar, 1]
|
1416
|
+
#
|
1417
|
+
# Returns `nil` if no such value found.
|
1418
|
+
#
|
1419
|
+
def rassoc: (V) -> [ K, V ]?
|
1420
|
+
|
1421
|
+
# <!--
|
1422
|
+
# rdoc-file=hash.c
|
1423
|
+
# - hash.rehash -> self
|
1424
|
+
# -->
|
1425
|
+
# Rebuilds the hash table by recomputing the hash index for each key; returns
|
1426
|
+
# `self`.
|
1427
|
+
#
|
1428
|
+
# The hash table becomes invalid if the hash value of a key has changed after
|
1429
|
+
# the entry was created. See [Modifying an Active Hash
|
1430
|
+
# Key](rdoc-ref:Hash@Modifying+an+Active+Hash+Key).
|
1431
|
+
#
|
1432
|
+
def rehash: () -> self
|
1433
|
+
|
1434
|
+
# <!--
|
1435
|
+
# rdoc-file=hash.c
|
1436
|
+
# - hash.reject {|key, value| ... } -> new_hash
|
1437
|
+
# - hash.reject -> new_enumerator
|
1438
|
+
# -->
|
1439
|
+
# Returns a new `Hash` object whose entries are all those from `self` for which
|
1440
|
+
# the block returns `false` or `nil`:
|
1441
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1442
|
+
# h1 = h.reject {|key, value| key.start_with?('b') }
|
1443
|
+
# h1 # => {:foo=>0}
|
1444
|
+
#
|
1445
|
+
# Returns a new Enumerator if no block given:
|
1446
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1447
|
+
# e = h.reject # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:reject>
|
1448
|
+
# h1 = e.each {|key, value| key.start_with?('b') }
|
1449
|
+
# h1 # => {:foo=>0}
|
1450
|
+
#
|
1451
|
+
def reject: () -> ::Enumerator[[ K, V ], ::Hash[K, V]]
|
1452
|
+
| () { (K, V) -> boolish } -> ::Hash[K, V]
|
1453
|
+
|
1454
|
+
# <!--
|
1455
|
+
# rdoc-file=hash.c
|
1456
|
+
# - hash.reject! {|key, value| ... } -> self or nil
|
1457
|
+
# - hash.reject! -> new_enumerator
|
1458
|
+
# -->
|
1459
|
+
# Returns `self`, whose remaining entries are those for which the block returns
|
1460
|
+
# `false` or `nil`:
|
1461
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1462
|
+
# h.reject! {|key, value| value < 2 } # => {:baz=>2}
|
1463
|
+
#
|
1464
|
+
# Returns `nil` if no entries are removed.
|
1465
|
+
#
|
1466
|
+
# Returns a new Enumerator if no block given:
|
1467
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1468
|
+
# e = h.reject! # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:reject!>
|
1469
|
+
# e.each {|key, value| key.start_with?('b') } # => {:foo=>0}
|
1470
|
+
#
|
1471
|
+
def reject!: () -> ::Enumerator[[ K, V ], self?]
|
1472
|
+
| () { (K, V) -> boolish } -> self?
|
1473
|
+
|
1474
|
+
# <!-- rdoc-file=hash.c -->
|
1475
|
+
# Replaces the entire contents of `self` with the contents of `other_hash`;
|
1476
|
+
# returns `self`:
|
1477
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1478
|
+
# h.replace({bat: 3, bam: 4}) # => {:bat=>3, :bam=>4}
|
1479
|
+
#
|
1480
|
+
def replace: (Hash[K, V]) -> self
|
1481
|
+
|
1482
|
+
# <!--
|
1483
|
+
# rdoc-file=hash.c
|
1484
|
+
# - hash.select {|key, value| ... } -> new_hash
|
1485
|
+
# - hash.select -> new_enumerator
|
1486
|
+
# -->
|
1487
|
+
# Returns a new `Hash` object whose entries are those for which the block
|
1488
|
+
# returns a truthy value:
|
1489
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1490
|
+
# h.select {|key, value| value < 2 } # => {:foo=>0, :bar=>1}
|
1491
|
+
#
|
1492
|
+
# Returns a new Enumerator if no block given:
|
1493
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1494
|
+
# e = h.select # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:select>
|
1495
|
+
# e.each {|key, value| value < 2 } # => {:foo=>0, :bar=>1}
|
1496
|
+
#
|
1497
|
+
alias select filter
|
1498
|
+
|
1499
|
+
# <!--
|
1500
|
+
# rdoc-file=hash.c
|
1501
|
+
# - hash.select! {|key, value| ... } -> self or nil
|
1502
|
+
# - hash.select! -> new_enumerator
|
1503
|
+
# -->
|
1504
|
+
# Returns `self`, whose entries are those for which the block returns a truthy
|
1505
|
+
# value:
|
1506
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1507
|
+
# h.select! {|key, value| value < 2 } => {:foo=>0, :bar=>1}
|
1508
|
+
#
|
1509
|
+
# Returns `nil` if no entries were removed.
|
1510
|
+
#
|
1511
|
+
# Returns a new Enumerator if no block given:
|
1512
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1513
|
+
# e = h.select! # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:select!>
|
1514
|
+
# e.each { |key, value| value < 2 } # => {:foo=>0, :bar=>1}
|
1515
|
+
#
|
1516
|
+
alias select! filter!
|
1517
|
+
|
1518
|
+
# <!--
|
1519
|
+
# rdoc-file=hash.c
|
1520
|
+
# - hash.shift -> [key, value] or nil
|
1521
|
+
# -->
|
1522
|
+
# Removes the first hash entry (see [Entry Order](rdoc-ref:Hash@Entry+Order));
|
1523
|
+
# returns a 2-element Array containing the removed key and value:
|
1524
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1525
|
+
# h.shift # => [:foo, 0]
|
1526
|
+
# h # => {:bar=>1, :baz=>2}
|
1527
|
+
#
|
1528
|
+
# Returns nil if the hash is empty.
|
1529
|
+
#
|
1530
|
+
def shift: () -> [ K, V ]?
|
1531
|
+
|
1532
|
+
# <!--
|
1533
|
+
# rdoc-file=hash.c
|
1534
|
+
# - hash.length -> integer
|
1535
|
+
# - hash.size -> integer
|
1536
|
+
# -->
|
1537
|
+
# Returns the count of entries in `self`:
|
1538
|
+
#
|
1539
|
+
# {foo: 0, bar: 1, baz: 2}.length # => 3
|
1540
|
+
#
|
1541
|
+
alias size length
|
1542
|
+
|
1543
|
+
# <!--
|
1544
|
+
# rdoc-file=hash.c
|
1545
|
+
# - hash.slice(*keys) -> new_hash
|
1546
|
+
# -->
|
1547
|
+
# Returns a new `Hash` object containing the entries for the given `keys`:
|
1548
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1549
|
+
# h.slice(:baz, :foo) # => {:baz=>2, :foo=>0}
|
1550
|
+
#
|
1551
|
+
# Any given `keys` that are not found are ignored.
|
1552
|
+
#
|
1553
|
+
def slice: (*K) -> ::Hash[K, V]
|
1554
|
+
|
1555
|
+
# <!-- rdoc-file=hash.c -->
|
1556
|
+
# Associates the given `value` with the given `key`; returns `value`.
|
1557
|
+
#
|
1558
|
+
# If the given `key` exists, replaces its value with the given `value`; the
|
1559
|
+
# ordering is not affected (see [Entry Order](rdoc-ref:Hash@Entry+Order)):
|
1560
|
+
# h = {foo: 0, bar: 1}
|
1561
|
+
# h[:foo] = 2 # => 2
|
1562
|
+
# h.store(:bar, 3) # => 3
|
1563
|
+
# h # => {:foo=>2, :bar=>3}
|
1564
|
+
#
|
1565
|
+
# If `key` does not exist, adds the `key` and `value`; the new entry is last in
|
1566
|
+
# the order (see [Entry Order](rdoc-ref:Hash@Entry+Order)):
|
1567
|
+
# h = {foo: 0, bar: 1}
|
1568
|
+
# h[:baz] = 2 # => 2
|
1569
|
+
# h.store(:bat, 3) # => 3
|
1570
|
+
# h # => {:foo=>0, :bar=>1, :baz=>2, :bat=>3}
|
1571
|
+
#
|
1572
|
+
alias store []=
|
1573
|
+
|
1574
|
+
# <!--
|
1575
|
+
# rdoc-file=hash.c
|
1576
|
+
# - hash.to_a -> new_array
|
1577
|
+
# -->
|
1578
|
+
# Returns a new Array of 2-element Array objects; each nested Array contains a
|
1579
|
+
# key-value pair from `self`:
|
1580
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1581
|
+
# h.to_a # => [[:foo, 0], [:bar, 1], [:baz, 2]]
|
1582
|
+
#
|
1583
|
+
def to_a: () -> ::Array[[ K, V ]]
|
1584
|
+
|
1585
|
+
# <!--
|
1586
|
+
# rdoc-file=hash.c
|
1587
|
+
# - hash.to_h -> self or new_hash
|
1588
|
+
# - hash.to_h {|key, value| ... } -> new_hash
|
1589
|
+
# -->
|
1590
|
+
# For an instance of `Hash`, returns `self`.
|
1591
|
+
#
|
1592
|
+
# For a subclass of `Hash`, returns a new `Hash` containing the content of
|
1593
|
+
# `self`.
|
1594
|
+
#
|
1595
|
+
# When a block is given, returns a new `Hash` object whose content is based on
|
1596
|
+
# the block; the block should return a 2-element Array object specifying the
|
1597
|
+
# key-value pair to be included in the returned Array:
|
1598
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1599
|
+
# h1 = h.to_h {|key, value| [value, key] }
|
1600
|
+
# h1 # => {0=>:foo, 1=>:bar, 2=>:baz}
|
1601
|
+
#
|
1602
|
+
def to_h: () -> Hash[K, V]
|
1603
|
+
| [A, B] () { (K, V) -> [ A, B ] } -> Hash[A, B]
|
1604
|
+
|
1605
|
+
# <!--
|
1606
|
+
# rdoc-file=hash.c
|
1607
|
+
# - hash.to_hash -> self
|
1608
|
+
# -->
|
1609
|
+
# Returns `self`.
|
1610
|
+
#
|
1611
|
+
def to_hash: () -> self
|
1612
|
+
|
1613
|
+
# <!--
|
1614
|
+
# rdoc-file=hash.c
|
1615
|
+
# - hash.to_proc -> proc
|
1616
|
+
# -->
|
1617
|
+
# Returns a Proc object that maps a key to its value:
|
1618
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1619
|
+
# proc = h.to_proc
|
1620
|
+
# proc.class # => Proc
|
1621
|
+
# proc.call(:foo) # => 0
|
1622
|
+
# proc.call(:bar) # => 1
|
1623
|
+
# proc.call(:nosuch) # => nil
|
1624
|
+
#
|
1625
|
+
def to_proc: () -> ^(K) -> V?
|
1626
|
+
|
1627
|
+
# <!-- rdoc-file=hash.c -->
|
1628
|
+
# Returns a new String containing the hash entries:
|
1629
|
+
#
|
1630
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1631
|
+
# h.inspect # => "{foo: 0, bar: 1, baz: 2}"
|
1632
|
+
#
|
1633
|
+
alias to_s inspect
|
1634
|
+
|
1635
|
+
# <!--
|
1636
|
+
# rdoc-file=hash.c
|
1637
|
+
# - hash.transform_keys {|key| ... } -> new_hash
|
1638
|
+
# - hash.transform_keys(hash2) -> new_hash
|
1639
|
+
# - hash.transform_keys(hash2) {|other_key| ...} -> new_hash
|
1640
|
+
# - hash.transform_keys -> new_enumerator
|
1641
|
+
# -->
|
1642
|
+
# Returns a new `Hash` object; each entry has:
|
1643
|
+
# * A key provided by the block.
|
1644
|
+
# * The value from `self`.
|
1645
|
+
#
|
1646
|
+
# An optional hash argument can be provided to map keys to new keys. Any key not
|
1647
|
+
# given will be mapped using the provided block, or remain the same if no block
|
1648
|
+
# is given.
|
1649
|
+
#
|
1650
|
+
# Transform keys:
|
1651
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1652
|
+
# h1 = h.transform_keys {|key| key.to_s }
|
1653
|
+
# h1 # => {"foo"=>0, "bar"=>1, "baz"=>2}
|
1654
|
+
#
|
1655
|
+
# h.transform_keys(foo: :bar, bar: :foo)
|
1656
|
+
# #=> {bar: 0, foo: 1, baz: 2}
|
1657
|
+
#
|
1658
|
+
# h.transform_keys(foo: :hello, &:to_s)
|
1659
|
+
# #=> {:hello=>0, "bar"=>1, "baz"=>2}
|
1660
|
+
#
|
1661
|
+
# Overwrites values for duplicate keys:
|
1662
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1663
|
+
# h1 = h.transform_keys {|key| :bat }
|
1664
|
+
# h1 # => {:bat=>2}
|
1665
|
+
#
|
1666
|
+
# Returns a new Enumerator if no block given:
|
1667
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1668
|
+
# e = h.transform_keys # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:transform_keys>
|
1669
|
+
# h1 = e.each { |key| key.to_s }
|
1670
|
+
# h1 # => {"foo"=>0, "bar"=>1, "baz"=>2}
|
1671
|
+
#
|
1672
|
+
def transform_keys: () -> Enumerator[K, Hash[untyped, V]]
|
1673
|
+
| [A] () { (K) -> A } -> Hash[A, V]
|
1674
|
+
|
1675
|
+
# <!--
|
1676
|
+
# rdoc-file=hash.c
|
1677
|
+
# - hash.transform_keys! {|key| ... } -> self
|
1678
|
+
# - hash.transform_keys!(hash2) -> self
|
1679
|
+
# - hash.transform_keys!(hash2) {|other_key| ...} -> self
|
1680
|
+
# - hash.transform_keys! -> new_enumerator
|
1681
|
+
# -->
|
1682
|
+
# Same as Hash#transform_keys but modifies the receiver in place instead of
|
1683
|
+
# returning a new hash.
|
1684
|
+
#
|
1685
|
+
def transform_keys!: () -> Enumerator[K, self]
|
1686
|
+
| () { (K) -> K } -> self
|
1687
|
+
|
1688
|
+
# <!--
|
1689
|
+
# rdoc-file=hash.c
|
1690
|
+
# - hash.transform_values {|value| ... } -> new_hash
|
1691
|
+
# - hash.transform_values -> new_enumerator
|
1692
|
+
# -->
|
1693
|
+
# Returns a new `Hash` object; each entry has:
|
1694
|
+
# * A key from `self`.
|
1695
|
+
# * A value provided by the block.
|
1696
|
+
#
|
1697
|
+
# Transform values:
|
1698
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1699
|
+
# h1 = h.transform_values {|value| value * 100}
|
1700
|
+
# h1 # => {:foo=>0, :bar=>100, :baz=>200}
|
1701
|
+
#
|
1702
|
+
# Returns a new Enumerator if no block given:
|
1703
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1704
|
+
# e = h.transform_values # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:transform_values>
|
1705
|
+
# h1 = e.each { |value| value * 100}
|
1706
|
+
# h1 # => {:foo=>0, :bar=>100, :baz=>200}
|
1707
|
+
#
|
1708
|
+
def transform_values: () -> Enumerator[V, Hash[K, untyped]]
|
1709
|
+
| [A] () { (V) -> A } -> Hash[K, A]
|
1710
|
+
|
1711
|
+
# <!--
|
1712
|
+
# rdoc-file=hash.c
|
1713
|
+
# - hash.transform_values! {|value| ... } -> self
|
1714
|
+
# - hash.transform_values! -> new_enumerator
|
1715
|
+
# -->
|
1716
|
+
# Returns `self`, whose keys are unchanged, and whose values are determined by
|
1717
|
+
# the given block.
|
1718
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1719
|
+
# h.transform_values! {|value| value * 100} # => {:foo=>0, :bar=>100, :baz=>200}
|
1720
|
+
#
|
1721
|
+
# Returns a new Enumerator if no block given:
|
1722
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1723
|
+
# e = h.transform_values! # => #<Enumerator: {:foo=>0, :bar=>100, :baz=>200}:transform_values!>
|
1724
|
+
# h1 = e.each {|value| value * 100}
|
1725
|
+
# h1 # => {:foo=>0, :bar=>100, :baz=>200}
|
1726
|
+
#
|
1727
|
+
def transform_values!: () -> Enumerator[V, self]
|
1728
|
+
| () { (V) -> V } -> self
|
1729
|
+
|
1730
|
+
# <!--
|
1731
|
+
# rdoc-file=hash.c
|
1732
|
+
# - hash.merge! -> self
|
1733
|
+
# - hash.merge!(*other_hashes) -> self
|
1734
|
+
# - hash.merge!(*other_hashes) { |key, old_value, new_value| ... } -> self
|
1735
|
+
# -->
|
1736
|
+
# Merges each of `other_hashes` into `self`; returns `self`.
|
1737
|
+
#
|
1738
|
+
# Each argument in `other_hashes` must be a `Hash`.
|
1739
|
+
#
|
1740
|
+
# With arguments and no block:
|
1741
|
+
# * Returns `self`, after the given hashes are merged into it.
|
1742
|
+
# * The given hashes are merged left to right.
|
1743
|
+
# * Each new entry is added at the end.
|
1744
|
+
# * Each duplicate-key entry's value overwrites the previous value.
|
1745
|
+
#
|
1746
|
+
# Example:
|
1747
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1748
|
+
# h1 = {bat: 3, bar: 4}
|
1749
|
+
# h2 = {bam: 5, bat:6}
|
1750
|
+
# h.merge!(h1, h2) # => {:foo=>0, :bar=>4, :baz=>2, :bat=>6, :bam=>5}
|
1751
|
+
#
|
1752
|
+
# With arguments and a block:
|
1753
|
+
# * Returns `self`, after the given hashes are merged.
|
1754
|
+
# * The given hashes are merged left to right.
|
1755
|
+
# * Each new-key entry is added at the end.
|
1756
|
+
# * For each duplicate key:
|
1757
|
+
# * Calls the block with the key and the old and new values.
|
1758
|
+
# * The block's return value becomes the new value for the entry.
|
1759
|
+
#
|
1760
|
+
# Example:
|
1761
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1762
|
+
# h1 = {bat: 3, bar: 4}
|
1763
|
+
# h2 = {bam: 5, bat:6}
|
1764
|
+
# h3 = h.merge!(h1, h2) { |key, old_value, new_value| old_value + new_value }
|
1765
|
+
# h3 # => {:foo=>0, :bar=>5, :baz=>2, :bat=>9, :bam=>5}
|
1766
|
+
#
|
1767
|
+
# With no arguments:
|
1768
|
+
# * Returns `self`, unmodified.
|
1769
|
+
# * The block, if given, is ignored.
|
1770
|
+
#
|
1771
|
+
# Example:
|
1772
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1773
|
+
# h.merge # => {:foo=>0, :bar=>1, :baz=>2}
|
1774
|
+
# h1 = h.merge! { |key, old_value, new_value| raise 'Cannot happen' }
|
1775
|
+
# h1 # => {:foo=>0, :bar=>1, :baz=>2}
|
1776
|
+
#
|
1777
|
+
alias update merge!
|
1778
|
+
|
1779
|
+
# <!-- rdoc-file=hash.c -->
|
1780
|
+
# Returns `true` if `value` is a value in `self`, otherwise `false`.
|
1781
|
+
#
|
1782
|
+
alias value? has_value?
|
1783
|
+
|
1784
|
+
# <!--
|
1785
|
+
# rdoc-file=hash.c
|
1786
|
+
# - hash.values -> new_array
|
1787
|
+
# -->
|
1788
|
+
# Returns a new Array containing all values in `self`:
|
1789
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1790
|
+
# h.values # => [0, 1, 2]
|
1791
|
+
#
|
1792
|
+
def values: () -> ::Array[V]
|
1793
|
+
|
1794
|
+
# <!--
|
1795
|
+
# rdoc-file=hash.c
|
1796
|
+
# - hash.values_at(*keys) -> new_array
|
1797
|
+
# -->
|
1798
|
+
# Returns a new Array containing values for the given `keys`:
|
1799
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1800
|
+
# h.values_at(:baz, :foo) # => [2, 0]
|
1801
|
+
#
|
1802
|
+
# The [default values](rdoc-ref:Hash@Default+Values) are returned for any keys
|
1803
|
+
# that are not found:
|
1804
|
+
# h.values_at(:hello, :foo) # => [nil, 0]
|
1805
|
+
#
|
1806
|
+
def values_at: (*K arg0) -> ::Array[V?]
|
1807
|
+
|
1808
|
+
private
|
1809
|
+
|
1810
|
+
# <!--
|
1811
|
+
# rdoc-file=hash.rb
|
1812
|
+
# - Hash.new(default_value = nil) -> new_hash
|
1813
|
+
# - Hash.new(default_value = nil, capacity: size) -> new_hash
|
1814
|
+
# - Hash.new {|hash, key| ... } -> new_hash
|
1815
|
+
# - Hash.new(capacity: size) {|hash, key| ... } -> new_hash
|
1816
|
+
# -->
|
1817
|
+
# Returns a new empty `Hash` object.
|
1818
|
+
#
|
1819
|
+
# The initial default value and initial default proc for the new hash depend on
|
1820
|
+
# which form above was used. See [Default Values](rdoc-ref:Hash@Default+Values).
|
1821
|
+
#
|
1822
|
+
# If neither an argument nor a block is given, initializes both the default
|
1823
|
+
# value and the default proc to `nil`:
|
1824
|
+
# h = Hash.new
|
1825
|
+
# h.default # => nil
|
1826
|
+
# h.default_proc # => nil
|
1827
|
+
#
|
1828
|
+
# If argument `default_value` is given but no block is given, initializes the
|
1829
|
+
# default value to the given `default_value` and the default proc to `nil`:
|
1830
|
+
# h = Hash.new(false)
|
1831
|
+
# h.default # => false
|
1832
|
+
# h.default_proc # => nil
|
1833
|
+
#
|
1834
|
+
# If a block is given but no `default_value`, stores the block as the default
|
1835
|
+
# proc and sets the default value to `nil`:
|
1836
|
+
# h = Hash.new {|hash, key| "Default value for #{key}" }
|
1837
|
+
# h.default # => nil
|
1838
|
+
# h.default_proc.class # => Proc
|
1839
|
+
# h[:nosuch] # => "Default value for nosuch"
|
1840
|
+
#
|
1841
|
+
# If both a block and a `default_value` are given, raises an `ArgumentError`
|
1842
|
+
#
|
1843
|
+
# If the optional keyword argument `capacity` is given, the hash will be
|
1844
|
+
# allocated with enough capacity to accommodate this many keys without having to
|
1845
|
+
# be resized.
|
1846
|
+
#
|
1847
|
+
def initialize: (?capacity: int) -> void
|
1848
|
+
| [V] (V default, ?capacity: int) -> void
|
1849
|
+
| [A, B] (?capacity: int) { (Hash[A, B] hash, A key) -> B } -> void
|
1850
|
+
|
1851
|
+
# <!--
|
1852
|
+
# rdoc-file=hash.c
|
1853
|
+
# - hash.replace(other_hash) -> self
|
1854
|
+
# -->
|
1855
|
+
# Replaces the entire contents of `self` with the contents of `other_hash`;
|
1856
|
+
# returns `self`:
|
1857
|
+
# h = {foo: 0, bar: 1, baz: 2}
|
1858
|
+
# h.replace({bat: 3, bam: 4}) # => {:bat=>3, :bam=>4}
|
1859
|
+
#
|
1860
|
+
def initialize_copy: (self object) -> self
|
1861
|
+
end
|