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/range.rbs
ADDED
@@ -0,0 +1,1107 @@
|
|
1
|
+
# <!-- rdoc-file=range.c -->
|
2
|
+
# A Range object represents a collection of values that are between given begin
|
3
|
+
# and end values.
|
4
|
+
#
|
5
|
+
# You can create an Range object explicitly with:
|
6
|
+
#
|
7
|
+
# * A [range literal](rdoc-ref:syntax/literals.rdoc@Range+Literals):
|
8
|
+
#
|
9
|
+
# # Ranges that use '..' to include the given end value.
|
10
|
+
# (1..4).to_a # => [1, 2, 3, 4]
|
11
|
+
# ('a'..'d').to_a # => ["a", "b", "c", "d"]
|
12
|
+
# # Ranges that use '...' to exclude the given end value.
|
13
|
+
# (1...4).to_a # => [1, 2, 3]
|
14
|
+
# ('a'...'d').to_a # => ["a", "b", "c"]
|
15
|
+
#
|
16
|
+
# * Method Range.new:
|
17
|
+
#
|
18
|
+
# # Ranges that by default include the given end value. Range.new(1, 4).to_a
|
19
|
+
# # => [1, 2, 3, 4] Range.new('a', 'd').to_a # => ["a", "b", "c", "d"] #
|
20
|
+
# Ranges that use third argument `exclude_end` to exclude the given end
|
21
|
+
# value. Range.new(1, 4, true).to_a # => [1, 2, 3] Range.new('a', 'd',
|
22
|
+
# true).to_a # => ["a", "b", "c"]
|
23
|
+
#
|
24
|
+
# ## Beginless Ranges
|
25
|
+
#
|
26
|
+
# A *beginless* *range* has a definite end value, but a `nil` begin value. Such
|
27
|
+
# a range includes all values up to the end value.
|
28
|
+
#
|
29
|
+
# r = (..4) # => nil..4
|
30
|
+
# r.begin # => nil
|
31
|
+
# r.include?(-50) # => true
|
32
|
+
# r.include?(4) # => true
|
33
|
+
#
|
34
|
+
# r = (...4) # => nil...4
|
35
|
+
# r.include?(4) # => false
|
36
|
+
#
|
37
|
+
# Range.new(nil, 4) # => nil..4
|
38
|
+
# Range.new(nil, 4, true) # => nil...4
|
39
|
+
#
|
40
|
+
# A beginless range may be used to slice an array:
|
41
|
+
#
|
42
|
+
# a = [1, 2, 3, 4]
|
43
|
+
# # Include the third array element in the slice
|
44
|
+
# r = (..2) # => nil..2
|
45
|
+
# a[r] # => [1, 2, 3]
|
46
|
+
# # Exclude the third array element from the slice
|
47
|
+
# r = (...2) # => nil...2
|
48
|
+
# a[r] # => [1, 2]
|
49
|
+
#
|
50
|
+
# Method `each` for a beginless range raises an exception.
|
51
|
+
#
|
52
|
+
# ## Endless Ranges
|
53
|
+
#
|
54
|
+
# An *endless* *range* has a definite begin value, but a `nil` end value. Such a
|
55
|
+
# range includes all values from the begin value.
|
56
|
+
#
|
57
|
+
# r = (1..) # => 1..
|
58
|
+
# r.end # => nil
|
59
|
+
# r.include?(50) # => true
|
60
|
+
#
|
61
|
+
# Range.new(1, nil) # => 1..
|
62
|
+
#
|
63
|
+
# The literal for an endless range may be written with either two dots or three.
|
64
|
+
# The range has the same elements, either way. But note that the two are not
|
65
|
+
# equal:
|
66
|
+
#
|
67
|
+
# r0 = (1..) # => 1..
|
68
|
+
# r1 = (1...) # => 1...
|
69
|
+
# r0.begin == r1.begin # => true
|
70
|
+
# r0.end == r1.end # => true
|
71
|
+
# r0 == r1 # => false
|
72
|
+
#
|
73
|
+
# An endless range may be used to slice an array:
|
74
|
+
#
|
75
|
+
# a = [1, 2, 3, 4]
|
76
|
+
# r = (2..) # => 2..
|
77
|
+
# a[r] # => [3, 4]
|
78
|
+
#
|
79
|
+
# Method `each` for an endless range calls the given block indefinitely:
|
80
|
+
#
|
81
|
+
# a = []
|
82
|
+
# r = (1..)
|
83
|
+
# r.each do |i|
|
84
|
+
# a.push(i) if i.even?
|
85
|
+
# break if i > 10
|
86
|
+
# end
|
87
|
+
# a # => [2, 4, 6, 8, 10]
|
88
|
+
#
|
89
|
+
# A range can be both beginless and endless. For literal beginless, endless
|
90
|
+
# ranges, at least the beginning or end of the range must be given as an
|
91
|
+
# explicit nil value. It is recommended to use an explicit nil beginning and
|
92
|
+
# implicit nil end, since that is what Ruby uses for Range#inspect:
|
93
|
+
#
|
94
|
+
# (nil..) # => (nil..)
|
95
|
+
# (..nil) # => (nil..)
|
96
|
+
# (nil..nil) # => (nil..)
|
97
|
+
#
|
98
|
+
# ## Ranges and Other Classes
|
99
|
+
#
|
100
|
+
# An object may be put into a range if its class implements instance method
|
101
|
+
# `#<=>`. Ruby core classes that do so include Array, Complex, File::Stat,
|
102
|
+
# Float, Integer, Kernel, Module, Numeric, Rational, String, Symbol, and Time.
|
103
|
+
#
|
104
|
+
# Example:
|
105
|
+
#
|
106
|
+
# t0 = Time.now # => 2021-09-19 09:22:48.4854986 -0500
|
107
|
+
# t1 = Time.now # => 2021-09-19 09:22:56.0365079 -0500
|
108
|
+
# t2 = Time.now # => 2021-09-19 09:23:08.5263283 -0500
|
109
|
+
# (t0..t2).include?(t1) # => true
|
110
|
+
# (t0..t1).include?(t2) # => false
|
111
|
+
#
|
112
|
+
# A range can be iterated over only if its elements implement instance method
|
113
|
+
# `succ`. Ruby core classes that do so include Integer, String, and Symbol (but
|
114
|
+
# not the other classes mentioned above).
|
115
|
+
#
|
116
|
+
# Iterator methods include:
|
117
|
+
#
|
118
|
+
# * In Range itself: #each, #step, and #%
|
119
|
+
# * Included from module Enumerable: #each_entry, #each_with_index,
|
120
|
+
# #each_with_object, #each_slice, #each_cons, and #reverse_each.
|
121
|
+
#
|
122
|
+
# Example:
|
123
|
+
#
|
124
|
+
# a = []
|
125
|
+
# (1..4).each {|i| a.push(i) }
|
126
|
+
# a # => [1, 2, 3, 4]
|
127
|
+
#
|
128
|
+
# ## Ranges and User-Defined Classes
|
129
|
+
#
|
130
|
+
# A user-defined class that is to be used in a range must implement instance
|
131
|
+
# method `#<=>`; see Integer#<=>. To make iteration available, it must also
|
132
|
+
# implement instance method `succ`; see Integer#succ.
|
133
|
+
#
|
134
|
+
# The class below implements both `#<=>` and `succ`, and so can be used both to
|
135
|
+
# construct ranges and to iterate over them. Note that the Comparable module is
|
136
|
+
# included so the `==` method is defined in terms of `#<=>`.
|
137
|
+
#
|
138
|
+
# # Represent a string of 'X' characters.
|
139
|
+
# class Xs
|
140
|
+
# include Comparable
|
141
|
+
# attr_accessor :length
|
142
|
+
# def initialize(n)
|
143
|
+
# @length = n
|
144
|
+
# end
|
145
|
+
# def succ
|
146
|
+
# Xs.new(@length + 1)
|
147
|
+
# end
|
148
|
+
# def <=>(other)
|
149
|
+
# @length <=> other.length
|
150
|
+
# end
|
151
|
+
# def to_s
|
152
|
+
# sprintf "%2d #{inspect}", @length
|
153
|
+
# end
|
154
|
+
# def inspect
|
155
|
+
# 'X' * @length
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
#
|
159
|
+
# r = Xs.new(3)..Xs.new(6) #=> XXX..XXXXXX
|
160
|
+
# r.to_a #=> [XXX, XXXX, XXXXX, XXXXXX]
|
161
|
+
# r.include?(Xs.new(5)) #=> true
|
162
|
+
# r.include?(Xs.new(7)) #=> false
|
163
|
+
#
|
164
|
+
# ## What's Here
|
165
|
+
#
|
166
|
+
# First, what's elsewhere. Class Range:
|
167
|
+
#
|
168
|
+
# * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
|
169
|
+
# * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
|
170
|
+
# provides dozens of additional methods.
|
171
|
+
#
|
172
|
+
# Here, class Range provides methods that are useful for:
|
173
|
+
#
|
174
|
+
# * [Creating a Range](rdoc-ref:Range@Methods+for+Creating+a+Range)
|
175
|
+
# * [Querying](rdoc-ref:Range@Methods+for+Querying)
|
176
|
+
# * [Comparing](rdoc-ref:Range@Methods+for+Comparing)
|
177
|
+
# * [Iterating](rdoc-ref:Range@Methods+for+Iterating)
|
178
|
+
# * [Converting](rdoc-ref:Range@Methods+for+Converting)
|
179
|
+
# * [Methods for Working with
|
180
|
+
# JSON](rdoc-ref:Range@Methods+for+Working+with+JSON)
|
181
|
+
#
|
182
|
+
# ### Methods for Creating a Range
|
183
|
+
#
|
184
|
+
# * ::new: Returns a new range.
|
185
|
+
#
|
186
|
+
# ### Methods for Querying
|
187
|
+
#
|
188
|
+
# * #begin: Returns the begin value given for `self`.
|
189
|
+
# * #bsearch: Returns an element from `self` selected by a binary search.
|
190
|
+
# * #count: Returns a count of elements in `self`.
|
191
|
+
# * #end: Returns the end value given for `self`.
|
192
|
+
# * #exclude_end?: Returns whether the end object is excluded.
|
193
|
+
# * #first: Returns the first elements of `self`.
|
194
|
+
# * #hash: Returns the integer hash code.
|
195
|
+
# * #last: Returns the last elements of `self`.
|
196
|
+
# * #max: Returns the maximum values in `self`.
|
197
|
+
# * #min: Returns the minimum values in `self`.
|
198
|
+
# * #minmax: Returns the minimum and maximum values in `self`.
|
199
|
+
# * #size: Returns the count of elements in `self`.
|
200
|
+
#
|
201
|
+
# ### Methods for Comparing
|
202
|
+
#
|
203
|
+
# * #==: Returns whether a given object is equal to `self` (uses #==).
|
204
|
+
# * #===: Returns whether the given object is between the begin and end
|
205
|
+
# values.
|
206
|
+
# * #cover?: Returns whether a given object is within `self`.
|
207
|
+
# * #eql?: Returns whether a given object is equal to `self` (uses #eql?).
|
208
|
+
# * #include? (aliased as #member?): Returns whether a given object is an
|
209
|
+
# element of `self`.
|
210
|
+
#
|
211
|
+
# ### Methods for Iterating
|
212
|
+
#
|
213
|
+
# * #%: Requires argument `n`; calls the block with each `n`-th element of
|
214
|
+
# `self`.
|
215
|
+
# * #each: Calls the block with each element of `self`.
|
216
|
+
# * #step: Takes optional argument `n` (defaults to 1); calls the block with
|
217
|
+
# each `n`-th element of `self`.
|
218
|
+
#
|
219
|
+
# ### Methods for Converting
|
220
|
+
#
|
221
|
+
# * #inspect: Returns a string representation of `self` (uses #inspect).
|
222
|
+
# * #to_a (aliased as #entries): Returns elements of `self` in an array.
|
223
|
+
# * #to_s: Returns a string representation of `self` (uses #to_s).
|
224
|
+
#
|
225
|
+
# ### Methods for Working with JSON
|
226
|
+
#
|
227
|
+
# * ::json_create: Returns a new Range object constructed from the given
|
228
|
+
# object.
|
229
|
+
# * #as_json: Returns a 2-element hash representing `self`.
|
230
|
+
# * #to_json: Returns a JSON string representing `self`.
|
231
|
+
#
|
232
|
+
# To make these methods available:
|
233
|
+
#
|
234
|
+
# require 'json/add/range'
|
235
|
+
#
|
236
|
+
class Range[out Elem] < Object
|
237
|
+
include Enumerable[Elem]
|
238
|
+
|
239
|
+
# <!--
|
240
|
+
# rdoc-file=range.c
|
241
|
+
# - %(n) {|element| ... } -> self
|
242
|
+
# - %(n) -> enumerator or arithmetic_sequence
|
243
|
+
# -->
|
244
|
+
# Same as #step (but doesn't provide default value for `n`). The method is
|
245
|
+
# convenient for experssive producing of Enumerator::ArithmeticSequence.
|
246
|
+
#
|
247
|
+
# array = [0, 1, 2, 3, 4, 5, 6]
|
248
|
+
#
|
249
|
+
# # slice each second element:
|
250
|
+
# seq = (0..) % 2 #=> ((0..).%(2))
|
251
|
+
# array[seq] #=> [0, 2, 4, 6]
|
252
|
+
# # or just
|
253
|
+
# array[(0..) % 2] #=> [0, 2, 4, 6]
|
254
|
+
#
|
255
|
+
# Note that due to operator precedence in Ruby, parentheses are mandatory around
|
256
|
+
# range in this case:
|
257
|
+
#
|
258
|
+
# (0..7) % 2 #=> ((0..7).%(2)) -- as expected
|
259
|
+
# 0..7 % 2 #=> 0..1 -- parsed as 0..(7 % 2)
|
260
|
+
#
|
261
|
+
def %: (Numeric | int n) -> Enumerator[Elem, self]
|
262
|
+
| (Numeric | int n) { (Elem element) -> void } -> self
|
263
|
+
|
264
|
+
# <!--
|
265
|
+
# rdoc-file=range.c
|
266
|
+
# - self == other -> true or false
|
267
|
+
# -->
|
268
|
+
# Returns `true` if and only if:
|
269
|
+
#
|
270
|
+
# * `other` is a range.
|
271
|
+
# * `other.begin == self.begin`.
|
272
|
+
# * `other.end == self.end`.
|
273
|
+
# * `other.exclude_end? == self.exclude_end?`.
|
274
|
+
#
|
275
|
+
# Otherwise returns `false`.
|
276
|
+
#
|
277
|
+
# r = (1..5)
|
278
|
+
# r == (1..5) # => true
|
279
|
+
# r = Range.new(1, 5)
|
280
|
+
# r == 'foo' # => false
|
281
|
+
# r == (2..5) # => false
|
282
|
+
# r == (1..4) # => false
|
283
|
+
# r == (1...5) # => false
|
284
|
+
# r == Range.new(1, 5, true) # => false
|
285
|
+
#
|
286
|
+
# Note that even with the same argument, the return values of #== and #eql? can
|
287
|
+
# differ:
|
288
|
+
#
|
289
|
+
# (1..2) == (1..2.0) # => true
|
290
|
+
# (1..2).eql? (1..2.0) # => false
|
291
|
+
#
|
292
|
+
# Related: Range#eql?.
|
293
|
+
#
|
294
|
+
def ==: (untyped obj) -> bool
|
295
|
+
|
296
|
+
# <!--
|
297
|
+
# rdoc-file=range.c
|
298
|
+
# - self === object -> true or false
|
299
|
+
# -->
|
300
|
+
# Returns `true` if `object` is between `self.begin` and `self.end`. `false`
|
301
|
+
# otherwise:
|
302
|
+
#
|
303
|
+
# (1..4) === 2 # => true
|
304
|
+
# (1..4) === 5 # => false
|
305
|
+
# (1..4) === 'a' # => false
|
306
|
+
# (1..4) === 4 # => true
|
307
|
+
# (1...4) === 4 # => false
|
308
|
+
# ('a'..'d') === 'c' # => true
|
309
|
+
# ('a'..'d') === 'e' # => false
|
310
|
+
#
|
311
|
+
# A case statement uses method `===`, and so:
|
312
|
+
#
|
313
|
+
# case 79
|
314
|
+
# when (1..50)
|
315
|
+
# "low"
|
316
|
+
# when (51..75)
|
317
|
+
# "medium"
|
318
|
+
# when (76..100)
|
319
|
+
# "high"
|
320
|
+
# end # => "high"
|
321
|
+
#
|
322
|
+
# case "2.6.5"
|
323
|
+
# when ..."2.4"
|
324
|
+
# "EOL"
|
325
|
+
# when "2.4"..."2.5"
|
326
|
+
# "maintenance"
|
327
|
+
# when "2.5"..."3.0"
|
328
|
+
# "stable"
|
329
|
+
# when "3.1"..
|
330
|
+
# "upcoming"
|
331
|
+
# end # => "stable"
|
332
|
+
#
|
333
|
+
def ===: (untyped obj) -> bool
|
334
|
+
|
335
|
+
# <!--
|
336
|
+
# rdoc-file=range.c
|
337
|
+
# - self.begin -> object
|
338
|
+
# -->
|
339
|
+
# Returns the object that defines the beginning of `self`.
|
340
|
+
#
|
341
|
+
# (1..4).begin # => 1
|
342
|
+
# (..2).begin # => nil
|
343
|
+
#
|
344
|
+
# Related: Range#first, Range#end.
|
345
|
+
#
|
346
|
+
def begin: () -> Elem
|
347
|
+
|
348
|
+
# <!--
|
349
|
+
# rdoc-file=range.c
|
350
|
+
# - bsearch {|obj| block } -> value
|
351
|
+
# -->
|
352
|
+
# Returns an element from `self` selected by a binary search.
|
353
|
+
#
|
354
|
+
# See [Binary Searching](rdoc-ref:bsearch.rdoc).
|
355
|
+
#
|
356
|
+
def bsearch: () -> ::Enumerator[Elem, Elem?]
|
357
|
+
| () { (Elem) -> (true | false) } -> Elem?
|
358
|
+
| () { (Elem) -> ::Integer } -> Elem?
|
359
|
+
|
360
|
+
# <!--
|
361
|
+
# rdoc-file=range.c
|
362
|
+
# - cover?(object) -> true or false
|
363
|
+
# - cover?(range) -> true or false
|
364
|
+
# -->
|
365
|
+
# Returns `true` if the given argument is within `self`, `false` otherwise.
|
366
|
+
#
|
367
|
+
# With non-range argument `object`, evaluates with `<=` and `<`.
|
368
|
+
#
|
369
|
+
# For range `self` with included end value (`#exclude_end? == false`), evaluates
|
370
|
+
# thus:
|
371
|
+
#
|
372
|
+
# self.begin <= object <= self.end
|
373
|
+
#
|
374
|
+
# Examples:
|
375
|
+
#
|
376
|
+
# r = (1..4)
|
377
|
+
# r.cover?(1) # => true
|
378
|
+
# r.cover?(4) # => true
|
379
|
+
# r.cover?(0) # => false
|
380
|
+
# r.cover?(5) # => false
|
381
|
+
# r.cover?('foo') # => false
|
382
|
+
#
|
383
|
+
# r = ('a'..'d')
|
384
|
+
# r.cover?('a') # => true
|
385
|
+
# r.cover?('d') # => true
|
386
|
+
# r.cover?(' ') # => false
|
387
|
+
# r.cover?('e') # => false
|
388
|
+
# r.cover?(0) # => false
|
389
|
+
#
|
390
|
+
# For range `r` with excluded end value (`#exclude_end? == true`), evaluates
|
391
|
+
# thus:
|
392
|
+
#
|
393
|
+
# r.begin <= object < r.end
|
394
|
+
#
|
395
|
+
# Examples:
|
396
|
+
#
|
397
|
+
# r = (1...4)
|
398
|
+
# r.cover?(1) # => true
|
399
|
+
# r.cover?(3) # => true
|
400
|
+
# r.cover?(0) # => false
|
401
|
+
# r.cover?(4) # => false
|
402
|
+
# r.cover?('foo') # => false
|
403
|
+
#
|
404
|
+
# r = ('a'...'d')
|
405
|
+
# r.cover?('a') # => true
|
406
|
+
# r.cover?('c') # => true
|
407
|
+
# r.cover?(' ') # => false
|
408
|
+
# r.cover?('d') # => false
|
409
|
+
# r.cover?(0) # => false
|
410
|
+
#
|
411
|
+
# With range argument `range`, compares the first and last elements of `self`
|
412
|
+
# and `range`:
|
413
|
+
#
|
414
|
+
# r = (1..4)
|
415
|
+
# r.cover?(1..4) # => true
|
416
|
+
# r.cover?(0..4) # => false
|
417
|
+
# r.cover?(1..5) # => false
|
418
|
+
# r.cover?('a'..'d') # => false
|
419
|
+
#
|
420
|
+
# r = (1...4)
|
421
|
+
# r.cover?(1..3) # => true
|
422
|
+
# r.cover?(1..4) # => false
|
423
|
+
#
|
424
|
+
# If begin and end are numeric, #cover? behaves like #include?
|
425
|
+
#
|
426
|
+
# (1..3).cover?(1.5) # => true
|
427
|
+
# (1..3).include?(1.5) # => true
|
428
|
+
#
|
429
|
+
# But when not numeric, the two methods may differ:
|
430
|
+
#
|
431
|
+
# ('a'..'d').cover?('cc') # => true
|
432
|
+
# ('a'..'d').include?('cc') # => false
|
433
|
+
#
|
434
|
+
# Returns `false` if either:
|
435
|
+
#
|
436
|
+
# * The begin value of `self` is larger than its end value.
|
437
|
+
# * An internal call to `#<=>` returns `nil`; that is, the operands are not
|
438
|
+
# comparable.
|
439
|
+
#
|
440
|
+
# Beginless ranges cover all values of the same type before the end, excluding
|
441
|
+
# the end for exclusive ranges. Beginless ranges cover ranges that end before
|
442
|
+
# the end of the beginless range, or at the end of the beginless range for
|
443
|
+
# inclusive ranges.
|
444
|
+
#
|
445
|
+
# (..2).cover?(1) # => true
|
446
|
+
# (..2).cover?(2) # => true
|
447
|
+
# (..2).cover?(3) # => false
|
448
|
+
# (...2).cover?(2) # => false
|
449
|
+
# (..2).cover?("2") # => false
|
450
|
+
# (..2).cover?(..2) # => true
|
451
|
+
# (..2).cover?(...2) # => true
|
452
|
+
# (..2).cover?(.."2") # => false
|
453
|
+
# (...2).cover?(..2) # => false
|
454
|
+
#
|
455
|
+
# Endless ranges cover all values of the same type after the beginning. Endless
|
456
|
+
# exclusive ranges do not cover endless inclusive ranges.
|
457
|
+
#
|
458
|
+
# (2..).cover?(1) # => false
|
459
|
+
# (2..).cover?(3) # => true
|
460
|
+
# (2...).cover?(3) # => true
|
461
|
+
# (2..).cover?(2) # => true
|
462
|
+
# (2..).cover?("2") # => false
|
463
|
+
# (2..).cover?(2..) # => true
|
464
|
+
# (2..).cover?(2...) # => true
|
465
|
+
# (2..).cover?("2"..) # => false
|
466
|
+
# (2...).cover?(2..) # => false
|
467
|
+
# (2...).cover?(3...) # => true
|
468
|
+
# (2...).cover?(3..) # => false
|
469
|
+
# (3..).cover?(2..) # => false
|
470
|
+
#
|
471
|
+
# Ranges that are both beginless and endless cover all values and ranges, and
|
472
|
+
# return true for all arguments, with the exception that beginless and endless
|
473
|
+
# exclusive ranges do not cover endless inclusive ranges.
|
474
|
+
#
|
475
|
+
# (nil...).cover?(Object.new) # => true
|
476
|
+
# (nil...).cover?(nil...) # => true
|
477
|
+
# (nil..).cover?(nil...) # => true
|
478
|
+
# (nil...).cover?(nil..) # => false
|
479
|
+
# (nil...).cover?(1..) # => false
|
480
|
+
#
|
481
|
+
# Related: Range#include?.
|
482
|
+
#
|
483
|
+
def cover?: (untyped obj) -> bool
|
484
|
+
|
485
|
+
# <!--
|
486
|
+
# rdoc-file=range.c
|
487
|
+
# - each {|element| ... } -> self
|
488
|
+
# - each -> an_enumerator
|
489
|
+
# -->
|
490
|
+
# With a block given, passes each element of `self` to the block:
|
491
|
+
#
|
492
|
+
# a = []
|
493
|
+
# (1..4).each {|element| a.push(element) } # => 1..4
|
494
|
+
# a # => [1, 2, 3, 4]
|
495
|
+
#
|
496
|
+
# Raises an exception unless `self.first.respond_to?(:succ)`.
|
497
|
+
#
|
498
|
+
# With no block given, returns an enumerator.
|
499
|
+
#
|
500
|
+
def each: () { (Elem arg0) -> untyped } -> self
|
501
|
+
| () -> ::Enumerator[Elem, self]
|
502
|
+
|
503
|
+
# <!--
|
504
|
+
# rdoc-file=range.c
|
505
|
+
# - self.end -> object
|
506
|
+
# -->
|
507
|
+
# Returns the object that defines the end of `self`.
|
508
|
+
#
|
509
|
+
# (1..4).end # => 4
|
510
|
+
# (1...4).end # => 4
|
511
|
+
# (1..).end # => nil
|
512
|
+
#
|
513
|
+
# Related: Range#begin, Range#last.
|
514
|
+
#
|
515
|
+
def end: () -> Elem
|
516
|
+
|
517
|
+
# <!--
|
518
|
+
# rdoc-file=range.c
|
519
|
+
# - exclude_end? -> true or false
|
520
|
+
# -->
|
521
|
+
# Returns `true` if `self` excludes its end value; `false` otherwise:
|
522
|
+
#
|
523
|
+
# Range.new(2, 5).exclude_end? # => false
|
524
|
+
# Range.new(2, 5, true).exclude_end? # => true
|
525
|
+
# (2..5).exclude_end? # => false
|
526
|
+
# (2...5).exclude_end? # => true
|
527
|
+
#
|
528
|
+
def exclude_end?: () -> bool
|
529
|
+
|
530
|
+
# <!--
|
531
|
+
# rdoc-file=range.c
|
532
|
+
# - first -> object
|
533
|
+
# - first(n) -> array
|
534
|
+
# -->
|
535
|
+
# With no argument, returns the first element of `self`, if it exists:
|
536
|
+
#
|
537
|
+
# (1..4).first # => 1
|
538
|
+
# ('a'..'d').first # => "a"
|
539
|
+
#
|
540
|
+
# With non-negative integer argument `n` given, returns the first `n` elements
|
541
|
+
# in an array:
|
542
|
+
#
|
543
|
+
# (1..10).first(3) # => [1, 2, 3]
|
544
|
+
# (1..10).first(0) # => []
|
545
|
+
# (1..4).first(50) # => [1, 2, 3, 4]
|
546
|
+
#
|
547
|
+
# Raises an exception if there is no first element:
|
548
|
+
#
|
549
|
+
# (..4).first # Raises RangeError
|
550
|
+
#
|
551
|
+
def first: () -> Elem
|
552
|
+
| (Integer n) -> ::Array[Elem]
|
553
|
+
|
554
|
+
# <!--
|
555
|
+
# rdoc-file=range.c
|
556
|
+
# - hash -> integer
|
557
|
+
# -->
|
558
|
+
# Returns the integer hash value for `self`. Two range objects `r0` and `r1`
|
559
|
+
# have the same hash value if and only if `r0.eql?(r1)`.
|
560
|
+
#
|
561
|
+
# Related: Range#eql?, Object#hash.
|
562
|
+
#
|
563
|
+
def hash: () -> Integer
|
564
|
+
|
565
|
+
# <!-- rdoc-file=range.c -->
|
566
|
+
# Returns `true` if `object` is an element of `self`, `false` otherwise:
|
567
|
+
#
|
568
|
+
# (1..4).include?(2) # => true
|
569
|
+
# (1..4).include?(5) # => false
|
570
|
+
# (1..4).include?(4) # => true
|
571
|
+
# (1...4).include?(4) # => false
|
572
|
+
# ('a'..'d').include?('b') # => true
|
573
|
+
# ('a'..'d').include?('e') # => false
|
574
|
+
# ('a'..'d').include?('B') # => false
|
575
|
+
# ('a'..'d').include?('d') # => true
|
576
|
+
# ('a'...'d').include?('d') # => false
|
577
|
+
#
|
578
|
+
# If begin and end are numeric, #include? behaves like #cover?
|
579
|
+
#
|
580
|
+
# (1..3).include?(1.5) # => true
|
581
|
+
# (1..3).cover?(1.5) # => true
|
582
|
+
#
|
583
|
+
# But when not numeric, the two methods may differ:
|
584
|
+
#
|
585
|
+
# ('a'..'d').include?('cc') # => false
|
586
|
+
# ('a'..'d').cover?('cc') # => true
|
587
|
+
#
|
588
|
+
# Related: Range#cover?.
|
589
|
+
#
|
590
|
+
def include?: (untyped obj) -> bool
|
591
|
+
|
592
|
+
# <!--
|
593
|
+
# rdoc-file=range.c
|
594
|
+
# - Range.new(begin, end, exclude_end = false) -> new_range
|
595
|
+
# -->
|
596
|
+
# Returns a new range based on the given objects `begin` and `end`. Optional
|
597
|
+
# argument `exclude_end` determines whether object `end` is included as the last
|
598
|
+
# object in the range:
|
599
|
+
#
|
600
|
+
# Range.new(2, 5).to_a # => [2, 3, 4, 5]
|
601
|
+
# Range.new(2, 5, true).to_a # => [2, 3, 4]
|
602
|
+
# Range.new('a', 'd').to_a # => ["a", "b", "c", "d"]
|
603
|
+
# Range.new('a', 'd', true).to_a # => ["a", "b", "c"]
|
604
|
+
#
|
605
|
+
def initialize: (Elem from, Elem to, ?boolish exclude_end) -> void
|
606
|
+
|
607
|
+
# <!--
|
608
|
+
# rdoc-file=range.c
|
609
|
+
# - inspect -> string
|
610
|
+
# -->
|
611
|
+
# Returns a string representation of `self`, including `begin.inspect` and
|
612
|
+
# `end.inspect`:
|
613
|
+
#
|
614
|
+
# (1..4).inspect # => "1..4"
|
615
|
+
# (1...4).inspect # => "1...4"
|
616
|
+
# (1..).inspect # => "1.."
|
617
|
+
# (..4).inspect # => "..4"
|
618
|
+
#
|
619
|
+
# Note that returns from #to_s and #inspect may differ:
|
620
|
+
#
|
621
|
+
# ('a'..'d').to_s # => "a..d"
|
622
|
+
# ('a'..'d').inspect # => "\"a\"..\"d\""
|
623
|
+
#
|
624
|
+
# Related: Range#to_s.
|
625
|
+
#
|
626
|
+
def inspect: () -> String
|
627
|
+
|
628
|
+
# <!--
|
629
|
+
# rdoc-file=range.c
|
630
|
+
# - last -> object
|
631
|
+
# - last(n) -> array
|
632
|
+
# -->
|
633
|
+
# With no argument, returns the last element of `self`, if it exists:
|
634
|
+
#
|
635
|
+
# (1..4).last # => 4
|
636
|
+
# ('a'..'d').last # => "d"
|
637
|
+
#
|
638
|
+
# Note that `last` with no argument returns the end element of `self` even if
|
639
|
+
# #exclude_end? is `true`:
|
640
|
+
#
|
641
|
+
# (1...4).last # => 4
|
642
|
+
# ('a'...'d').last # => "d"
|
643
|
+
#
|
644
|
+
# With non-negative integer argument `n` given, returns the last `n` elements in
|
645
|
+
# an array:
|
646
|
+
#
|
647
|
+
# (1..10).last(3) # => [8, 9, 10]
|
648
|
+
# (1..10).last(0) # => []
|
649
|
+
# (1..4).last(50) # => [1, 2, 3, 4]
|
650
|
+
#
|
651
|
+
# Note that `last` with argument does not return the end element of `self` if
|
652
|
+
# #exclude_end? it `true`:
|
653
|
+
#
|
654
|
+
# (1...4).last(3) # => [1, 2, 3]
|
655
|
+
# ('a'...'d').last(3) # => ["a", "b", "c"]
|
656
|
+
#
|
657
|
+
# Raises an exception if there is no last element:
|
658
|
+
#
|
659
|
+
# (1..).last # Raises RangeError
|
660
|
+
#
|
661
|
+
def last: () -> Elem
|
662
|
+
| (Integer n) -> ::Array[Elem]
|
663
|
+
|
664
|
+
# <!--
|
665
|
+
# rdoc-file=range.c
|
666
|
+
# - max -> object
|
667
|
+
# - max(n) -> array
|
668
|
+
# - max {|a, b| ... } -> object
|
669
|
+
# - max(n) {|a, b| ... } -> array
|
670
|
+
# -->
|
671
|
+
# Returns the maximum value in `self`, using method `#<=>` or a given block for
|
672
|
+
# comparison.
|
673
|
+
#
|
674
|
+
# With no argument and no block given, returns the maximum-valued element of
|
675
|
+
# `self`.
|
676
|
+
#
|
677
|
+
# (1..4).max # => 4
|
678
|
+
# ('a'..'d').max # => "d"
|
679
|
+
# (-4..-1).max # => -1
|
680
|
+
#
|
681
|
+
# With non-negative integer argument `n` given, and no block given, returns the
|
682
|
+
# `n` maximum-valued elements of `self` in an array:
|
683
|
+
#
|
684
|
+
# (1..4).max(2) # => [4, 3]
|
685
|
+
# ('a'..'d').max(2) # => ["d", "c"]
|
686
|
+
# (-4..-1).max(2) # => [-1, -2]
|
687
|
+
# (1..4).max(50) # => [4, 3, 2, 1]
|
688
|
+
#
|
689
|
+
# If a block is given, it is called:
|
690
|
+
#
|
691
|
+
# * First, with the first two element of `self`.
|
692
|
+
# * Then, sequentially, with the so-far maximum value and the next element of
|
693
|
+
# `self`.
|
694
|
+
#
|
695
|
+
# To illustrate:
|
696
|
+
#
|
697
|
+
# (1..4).max {|a, b| p [a, b]; a <=> b } # => 4
|
698
|
+
#
|
699
|
+
# Output:
|
700
|
+
#
|
701
|
+
# [2, 1]
|
702
|
+
# [3, 2]
|
703
|
+
# [4, 3]
|
704
|
+
#
|
705
|
+
# With no argument and a block given, returns the return value of the last call
|
706
|
+
# to the block:
|
707
|
+
#
|
708
|
+
# (1..4).max {|a, b| -(a <=> b) } # => 1
|
709
|
+
#
|
710
|
+
# With non-negative integer argument `n` given, and a block given, returns the
|
711
|
+
# return values of the last `n` calls to the block in an array:
|
712
|
+
#
|
713
|
+
# (1..4).max(2) {|a, b| -(a <=> b) } # => [1, 2]
|
714
|
+
# (1..4).max(50) {|a, b| -(a <=> b) } # => [1, 2, 3, 4]
|
715
|
+
#
|
716
|
+
# Returns an empty array if `n` is zero:
|
717
|
+
#
|
718
|
+
# (1..4).max(0) # => []
|
719
|
+
# (1..4).max(0) {|a, b| -(a <=> b) } # => []
|
720
|
+
#
|
721
|
+
# Returns `nil` or an empty array if:
|
722
|
+
#
|
723
|
+
# * The begin value of the range is larger than the end value:
|
724
|
+
#
|
725
|
+
# (4..1).max # => nil
|
726
|
+
# (4..1).max(2) # => []
|
727
|
+
# (4..1).max {|a, b| -(a <=> b) } # => nil
|
728
|
+
# (4..1).max(2) {|a, b| -(a <=> b) } # => []
|
729
|
+
#
|
730
|
+
# * The begin value of an exclusive range is equal to the end value:
|
731
|
+
#
|
732
|
+
# (1...1).max # => nil
|
733
|
+
# (1...1).max(2) # => []
|
734
|
+
# (1...1).max {|a, b| -(a <=> b) } # => nil
|
735
|
+
# (1...1).max(2) {|a, b| -(a <=> b) } # => []
|
736
|
+
#
|
737
|
+
# Raises an exception if either:
|
738
|
+
#
|
739
|
+
# * `self` is a endless range: `(1..)`.
|
740
|
+
# * A block is given and `self` is a beginless range.
|
741
|
+
#
|
742
|
+
# Related: Range#min, Range#minmax.
|
743
|
+
#
|
744
|
+
def max: () -> Elem
|
745
|
+
| () { (Elem a, Elem b) -> Integer } -> Elem
|
746
|
+
| (Integer n) -> ::Array[Elem]
|
747
|
+
| (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
|
748
|
+
|
749
|
+
# <!--
|
750
|
+
# rdoc-file=range.c
|
751
|
+
# - min -> object
|
752
|
+
# - min(n) -> array
|
753
|
+
# - min {|a, b| ... } -> object
|
754
|
+
# - min(n) {|a, b| ... } -> array
|
755
|
+
# -->
|
756
|
+
# Returns the minimum value in `self`, using method `#<=>` or a given block for
|
757
|
+
# comparison.
|
758
|
+
#
|
759
|
+
# With no argument and no block given, returns the minimum-valued element of
|
760
|
+
# `self`.
|
761
|
+
#
|
762
|
+
# (1..4).min # => 1
|
763
|
+
# ('a'..'d').min # => "a"
|
764
|
+
# (-4..-1).min # => -4
|
765
|
+
#
|
766
|
+
# With non-negative integer argument `n` given, and no block given, returns the
|
767
|
+
# `n` minimum-valued elements of `self` in an array:
|
768
|
+
#
|
769
|
+
# (1..4).min(2) # => [1, 2]
|
770
|
+
# ('a'..'d').min(2) # => ["a", "b"]
|
771
|
+
# (-4..-1).min(2) # => [-4, -3]
|
772
|
+
# (1..4).min(50) # => [1, 2, 3, 4]
|
773
|
+
#
|
774
|
+
# If a block is given, it is called:
|
775
|
+
#
|
776
|
+
# * First, with the first two element of `self`.
|
777
|
+
# * Then, sequentially, with the so-far minimum value and the next element of
|
778
|
+
# `self`.
|
779
|
+
#
|
780
|
+
# To illustrate:
|
781
|
+
#
|
782
|
+
# (1..4).min {|a, b| p [a, b]; a <=> b } # => 1
|
783
|
+
#
|
784
|
+
# Output:
|
785
|
+
#
|
786
|
+
# [2, 1]
|
787
|
+
# [3, 1]
|
788
|
+
# [4, 1]
|
789
|
+
#
|
790
|
+
# With no argument and a block given, returns the return value of the last call
|
791
|
+
# to the block:
|
792
|
+
#
|
793
|
+
# (1..4).min {|a, b| -(a <=> b) } # => 4
|
794
|
+
#
|
795
|
+
# With non-negative integer argument `n` given, and a block given, returns the
|
796
|
+
# return values of the last `n` calls to the block in an array:
|
797
|
+
#
|
798
|
+
# (1..4).min(2) {|a, b| -(a <=> b) } # => [4, 3]
|
799
|
+
# (1..4).min(50) {|a, b| -(a <=> b) } # => [4, 3, 2, 1]
|
800
|
+
#
|
801
|
+
# Returns an empty array if `n` is zero:
|
802
|
+
#
|
803
|
+
# (1..4).min(0) # => []
|
804
|
+
# (1..4).min(0) {|a, b| -(a <=> b) } # => []
|
805
|
+
#
|
806
|
+
# Returns `nil` or an empty array if:
|
807
|
+
#
|
808
|
+
# * The begin value of the range is larger than the end value:
|
809
|
+
#
|
810
|
+
# (4..1).min # => nil
|
811
|
+
# (4..1).min(2) # => []
|
812
|
+
# (4..1).min {|a, b| -(a <=> b) } # => nil
|
813
|
+
# (4..1).min(2) {|a, b| -(a <=> b) } # => []
|
814
|
+
#
|
815
|
+
# * The begin value of an exclusive range is equal to the end value:
|
816
|
+
#
|
817
|
+
# (1...1).min # => nil
|
818
|
+
# (1...1).min(2) # => []
|
819
|
+
# (1...1).min {|a, b| -(a <=> b) } # => nil
|
820
|
+
# (1...1).min(2) {|a, b| -(a <=> b) } # => []
|
821
|
+
#
|
822
|
+
# Raises an exception if either:
|
823
|
+
#
|
824
|
+
# * `self` is a beginless range: `(..4)`.
|
825
|
+
# * A block is given and `self` is an endless range.
|
826
|
+
#
|
827
|
+
# Related: Range#max, Range#minmax.
|
828
|
+
#
|
829
|
+
def min: () -> Elem
|
830
|
+
| () { (Elem a, Elem b) -> Integer } -> Elem
|
831
|
+
| (Integer n) -> ::Array[Elem]
|
832
|
+
| (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
|
833
|
+
|
834
|
+
# <!--
|
835
|
+
# rdoc-file=range.c
|
836
|
+
# - overlap?(range) -> true or false
|
837
|
+
# -->
|
838
|
+
# Returns `true` if `range` overlaps with `self`, `false` otherwise:
|
839
|
+
#
|
840
|
+
# (0..2).overlap?(1..3) #=> true
|
841
|
+
# (0..2).overlap?(3..4) #=> false
|
842
|
+
# (0..).overlap?(..0) #=> true
|
843
|
+
#
|
844
|
+
# With non-range argument, raises TypeError.
|
845
|
+
#
|
846
|
+
# (1..3).overlap?(1) # TypeError
|
847
|
+
#
|
848
|
+
# Returns `false` if an internal call to `#<=>` returns `nil`; that is, the
|
849
|
+
# operands are not comparable.
|
850
|
+
#
|
851
|
+
# (1..3).overlap?('a'..'d') # => false
|
852
|
+
#
|
853
|
+
# Returns `false` if `self` or `range` is empty. "Empty range" means that its
|
854
|
+
# begin value is larger than, or equal for an exclusive range, its end value.
|
855
|
+
#
|
856
|
+
# (4..1).overlap?(2..3) # => false
|
857
|
+
# (4..1).overlap?(..3) # => false
|
858
|
+
# (4..1).overlap?(2..) # => false
|
859
|
+
# (2...2).overlap?(1..2) # => false
|
860
|
+
#
|
861
|
+
# (1..4).overlap?(3..2) # => false
|
862
|
+
# (..4).overlap?(3..2) # => false
|
863
|
+
# (1..).overlap?(3..2) # => false
|
864
|
+
# (1..2).overlap?(2...2) # => false
|
865
|
+
#
|
866
|
+
# Returns `false` if the begin value one of `self` and `range` is larger than,
|
867
|
+
# or equal if the other is an exclusive range, the end value of the other:
|
868
|
+
#
|
869
|
+
# (4..5).overlap?(2..3) # => false
|
870
|
+
# (4..5).overlap?(2...4) # => false
|
871
|
+
#
|
872
|
+
# (1..2).overlap?(3..4) # => false
|
873
|
+
# (1...3).overlap?(3..4) # => false
|
874
|
+
#
|
875
|
+
# Returns `false` if the end value one of `self` and `range` is larger than, or
|
876
|
+
# equal for an exclusive range, the end value of the other:
|
877
|
+
#
|
878
|
+
# (4..5).overlap?(2..3) # => false
|
879
|
+
# (4..5).overlap?(2...4) # => false
|
880
|
+
#
|
881
|
+
# (1..2).overlap?(3..4) # => false
|
882
|
+
# (1...3).overlap?(3..4) # => false
|
883
|
+
#
|
884
|
+
# Note that the method wouldn't make any assumptions about the beginless range
|
885
|
+
# being actually empty, even if its upper bound is the minimum possible value of
|
886
|
+
# its type, so all this would return `true`:
|
887
|
+
#
|
888
|
+
# (...-Float::INFINITY).overlap?(...-Float::INFINITY) # => true
|
889
|
+
# (..."").overlap?(..."") # => true
|
890
|
+
# (...[]).overlap?(...[]) # => true
|
891
|
+
#
|
892
|
+
# Even if those ranges are effectively empty (no number can be smaller than
|
893
|
+
# `-Float::INFINITY`), they are still considered overlapping with themselves.
|
894
|
+
#
|
895
|
+
# Related: Range#cover?.
|
896
|
+
#
|
897
|
+
def overlap?: (Range[untyped]) -> bool
|
898
|
+
|
899
|
+
# <!--
|
900
|
+
# rdoc-file=range.c
|
901
|
+
# - reverse_each {|element| ... } -> self
|
902
|
+
# - reverse_each -> an_enumerator
|
903
|
+
# -->
|
904
|
+
# With a block given, passes each element of `self` to the block in reverse
|
905
|
+
# order:
|
906
|
+
#
|
907
|
+
# a = []
|
908
|
+
# (1..4).reverse_each {|element| a.push(element) } # => 1..4
|
909
|
+
# a # => [4, 3, 2, 1]
|
910
|
+
#
|
911
|
+
# a = []
|
912
|
+
# (1...4).reverse_each {|element| a.push(element) } # => 1...4
|
913
|
+
# a # => [3, 2, 1]
|
914
|
+
#
|
915
|
+
# With no block given, returns an enumerator.
|
916
|
+
#
|
917
|
+
def reverse_each: () { (Elem) -> void } -> self
|
918
|
+
| () -> ::Enumerator[Elem, self]
|
919
|
+
|
920
|
+
# <!--
|
921
|
+
# rdoc-file=range.c
|
922
|
+
# - size -> non_negative_integer or Infinity or nil
|
923
|
+
# -->
|
924
|
+
# Returns the count of elements in `self` if both begin and end values are
|
925
|
+
# numeric; otherwise, returns `nil`:
|
926
|
+
#
|
927
|
+
# (1..4).size # => 4
|
928
|
+
# (1...4).size # => 3
|
929
|
+
# (1..).size # => Infinity
|
930
|
+
# ('a'..'z').size # => nil
|
931
|
+
#
|
932
|
+
# If `self` is not iterable, raises an exception:
|
933
|
+
#
|
934
|
+
# (0.5..2.5).size # TypeError
|
935
|
+
# (..1).size # TypeError
|
936
|
+
#
|
937
|
+
# Related: Range#count.
|
938
|
+
#
|
939
|
+
def size: () -> Integer?
|
940
|
+
| () -> Float?
|
941
|
+
|
942
|
+
# <!--
|
943
|
+
# rdoc-file=range.c
|
944
|
+
# - step(s = 1) {|element| ... } -> self
|
945
|
+
# - step(s = 1) -> enumerator/arithmetic_sequence
|
946
|
+
# -->
|
947
|
+
# Iterates over the elements of range in steps of `s`. The iteration is
|
948
|
+
# performed by `+` operator:
|
949
|
+
#
|
950
|
+
# (0..6).step(2) { puts _1 } #=> 1..5
|
951
|
+
# # Prints: 0, 2, 4, 6
|
952
|
+
#
|
953
|
+
# # Iterate between two dates in step of 1 day (24 hours)
|
954
|
+
# (Time.utc(2022, 2, 24)..Time.utc(2022, 3, 1)).step(24*60*60) { puts _1 }
|
955
|
+
# # Prints:
|
956
|
+
# # 2022-02-24 00:00:00 UTC
|
957
|
+
# # 2022-02-25 00:00:00 UTC
|
958
|
+
# # 2022-02-26 00:00:00 UTC
|
959
|
+
# # 2022-02-27 00:00:00 UTC
|
960
|
+
# # 2022-02-28 00:00:00 UTC
|
961
|
+
# # 2022-03-01 00:00:00 UTC
|
962
|
+
#
|
963
|
+
# If ` + step` decreases the value, iteration is still performed when step
|
964
|
+
# `begin` is higher than the `end`:
|
965
|
+
#
|
966
|
+
# (0..6).step(-2) { puts _1 }
|
967
|
+
# # Prints nothing
|
968
|
+
#
|
969
|
+
# (6..0).step(-2) { puts _1 }
|
970
|
+
# # Prints: 6, 4, 2, 0
|
971
|
+
#
|
972
|
+
# (Time.utc(2022, 3, 1)..Time.utc(2022, 2, 24)).step(-24*60*60) { puts _1 }
|
973
|
+
# # Prints:
|
974
|
+
# # 2022-03-01 00:00:00 UTC
|
975
|
+
# # 2022-02-28 00:00:00 UTC
|
976
|
+
# # 2022-02-27 00:00:00 UTC
|
977
|
+
# # 2022-02-26 00:00:00 UTC
|
978
|
+
# # 2022-02-25 00:00:00 UTC
|
979
|
+
# # 2022-02-24 00:00:00 UTC
|
980
|
+
#
|
981
|
+
# When the block is not provided, and range boundaries and step are Numeric, the
|
982
|
+
# method returns Enumerator::ArithmeticSequence.
|
983
|
+
#
|
984
|
+
# (1..5).step(2) # => ((1..5).step(2))
|
985
|
+
# (1.0..).step(1.5) #=> ((1.0..).step(1.5))
|
986
|
+
# (..3r).step(1/3r) #=> ((..3/1).step((1/3)))
|
987
|
+
#
|
988
|
+
# Enumerator::ArithmeticSequence can be further used as a value object for
|
989
|
+
# iteration or slicing of collections (see Array#[]). There is a convenience
|
990
|
+
# method #% with behavior similar to `step` to produce arithmetic sequences more
|
991
|
+
# expressively:
|
992
|
+
#
|
993
|
+
# # Same as (1..5).step(2)
|
994
|
+
# (1..5) % 2 # => ((1..5).%(2))
|
995
|
+
#
|
996
|
+
# In a generic case, when the block is not provided, Enumerator is returned:
|
997
|
+
#
|
998
|
+
# ('a'..).step('b') #=> #<Enumerator: "a"..:step("b")>
|
999
|
+
# ('a'..).step('b').take(3) #=> ["a", "ab", "abb"]
|
1000
|
+
#
|
1001
|
+
# If `s` is not provided, it is considered `1` for ranges with numeric `begin`:
|
1002
|
+
#
|
1003
|
+
# (1..5).step { p _1 }
|
1004
|
+
# # Prints: 1, 2, 3, 4, 5
|
1005
|
+
#
|
1006
|
+
# For non-Numeric ranges, step absence is an error:
|
1007
|
+
#
|
1008
|
+
# (Time.utc(2022, 3, 1)..Time.utc(2022, 2, 24)).step { p _1 }
|
1009
|
+
# # raises: step is required for non-numeric ranges (ArgumentError)
|
1010
|
+
#
|
1011
|
+
# For backward compatibility reasons, String ranges support the iteration both
|
1012
|
+
# with string step and with integer step. In the latter case, the iteration is
|
1013
|
+
# performed by calculating the next values with String#succ:
|
1014
|
+
#
|
1015
|
+
# ('a'..'e').step(2) { p _1 }
|
1016
|
+
# # Prints: a, c, e
|
1017
|
+
# ('a'..'e').step { p _1 }
|
1018
|
+
# # Default step 1; prints: a, b, c, d, e
|
1019
|
+
#
|
1020
|
+
def step: (?Numeric | int) -> Enumerator[Elem, self]
|
1021
|
+
| (?Numeric | int) { (Elem element) -> void } -> self
|
1022
|
+
| (untyped) -> Enumerator[Elem, self]
|
1023
|
+
| (untyped) { (Elem element) -> void } -> self
|
1024
|
+
|
1025
|
+
# <!--
|
1026
|
+
# rdoc-file=range.c
|
1027
|
+
# - to_s -> string
|
1028
|
+
# -->
|
1029
|
+
# Returns a string representation of `self`, including `begin.to_s` and
|
1030
|
+
# `end.to_s`:
|
1031
|
+
#
|
1032
|
+
# (1..4).to_s # => "1..4"
|
1033
|
+
# (1...4).to_s # => "1...4"
|
1034
|
+
# (1..).to_s # => "1.."
|
1035
|
+
# (..4).to_s # => "..4"
|
1036
|
+
#
|
1037
|
+
# Note that returns from #to_s and #inspect may differ:
|
1038
|
+
#
|
1039
|
+
# ('a'..'d').to_s # => "a..d"
|
1040
|
+
# ('a'..'d').inspect # => "\"a\"..\"d\""
|
1041
|
+
#
|
1042
|
+
# Related: Range#inspect.
|
1043
|
+
#
|
1044
|
+
def to_s: () -> String
|
1045
|
+
|
1046
|
+
# <!--
|
1047
|
+
# rdoc-file=range.c
|
1048
|
+
# - eql?(other) -> true or false
|
1049
|
+
# -->
|
1050
|
+
# Returns `true` if and only if:
|
1051
|
+
#
|
1052
|
+
# * `other` is a range.
|
1053
|
+
# * `other.begin.eql?(self.begin)`.
|
1054
|
+
# * `other.end.eql?(self.end)`.
|
1055
|
+
# * `other.exclude_end? == self.exclude_end?`.
|
1056
|
+
#
|
1057
|
+
# Otherwise returns `false`.
|
1058
|
+
#
|
1059
|
+
# r = (1..5)
|
1060
|
+
# r.eql?(1..5) # => true
|
1061
|
+
# r = Range.new(1, 5)
|
1062
|
+
# r.eql?('foo') # => false
|
1063
|
+
# r.eql?(2..5) # => false
|
1064
|
+
# r.eql?(1..4) # => false
|
1065
|
+
# r.eql?(1...5) # => false
|
1066
|
+
# r.eql?(Range.new(1, 5, true)) # => false
|
1067
|
+
#
|
1068
|
+
# Note that even with the same argument, the return values of #== and #eql? can
|
1069
|
+
# differ:
|
1070
|
+
#
|
1071
|
+
# (1..2) == (1..2.0) # => true
|
1072
|
+
# (1..2).eql? (1..2.0) # => false
|
1073
|
+
#
|
1074
|
+
# Related: Range#==.
|
1075
|
+
#
|
1076
|
+
def eql?: (untyped obj) -> bool
|
1077
|
+
|
1078
|
+
# <!--
|
1079
|
+
# rdoc-file=range.c
|
1080
|
+
# - include?(object) -> true or false
|
1081
|
+
# -->
|
1082
|
+
# Returns `true` if `object` is an element of `self`, `false` otherwise:
|
1083
|
+
#
|
1084
|
+
# (1..4).include?(2) # => true
|
1085
|
+
# (1..4).include?(5) # => false
|
1086
|
+
# (1..4).include?(4) # => true
|
1087
|
+
# (1...4).include?(4) # => false
|
1088
|
+
# ('a'..'d').include?('b') # => true
|
1089
|
+
# ('a'..'d').include?('e') # => false
|
1090
|
+
# ('a'..'d').include?('B') # => false
|
1091
|
+
# ('a'..'d').include?('d') # => true
|
1092
|
+
# ('a'...'d').include?('d') # => false
|
1093
|
+
#
|
1094
|
+
# If begin and end are numeric, #include? behaves like #cover?
|
1095
|
+
#
|
1096
|
+
# (1..3).include?(1.5) # => true
|
1097
|
+
# (1..3).cover?(1.5) # => true
|
1098
|
+
#
|
1099
|
+
# But when not numeric, the two methods may differ:
|
1100
|
+
#
|
1101
|
+
# ('a'..'d').include?('cc') # => false
|
1102
|
+
# ('a'..'d').cover?('cc') # => true
|
1103
|
+
#
|
1104
|
+
# Related: Range#cover?.
|
1105
|
+
#
|
1106
|
+
def member?: (untyped obj) -> bool
|
1107
|
+
end
|