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/string.rbs
ADDED
@@ -0,0 +1,3583 @@
|
|
1
|
+
# <!-- rdoc-file=string.rb -->
|
2
|
+
# A `String` object has an arbitrary sequence of bytes, typically representing
|
3
|
+
# text or binary data. A `String` object may be created using String::new or as
|
4
|
+
# literals.
|
5
|
+
#
|
6
|
+
# String objects differ from Symbol objects in that Symbol objects are designed
|
7
|
+
# to be used as identifiers, instead of text or data.
|
8
|
+
#
|
9
|
+
# You can create a `String` object explicitly with:
|
10
|
+
#
|
11
|
+
# * A [string literal](rdoc-ref:syntax/literals.rdoc@String+Literals).
|
12
|
+
# * A [heredoc literal](rdoc-ref:syntax/literals.rdoc@Here+Document+Literals).
|
13
|
+
#
|
14
|
+
# You can convert certain objects to Strings with:
|
15
|
+
#
|
16
|
+
# * Method #String.
|
17
|
+
#
|
18
|
+
# Some `String` methods modify `self`. Typically, a method whose name ends with
|
19
|
+
# `!` modifies `self` and returns `self`; often, a similarly named method
|
20
|
+
# (without the `!`) returns a new string.
|
21
|
+
#
|
22
|
+
# In general, if both bang and non-bang versions of a method exist, the bang
|
23
|
+
# method mutates and the non-bang method does not. However, a method without a
|
24
|
+
# bang can also mutate, such as String#replace.
|
25
|
+
#
|
26
|
+
# ## Substitution Methods
|
27
|
+
#
|
28
|
+
# These methods perform substitutions:
|
29
|
+
#
|
30
|
+
# * String#sub: One substitution (or none); returns a new string.
|
31
|
+
# * String#sub!: One substitution (or none); returns `self` if any changes,
|
32
|
+
# `nil` otherwise.
|
33
|
+
# * String#gsub: Zero or more substitutions; returns a new string.
|
34
|
+
# * String#gsub!: Zero or more substitutions; returns `self` if any changes,
|
35
|
+
# `nil` otherwise.
|
36
|
+
#
|
37
|
+
# Each of these methods takes:
|
38
|
+
#
|
39
|
+
# * A first argument, `pattern` (String or Regexp), that specifies the
|
40
|
+
# substring(s) to be replaced.
|
41
|
+
#
|
42
|
+
# * Either of the following:
|
43
|
+
#
|
44
|
+
# * A second argument, `replacement` (String or Hash), that determines the
|
45
|
+
# replacing string.
|
46
|
+
# * A block that will determine the replacing string.
|
47
|
+
#
|
48
|
+
# The examples in this section mostly use the String#sub and String#gsub
|
49
|
+
# methods; the principles illustrated apply to all four substitution methods.
|
50
|
+
#
|
51
|
+
# **Argument `pattern`**
|
52
|
+
#
|
53
|
+
# Argument `pattern` is commonly a regular expression:
|
54
|
+
#
|
55
|
+
# s = 'hello'
|
56
|
+
# s.sub(/[aeiou]/, '*') # => "h*llo"
|
57
|
+
# s.gsub(/[aeiou]/, '*') # => "h*ll*"
|
58
|
+
# s.gsub(/[aeiou]/, '') # => "hll"
|
59
|
+
# s.sub(/ell/, 'al') # => "halo"
|
60
|
+
# s.gsub(/xyzzy/, '*') # => "hello"
|
61
|
+
# 'THX1138'.gsub(/\d+/, '00') # => "THX00"
|
62
|
+
#
|
63
|
+
# When `pattern` is a string, all its characters are treated as ordinary
|
64
|
+
# characters (not as Regexp special characters):
|
65
|
+
#
|
66
|
+
# 'THX1138'.gsub('\d+', '00') # => "THX1138"
|
67
|
+
#
|
68
|
+
# **`String` `replacement`**
|
69
|
+
#
|
70
|
+
# If `replacement` is a string, that string determines the replacing string that
|
71
|
+
# is substituted for the matched text.
|
72
|
+
#
|
73
|
+
# Each of the examples above uses a simple string as the replacing string.
|
74
|
+
#
|
75
|
+
# `String` `replacement` may contain back-references to the pattern's captures:
|
76
|
+
#
|
77
|
+
# * `\n` (*n* is a non-negative integer) refers to `$n`.
|
78
|
+
# * `\k<name>` refers to the named capture `name`.
|
79
|
+
#
|
80
|
+
# See Regexp for details.
|
81
|
+
#
|
82
|
+
# Note that within the string `replacement`, a character combination such as
|
83
|
+
# `$&` is treated as ordinary text, not as a special match variable. However,
|
84
|
+
# you may refer to some special match variables using these combinations:
|
85
|
+
#
|
86
|
+
# * `\&` and `\0` correspond to `$&`, which contains the complete matched
|
87
|
+
# text.
|
88
|
+
# * `\'` corresponds to `$'`, which contains the string after the match.
|
89
|
+
# * `\`` corresponds to `$``, which contains the string before the match.
|
90
|
+
# * `\+` corresponds to `$+`, which contains the last capture group.
|
91
|
+
#
|
92
|
+
# See Regexp for details.
|
93
|
+
#
|
94
|
+
# Note that `\\\` is interpreted as an escape, i.e., a single backslash.
|
95
|
+
#
|
96
|
+
# Note also that a string literal consumes backslashes. See [String
|
97
|
+
# Literals](rdoc-ref:syntax/literals.rdoc@String+Literals) for details about
|
98
|
+
# string literals.
|
99
|
+
#
|
100
|
+
# A back-reference is typically preceded by an additional backslash. For
|
101
|
+
# example, if you want to write a back-reference `\&` in `replacement` with a
|
102
|
+
# double-quoted string literal, you need to write `"..\\\\&.."`.
|
103
|
+
#
|
104
|
+
# If you want to write a non-back-reference string `\&` in `replacement`, you
|
105
|
+
# need to first escape the backslash to prevent this method from interpreting it
|
106
|
+
# as a back-reference, and then you need to escape the backslashes again to
|
107
|
+
# prevent a string literal from consuming them: `"..\\\\\\\\&.."`.
|
108
|
+
#
|
109
|
+
# You may want to use the block form to avoid excessive backslashes.
|
110
|
+
#
|
111
|
+
# **\Hash `replacement`**
|
112
|
+
#
|
113
|
+
# If the argument `replacement` is a hash, and `pattern` matches one of its
|
114
|
+
# keys, the replacing string is the value for that key:
|
115
|
+
#
|
116
|
+
# h = {'foo' => 'bar', 'baz' => 'bat'}
|
117
|
+
# 'food'.sub('foo', h) # => "bard"
|
118
|
+
#
|
119
|
+
# Note that a symbol key does not match:
|
120
|
+
#
|
121
|
+
# h = {foo: 'bar', baz: 'bat'}
|
122
|
+
# 'food'.sub('foo', h) # => "d"
|
123
|
+
#
|
124
|
+
# **Block**
|
125
|
+
#
|
126
|
+
# In the block form, the current match string is passed to the block; the
|
127
|
+
# block's return value becomes the replacing string:
|
128
|
+
#
|
129
|
+
# s = '@'
|
130
|
+
# '1234'.gsub(/\d/) { |match| s.succ! } # => "ABCD"
|
131
|
+
#
|
132
|
+
# Special match variables such as `$1`, `$2`, `$``, `$&`, and `$'` are set
|
133
|
+
# appropriately.
|
134
|
+
#
|
135
|
+
# ## Whitespace in Strings
|
136
|
+
#
|
137
|
+
# In the class `String`, *whitespace* is defined as a contiguous sequence of
|
138
|
+
# characters consisting of any mixture of the following:
|
139
|
+
#
|
140
|
+
# * NL (null): `"\x00"`, `"\u0000"`.
|
141
|
+
# * HT (horizontal tab): `"\x09"`, `"\t"`.
|
142
|
+
# * LF (line feed): `"\x0a"`, `"\n"`.
|
143
|
+
# * VT (vertical tab): `"\x0b"`, `"\v"`.
|
144
|
+
# * FF (form feed): `"\x0c"`, `"\f"`.
|
145
|
+
# * CR (carriage return): `"\x0d"`, `"\r"`.
|
146
|
+
# * SP (space): `"\x20"`, `" "`.
|
147
|
+
#
|
148
|
+
# Whitespace is relevant for the following methods:
|
149
|
+
#
|
150
|
+
# * #lstrip, #lstrip!: Strip leading whitespace.
|
151
|
+
# * #rstrip, #rstrip!: Strip trailing whitespace.
|
152
|
+
# * #strip, #strip!: Strip leading and trailing whitespace.
|
153
|
+
#
|
154
|
+
# ## `String` Slices
|
155
|
+
#
|
156
|
+
# A *slice* of a string is a substring selected by certain criteria.
|
157
|
+
#
|
158
|
+
# These instance methods utilize slicing:
|
159
|
+
#
|
160
|
+
# * String#[] (aliased as String#slice): Returns a slice copied from `self`.
|
161
|
+
# * String#[]=: Mutates `self` with the slice replaced.
|
162
|
+
# * String#slice!: Mutates `self` with the slice removed and returns the
|
163
|
+
# removed slice.
|
164
|
+
#
|
165
|
+
# Each of the above methods takes arguments that determine the slice to be
|
166
|
+
# copied or replaced.
|
167
|
+
#
|
168
|
+
# The arguments have several forms. For a string `string`, the forms are:
|
169
|
+
#
|
170
|
+
# * `string[index]`
|
171
|
+
# * `string[start, length]`
|
172
|
+
# * `string[range]`
|
173
|
+
# * `string[regexp, capture = 0]`
|
174
|
+
# * `string[substring]`
|
175
|
+
#
|
176
|
+
# **`string[index]`**
|
177
|
+
#
|
178
|
+
# When a non-negative integer argument `index` is given, the slice is the
|
179
|
+
# 1-character substring found in `self` at character offset `index`:
|
180
|
+
#
|
181
|
+
# 'bar'[0] # => "b"
|
182
|
+
# 'bar'[2] # => "r"
|
183
|
+
# 'bar'[20] # => nil
|
184
|
+
# 'тест'[2] # => "с"
|
185
|
+
# 'こんにちは'[4] # => "は"
|
186
|
+
#
|
187
|
+
# When a negative integer `index` is given, the slice begins at the offset given
|
188
|
+
# by counting backward from the end of `self`:
|
189
|
+
#
|
190
|
+
# 'bar'[-3] # => "b"
|
191
|
+
# 'bar'[-1] # => "r"
|
192
|
+
# 'bar'[-20] # => nil
|
193
|
+
#
|
194
|
+
# **`string[start, length]`**
|
195
|
+
#
|
196
|
+
# When non-negative integer arguments `start` and `length` are given, the slice
|
197
|
+
# begins at character offset `start`, if it exists, and continues for `length`
|
198
|
+
# characters, if available:
|
199
|
+
#
|
200
|
+
# 'foo'[0, 2] # => "fo"
|
201
|
+
# 'тест'[1, 2] # => "ес"
|
202
|
+
# 'こんにちは'[2, 2] # => "にち"
|
203
|
+
# # Zero length.
|
204
|
+
# 'foo'[2, 0] # => ""
|
205
|
+
# # Length not entirely available.
|
206
|
+
# 'foo'[1, 200] # => "oo"
|
207
|
+
# # Start out of range.
|
208
|
+
# 'foo'[4, 2] # => nil
|
209
|
+
#
|
210
|
+
# Special case: if `start` equals the length of `self`, the slice is a new empty
|
211
|
+
# string:
|
212
|
+
#
|
213
|
+
# 'foo'[3, 2] # => ""
|
214
|
+
# 'foo'[3, 200] # => ""
|
215
|
+
#
|
216
|
+
# When a negative `start` and non-negative `length` are given, the slice begins
|
217
|
+
# by counting backward from the end of `self`, and continues for `length`
|
218
|
+
# characters, if available:
|
219
|
+
#
|
220
|
+
# 'foo'[-2, 2] # => "oo"
|
221
|
+
# 'foo'[-2, 200] # => "oo"
|
222
|
+
# # Start out of range.
|
223
|
+
# 'foo'[-4, 2] # => nil
|
224
|
+
#
|
225
|
+
# When a negative `length` is given, there is no slice:
|
226
|
+
#
|
227
|
+
# 'foo'[1, -1] # => nil
|
228
|
+
# 'foo'[-2, -1] # => nil
|
229
|
+
#
|
230
|
+
# **`string[range]`**
|
231
|
+
#
|
232
|
+
# When a Range argument `range` is given, it creates a substring of `string`
|
233
|
+
# using the indices in `range`. The slice is then determined as above:
|
234
|
+
#
|
235
|
+
# 'foo'[0..1] # => "fo"
|
236
|
+
# 'foo'[0, 2] # => "fo"
|
237
|
+
#
|
238
|
+
# 'foo'[2...2] # => ""
|
239
|
+
# 'foo'[2, 0] # => ""
|
240
|
+
#
|
241
|
+
# 'foo'[1..200] # => "oo"
|
242
|
+
# 'foo'[1, 200] # => "oo"
|
243
|
+
#
|
244
|
+
# 'foo'[4..5] # => nil
|
245
|
+
# 'foo'[4, 2] # => nil
|
246
|
+
#
|
247
|
+
# 'foo'[-4..-3] # => nil
|
248
|
+
# 'foo'[-4, 2] # => nil
|
249
|
+
#
|
250
|
+
# 'foo'[3..4] # => ""
|
251
|
+
# 'foo'[3, 2] # => ""
|
252
|
+
#
|
253
|
+
# 'foo'[-2..-1] # => "oo"
|
254
|
+
# 'foo'[-2, 2] # => "oo"
|
255
|
+
#
|
256
|
+
# 'foo'[-2..197] # => "oo"
|
257
|
+
# 'foo'[-2, 200] # => "oo"
|
258
|
+
#
|
259
|
+
# **`string[regexp, capture = 0]`**
|
260
|
+
#
|
261
|
+
# When the Regexp argument `regexp` is given, and the `capture` argument is `0`,
|
262
|
+
# the slice is the first matching substring found in `self`:
|
263
|
+
#
|
264
|
+
# 'foo'[/o/] # => "o"
|
265
|
+
# 'foo'[/x/] # => nil
|
266
|
+
# s = 'hello there'
|
267
|
+
# s[/[aeiou](.)\1/] # => "ell"
|
268
|
+
# s[/[aeiou](.)\1/, 0] # => "ell"
|
269
|
+
#
|
270
|
+
# If the argument `capture` is provided and not `0`, it should be either a
|
271
|
+
# capture group index (integer) or a capture group name (String or Symbol); the
|
272
|
+
# slice is the specified capture (see Regexp@Groups and Captures):
|
273
|
+
#
|
274
|
+
# s = 'hello there'
|
275
|
+
# s[/[aeiou](.)\1/, 1] # => "l"
|
276
|
+
# s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "non_vowel"] # => "l"
|
277
|
+
# s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, :vowel] # => "e"
|
278
|
+
#
|
279
|
+
# If an invalid capture group index is given, there is no slice. If an invalid
|
280
|
+
# capture group name is given, `IndexError` is raised.
|
281
|
+
#
|
282
|
+
# **`string[substring]`**
|
283
|
+
#
|
284
|
+
# When the single `String` argument `substring` is given, it returns the
|
285
|
+
# substring from `self` if found, otherwise `nil`:
|
286
|
+
#
|
287
|
+
# 'foo'['oo'] # => "oo"
|
288
|
+
# 'foo'['xx'] # => nil
|
289
|
+
#
|
290
|
+
# ## What's Here
|
291
|
+
#
|
292
|
+
# First, what's elsewhere. Class `String`:
|
293
|
+
#
|
294
|
+
# * Inherits from the [Object class](rdoc-ref:Object@What-27s+Here).
|
295
|
+
# * Includes the [Comparable module](rdoc-ref:Comparable@What-27s+Here).
|
296
|
+
#
|
297
|
+
# Here, class `String` provides methods that are useful for:
|
298
|
+
#
|
299
|
+
# * [Creating a String](rdoc-ref:String@Methods+for+Creating+a+String)
|
300
|
+
# * [Frozen/Unfrozen
|
301
|
+
# Strings](rdoc-ref:String@Methods+for+a+Frozen-2FUnfrozen+String)
|
302
|
+
# * [Querying](rdoc-ref:String@Methods+for+Querying)
|
303
|
+
# * [Comparing](rdoc-ref:String@Methods+for+Comparing)
|
304
|
+
# * [Modifying a String](rdoc-ref:String@Methods+for+Modifying+a+String)
|
305
|
+
# * [Converting to New
|
306
|
+
# String](rdoc-ref:String@Methods+for+Converting+to+New+String)
|
307
|
+
# * [Converting to
|
308
|
+
# Non-String](rdoc-ref:String@Methods+for+Converting+to+Non-String)
|
309
|
+
# * [Iterating](rdoc-ref:String@Methods+for+Iterating)
|
310
|
+
#
|
311
|
+
# ### Methods for Creating a `String`
|
312
|
+
#
|
313
|
+
# * ::new: Returns a new string.
|
314
|
+
# * ::try_convert: Returns a new string created from a given object.
|
315
|
+
#
|
316
|
+
# ### Methods for a Frozen/Unfrozen String
|
317
|
+
#
|
318
|
+
# * #+@: Returns a string that is not frozen: `self` if not frozen; `self.dup`
|
319
|
+
# otherwise.
|
320
|
+
# * #-@ (aliased as #dedup): Returns a string that is frozen: `self` if
|
321
|
+
# already frozen; `self.freeze` otherwise.
|
322
|
+
# * #freeze: Freezes `self` if not already frozen; returns `self`.
|
323
|
+
#
|
324
|
+
# ### Methods for Querying
|
325
|
+
#
|
326
|
+
# *Counts*
|
327
|
+
#
|
328
|
+
# * #length (aliased as #size): Returns the count of characters (not bytes).
|
329
|
+
# * #empty?: Returns `true` if `self.length` is zero; `false` otherwise.
|
330
|
+
# * #bytesize: Returns the count of bytes.
|
331
|
+
# * #count: Returns the count of substrings matching given strings.
|
332
|
+
#
|
333
|
+
# *Substrings*
|
334
|
+
#
|
335
|
+
# * #=~: Returns the index of the first substring that matches a given Regexp
|
336
|
+
# or other object; returns `nil` if no match is found.
|
337
|
+
# * #index: Returns the index of the *first* occurrence of a given substring;
|
338
|
+
# returns `nil` if none found.
|
339
|
+
# * #rindex: Returns the index of the *last* occurrence of a given substring;
|
340
|
+
# returns `nil` if none found.
|
341
|
+
# * #include?: Returns `true` if the string contains a given substring;
|
342
|
+
# `false` otherwise.
|
343
|
+
# * #match: Returns a MatchData object if the string matches a given Regexp;
|
344
|
+
# `nil` otherwise.
|
345
|
+
# * #match?: Returns `true` if the string matches a given Regexp; `false`
|
346
|
+
# otherwise.
|
347
|
+
# * #start_with?: Returns `true` if the string begins with any of the given
|
348
|
+
# substrings.
|
349
|
+
# * #end_with?: Returns `true` if the string ends with any of the given
|
350
|
+
# substrings.
|
351
|
+
#
|
352
|
+
# *Encodings*
|
353
|
+
#
|
354
|
+
# * #encoding: Returns the Encoding object that represents the encoding of the
|
355
|
+
# string.
|
356
|
+
# * #unicode_normalized?: Returns `true` if the string is in Unicode
|
357
|
+
# normalized form; `false` otherwise.
|
358
|
+
# * #valid_encoding?: Returns `true` if the string contains only characters
|
359
|
+
# that are valid for its encoding.
|
360
|
+
# * #ascii_only?: Returns `true` if the string has only ASCII characters;
|
361
|
+
# `false` otherwise.
|
362
|
+
#
|
363
|
+
# *Other*
|
364
|
+
#
|
365
|
+
# * #sum: Returns a basic checksum for the string: the sum of each byte.
|
366
|
+
# * #hash: Returns the integer hash code.
|
367
|
+
#
|
368
|
+
# ### Methods for Comparing
|
369
|
+
#
|
370
|
+
# * #== (aliased as #===): Returns `true` if a given other string has the same
|
371
|
+
# content as `self`.
|
372
|
+
# * #eql?: Returns `true` if the content is the same as the given other
|
373
|
+
# string.
|
374
|
+
# * #<=>: Returns -1, 0, or 1 as a given other string is smaller than, equal
|
375
|
+
# to, or larger than `self`.
|
376
|
+
# * #casecmp: Ignoring case, returns -1, 0, or 1 as a given other string is
|
377
|
+
# smaller than, equal to, or larger than `self`.
|
378
|
+
# * #casecmp?: Returns `true` if the string is equal to a given string after
|
379
|
+
# Unicode case folding; `false` otherwise.
|
380
|
+
#
|
381
|
+
# ### Methods for Modifying a `String`
|
382
|
+
#
|
383
|
+
# Each of these methods modifies `self`.
|
384
|
+
#
|
385
|
+
# *Insertion*
|
386
|
+
#
|
387
|
+
# * #insert: Returns `self` with a given string inserted at a specified
|
388
|
+
# offset.
|
389
|
+
# * #<<: Returns `self` concatenated with a given string or integer.
|
390
|
+
# * #append_as_bytes: Returns `self` concatenated with strings without
|
391
|
+
# performing any encoding validation or conversion.
|
392
|
+
#
|
393
|
+
# *Substitution*
|
394
|
+
#
|
395
|
+
# * #sub!: Replaces the first substring that matches a given pattern with a
|
396
|
+
# given replacement string; returns `self` if any changes, `nil` otherwise.
|
397
|
+
# * #gsub!: Replaces each substring that matches a given pattern with a given
|
398
|
+
# replacement string; returns `self` if any changes, `nil` otherwise.
|
399
|
+
# * #succ! (aliased as #next!): Returns `self` modified to become its own
|
400
|
+
# successor.
|
401
|
+
# * #initialize_copy (aliased as #replace): Returns `self` with its entire
|
402
|
+
# content replaced by a given string.
|
403
|
+
# * #reverse!: Returns `self` with its characters in reverse order.
|
404
|
+
# * #setbyte: Sets the byte at a given integer offset to a given value;
|
405
|
+
# returns the argument.
|
406
|
+
# * #tr!: Replaces specified characters in `self` with specified replacement
|
407
|
+
# characters; returns `self` if any changes, `nil` otherwise.
|
408
|
+
# * #tr_s!: Replaces specified characters in `self` with specified replacement
|
409
|
+
# characters, removing duplicates from the substrings that were modified;
|
410
|
+
# returns `self` if any changes, `nil` otherwise.
|
411
|
+
#
|
412
|
+
# *Casing*
|
413
|
+
#
|
414
|
+
# * #capitalize!: Upcases the initial character and downcases all others;
|
415
|
+
# returns `self` if any changes, `nil` otherwise.
|
416
|
+
# * #downcase!: Downcases all characters; returns `self` if any changes, `nil`
|
417
|
+
# otherwise.
|
418
|
+
# * #upcase!: Upcases all characters; returns `self` if any changes, `nil`
|
419
|
+
# otherwise.
|
420
|
+
# * #swapcase!: Upcases each downcase character and downcases each upcase
|
421
|
+
# character; returns `self` if any changes, `nil` otherwise.
|
422
|
+
#
|
423
|
+
# *Encoding*
|
424
|
+
#
|
425
|
+
# * #encode!: Returns `self` with all characters transcoded from one encoding
|
426
|
+
# to another.
|
427
|
+
# * #unicode_normalize!: Unicode-normalizes `self`; returns `self`.
|
428
|
+
# * #scrub!: Replaces each invalid byte with a given character; returns
|
429
|
+
# `self`.
|
430
|
+
# * #force_encoding: Changes the encoding to a given encoding; returns `self`.
|
431
|
+
#
|
432
|
+
# *Deletion*
|
433
|
+
#
|
434
|
+
# * #clear: Removes all content, so that `self` is empty; returns `self`.
|
435
|
+
# * #slice!, #[]=: Removes a substring determined by a given index,
|
436
|
+
# start/length, range, regexp, or substring.
|
437
|
+
# * #squeeze!: Removes contiguous duplicate characters; returns `self`.
|
438
|
+
# * #delete!: Removes characters as determined by the intersection of
|
439
|
+
# substring arguments.
|
440
|
+
# * #lstrip!: Removes leading whitespace; returns `self` if any changes, `nil`
|
441
|
+
# otherwise.
|
442
|
+
# * #rstrip!: Removes trailing whitespace; returns `self` if any changes,
|
443
|
+
# `nil` otherwise.
|
444
|
+
# * #strip!: Removes leading and trailing whitespace; returns `self` if any
|
445
|
+
# changes, `nil` otherwise.
|
446
|
+
# * #chomp!: Removes the trailing record separator, if found; returns `self`
|
447
|
+
# if any changes, `nil` otherwise.
|
448
|
+
# * #chop!: Removes trailing newline characters if found; otherwise removes
|
449
|
+
# the last character; returns `self` if any changes, `nil` otherwise.
|
450
|
+
#
|
451
|
+
# ### Methods for Converting to New `String`
|
452
|
+
#
|
453
|
+
# Each of these methods returns a new `String` based on `self`, often just a
|
454
|
+
# modified copy of `self`.
|
455
|
+
#
|
456
|
+
# *Extension*
|
457
|
+
#
|
458
|
+
# * #*: Returns the concatenation of multiple copies of `self`.
|
459
|
+
# * #+: Returns the concatenation of `self` and a given other string.
|
460
|
+
# * #center: Returns a copy of `self` centered between pad substrings.
|
461
|
+
# * #concat: Returns the concatenation of `self` with given other strings.
|
462
|
+
# * #prepend: Returns the concatenation of a given other string with `self`.
|
463
|
+
# * #ljust: Returns a copy of `self` of a given length, right-padded with a
|
464
|
+
# given other string.
|
465
|
+
# * #rjust: Returns a copy of `self` of a given length, left-padded with a
|
466
|
+
# given other string.
|
467
|
+
#
|
468
|
+
# *Encoding*
|
469
|
+
#
|
470
|
+
# * #b: Returns a copy of `self` with ASCII-8BIT encoding.
|
471
|
+
# * #scrub: Returns a copy of `self` with each invalid byte replaced with a
|
472
|
+
# given character.
|
473
|
+
# * #unicode_normalize: Returns a copy of `self` with each character
|
474
|
+
# Unicode-normalized.
|
475
|
+
# * #encode: Returns a copy of `self` with all characters transcoded from one
|
476
|
+
# encoding to another.
|
477
|
+
#
|
478
|
+
# *Substitution*
|
479
|
+
#
|
480
|
+
# * #dump: Returns a copy of `self` with all non-printing characters replaced
|
481
|
+
# by xHH notation and all special characters escaped.
|
482
|
+
# * #undump: Returns a copy of `self` with all `\xNN` notations replaced by
|
483
|
+
# `\uNNNN` notations and all escaped characters unescaped.
|
484
|
+
# * #sub: Returns a copy of `self` with the first substring matching a given
|
485
|
+
# pattern replaced with a given replacement string.
|
486
|
+
# * #gsub: Returns a copy of `self` with each substring that matches a given
|
487
|
+
# pattern replaced with a given replacement string.
|
488
|
+
# * #succ (aliased as #next): Returns the string that is the successor to
|
489
|
+
# `self`.
|
490
|
+
# * #reverse: Returns a copy of `self` with its characters in reverse order.
|
491
|
+
# * #tr: Returns a copy of `self` with specified characters replaced with
|
492
|
+
# specified replacement characters.
|
493
|
+
# * #tr_s: Returns a copy of `self` with specified characters replaced with
|
494
|
+
# specified replacement characters, removing duplicates from the substrings
|
495
|
+
# that were modified.
|
496
|
+
# * #%: Returns the string resulting from formatting a given object into
|
497
|
+
# `self`.
|
498
|
+
#
|
499
|
+
# *Casing*
|
500
|
+
#
|
501
|
+
# * #capitalize: Returns a copy of `self` with the first character upcased and
|
502
|
+
# all other characters downcased.
|
503
|
+
# * #downcase: Returns a copy of `self` with all characters downcased.
|
504
|
+
# * #upcase: Returns a copy of `self` with all characters upcased.
|
505
|
+
# * #swapcase: Returns a copy of `self` with all upcase characters downcased
|
506
|
+
# and all downcase characters upcased.
|
507
|
+
#
|
508
|
+
# *Deletion*
|
509
|
+
#
|
510
|
+
# * #delete: Returns a copy of `self` with characters removed.
|
511
|
+
# * #delete_prefix: Returns a copy of `self` with a given prefix removed.
|
512
|
+
# * #delete_suffix: Returns a copy of `self` with a given suffix removed.
|
513
|
+
# * #lstrip: Returns a copy of `self` with leading whitespace removed.
|
514
|
+
# * #rstrip: Returns a copy of `self` with trailing whitespace removed.
|
515
|
+
# * #strip: Returns a copy of `self` with leading and trailing whitespace
|
516
|
+
# removed.
|
517
|
+
# * #chomp: Returns a copy of `self` with a trailing record separator removed,
|
518
|
+
# if found.
|
519
|
+
# * #chop: Returns a copy of `self` with trailing newline characters or the
|
520
|
+
# last character removed.
|
521
|
+
# * #squeeze: Returns a copy of `self` with contiguous duplicate characters
|
522
|
+
# removed.
|
523
|
+
# * #[] (aliased as #slice): Returns a substring determined by a given index,
|
524
|
+
# start/length, range, regexp, or string.
|
525
|
+
# * #byteslice: Returns a substring determined by a given index, start/length,
|
526
|
+
# or range.
|
527
|
+
# * #chr: Returns the first character.
|
528
|
+
#
|
529
|
+
# *Duplication*
|
530
|
+
#
|
531
|
+
# * #to_s (aliased as #to_str): If `self` is a subclass of `String`, returns
|
532
|
+
# `self` copied into a `String`; otherwise, returns `self`.
|
533
|
+
#
|
534
|
+
# ### Methods for Converting to Non-`String`
|
535
|
+
#
|
536
|
+
# Each of these methods converts the contents of `self` to a non-`String`.
|
537
|
+
#
|
538
|
+
# *Characters, Bytes, and Clusters*
|
539
|
+
#
|
540
|
+
# * #bytes: Returns an array of the bytes in `self`.
|
541
|
+
# * #chars: Returns an array of the characters in `self`.
|
542
|
+
# * #codepoints: Returns an array of the integer ordinals in `self`.
|
543
|
+
# * #getbyte: Returns the integer byte at the given index in `self`.
|
544
|
+
# * #grapheme_clusters: Returns an array of the grapheme clusters in `self`.
|
545
|
+
#
|
546
|
+
# *Splitting*
|
547
|
+
#
|
548
|
+
# * #lines: Returns an array of the lines in `self`, as determined by a given
|
549
|
+
# record separator.
|
550
|
+
# * #partition: Returns a 3-element array determined by the first substring
|
551
|
+
# that matches a given substring or regexp.
|
552
|
+
# * #rpartition: Returns a 3-element array determined by the last substring
|
553
|
+
# that matches a given substring or regexp.
|
554
|
+
# * #split: Returns an array of substrings determined by a given delimiter --
|
555
|
+
# regexp or string -- or, if a block is given, passes those substrings to
|
556
|
+
# the block.
|
557
|
+
#
|
558
|
+
# *Matching*
|
559
|
+
#
|
560
|
+
# * #scan: Returns an array of substrings matching a given regexp or string,
|
561
|
+
# or, if a block is given, passes each matching substring to the block.
|
562
|
+
# * #unpack: Returns an array of substrings extracted from `self` according to
|
563
|
+
# a given format.
|
564
|
+
# * #unpack1: Returns the first substring extracted from `self` according to a
|
565
|
+
# given format.
|
566
|
+
#
|
567
|
+
# *Numerics*
|
568
|
+
#
|
569
|
+
# * #hex: Returns the integer value of the leading characters, interpreted as
|
570
|
+
# hexadecimal digits.
|
571
|
+
# * #oct: Returns the integer value of the leading characters, interpreted as
|
572
|
+
# octal digits.
|
573
|
+
# * #ord: Returns the integer ordinal of the first character in `self`.
|
574
|
+
# * #to_i: Returns the integer value of leading characters, interpreted as an
|
575
|
+
# integer.
|
576
|
+
# * #to_f: Returns the floating-point value of leading characters, interpreted
|
577
|
+
# as a floating-point number.
|
578
|
+
#
|
579
|
+
# *Strings and Symbols*
|
580
|
+
#
|
581
|
+
# * #inspect: Returns a copy of `self`, enclosed in double quotes, with
|
582
|
+
# special characters escaped.
|
583
|
+
# * #intern (aliased as #to_sym): Returns the symbol corresponding to `self`.
|
584
|
+
#
|
585
|
+
# ### Methods for Iterating
|
586
|
+
#
|
587
|
+
# * #each_byte: Calls the given block with each successive byte in `self`.
|
588
|
+
# * #each_char: Calls the given block with each successive character in
|
589
|
+
# `self`.
|
590
|
+
# * #each_codepoint: Calls the given block with each successive integer
|
591
|
+
# codepoint in `self`.
|
592
|
+
# * #each_grapheme_cluster: Calls the given block with each successive
|
593
|
+
# grapheme cluster in `self`.
|
594
|
+
# * #each_line: Calls the given block with each successive line in `self`, as
|
595
|
+
# determined by a given record separator.
|
596
|
+
# * #upto: Calls the given block with each string value returned by successive
|
597
|
+
# calls to #succ.
|
598
|
+
#
|
599
|
+
class String
|
600
|
+
include Comparable
|
601
|
+
|
602
|
+
# A `selector` is a special type of string, used within methods like `String#tr`.
|
603
|
+
type selector = string
|
604
|
+
|
605
|
+
# <!--
|
606
|
+
# rdoc-file=string.c
|
607
|
+
# - String.try_convert(object) -> object, new_string, or nil
|
608
|
+
# -->
|
609
|
+
# If `object` is a `String` object, returns `object`.
|
610
|
+
#
|
611
|
+
# Otherwise if `object` responds to `:to_str`, calls `object.to_str` and returns
|
612
|
+
# the result.
|
613
|
+
#
|
614
|
+
# Returns `nil` if `object` does not respond to `:to_str`.
|
615
|
+
#
|
616
|
+
# Raises an exception unless `object.to_str` returns a `String` object.
|
617
|
+
#
|
618
|
+
def self.try_convert: (String object) -> String # technically will return `object` unchanged.
|
619
|
+
| (_ToStr object) -> String
|
620
|
+
| (untyped object) -> String?
|
621
|
+
|
622
|
+
# <!--
|
623
|
+
# rdoc-file=string.c
|
624
|
+
# - String.new(string = '', **opts) -> new_string
|
625
|
+
# -->
|
626
|
+
# Returns a new String that is a copy of `string`.
|
627
|
+
#
|
628
|
+
# With no arguments, returns the empty string with the Encoding `ASCII-8BIT`:
|
629
|
+
#
|
630
|
+
# s = String.new
|
631
|
+
# s # => ""
|
632
|
+
# s.encoding # => #<Encoding:ASCII-8BIT>
|
633
|
+
#
|
634
|
+
# With optional argument `string` and no keyword arguments, returns a copy of
|
635
|
+
# `string` with the same encoding:
|
636
|
+
#
|
637
|
+
# String.new('foo') # => "foo"
|
638
|
+
# String.new('тест') # => "тест"
|
639
|
+
# String.new('こんにちは') # => "こんにちは"
|
640
|
+
#
|
641
|
+
# (Unlike String.new, a [string
|
642
|
+
# literal](rdoc-ref:syntax/literals.rdoc@String+Literals) like `''` or a [here
|
643
|
+
# document literal](rdoc-ref:syntax/literals.rdoc@Here+Document+Literals) always
|
644
|
+
# has [script encoding](rdoc-ref:encodings.rdoc@Script+Encoding).)
|
645
|
+
#
|
646
|
+
# With optional keyword argument `encoding`, returns a copy of `string` with the
|
647
|
+
# specified encoding; the `encoding` may be an Encoding object, an encoding
|
648
|
+
# name, or an encoding name alias:
|
649
|
+
#
|
650
|
+
# String.new('foo', encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII>
|
651
|
+
# String.new('foo', encoding: 'US-ASCII').encoding # => #<Encoding:US-ASCII>
|
652
|
+
# String.new('foo', encoding: 'ASCII').encoding # => #<Encoding:US-ASCII>
|
653
|
+
#
|
654
|
+
# The given encoding need not be valid for the string's content, and that
|
655
|
+
# validity is not checked:
|
656
|
+
#
|
657
|
+
# s = String.new('こんにちは', encoding: 'ascii')
|
658
|
+
# s.valid_encoding? # => false
|
659
|
+
#
|
660
|
+
# But the given `encoding` itself is checked:
|
661
|
+
#
|
662
|
+
# String.new('foo', encoding: 'bar') # Raises ArgumentError.
|
663
|
+
#
|
664
|
+
# With optional keyword argument `capacity`, returns a copy of `string` (or an
|
665
|
+
# empty string, if `string` is not given); the given `capacity` is advisory
|
666
|
+
# only, and may or may not set the size of the internal buffer, which may in
|
667
|
+
# turn affect performance:
|
668
|
+
#
|
669
|
+
# String.new(capacity: 1)
|
670
|
+
# String.new('foo', capacity: 4096)
|
671
|
+
#
|
672
|
+
# Note that Ruby strings are null-terminated internally, so the internal buffer
|
673
|
+
# size will be one or more bytes larger than the requested capacity depending on
|
674
|
+
# the encoding.
|
675
|
+
#
|
676
|
+
# The `string`, `encoding`, and `capacity` arguments may all be used together:
|
677
|
+
#
|
678
|
+
# String.new('hello', encoding: 'UTF-8', capacity: 25)
|
679
|
+
#
|
680
|
+
def initialize: (?string source, ?encoding: encoding, ?capacity: int) -> void
|
681
|
+
|
682
|
+
# <!--
|
683
|
+
# rdoc-file=string.c
|
684
|
+
# - replace(other_string) -> self
|
685
|
+
# -->
|
686
|
+
# Replaces the contents of `self` with the contents of `other_string`:
|
687
|
+
#
|
688
|
+
# s = 'foo' # => "foo"
|
689
|
+
# s.replace('bar') # => "bar"
|
690
|
+
#
|
691
|
+
alias initialize_copy replace
|
692
|
+
|
693
|
+
# <!--
|
694
|
+
# rdoc-file=string.c
|
695
|
+
# - string % object -> new_string
|
696
|
+
# -->
|
697
|
+
# Returns the result of formatting `object` into the format specification `self`
|
698
|
+
# (see Kernel#sprintf for formatting details):
|
699
|
+
#
|
700
|
+
# "%05d" % 123 # => "00123"
|
701
|
+
#
|
702
|
+
# If `self` contains multiple substitutions, `object` must be an Array or Hash
|
703
|
+
# containing the values to be substituted:
|
704
|
+
#
|
705
|
+
# "%-5s: %016x" % [ "ID", self.object_id ] # => "ID : 00002b054ec93168"
|
706
|
+
# "foo = %{foo}" % {foo: 'bar'} # => "foo = bar"
|
707
|
+
# "foo = %{foo}, baz = %{baz}" % {foo: 'bar', baz: 'bat'} # => "foo = bar, baz = bat"
|
708
|
+
#
|
709
|
+
def %: (array[untyped] positional_args) -> String
|
710
|
+
| (hash[Symbol, untyped] named_args) -> String
|
711
|
+
| (untyped arg) -> String
|
712
|
+
|
713
|
+
# <!--
|
714
|
+
# rdoc-file=string.c
|
715
|
+
# - string * integer -> new_string
|
716
|
+
# -->
|
717
|
+
# Returns a new `String` containing `integer` copies of `self`:
|
718
|
+
#
|
719
|
+
# "Ho! " * 3 # => "Ho! Ho! Ho! "
|
720
|
+
# "Ho! " * 0 # => ""
|
721
|
+
#
|
722
|
+
def *: (int amount) -> String
|
723
|
+
|
724
|
+
# <!--
|
725
|
+
# rdoc-file=string.c
|
726
|
+
# - string + other_string -> new_string
|
727
|
+
# -->
|
728
|
+
# Returns a new `String` containing `other_string` concatenated to `self`:
|
729
|
+
#
|
730
|
+
# "Hello from " + self.to_s # => "Hello from main"
|
731
|
+
#
|
732
|
+
def +: (string other_string) -> String
|
733
|
+
|
734
|
+
# <!--
|
735
|
+
# rdoc-file=string.c
|
736
|
+
# - +string -> new_string or self
|
737
|
+
# -->
|
738
|
+
# Returns `self` if `self` is not frozen and can be mutated without warning
|
739
|
+
# issuance.
|
740
|
+
#
|
741
|
+
# Otherwise returns `self.dup`, which is not frozen.
|
742
|
+
#
|
743
|
+
def +@: () -> self
|
744
|
+
|
745
|
+
# <!--
|
746
|
+
# rdoc-file=string.c
|
747
|
+
# - -string -> frozen_string
|
748
|
+
# - dedup -> frozen_string
|
749
|
+
# -->
|
750
|
+
# Returns a frozen, possibly pre-existing copy of the string.
|
751
|
+
#
|
752
|
+
# The returned `String` will be deduplicated as long as it does not have any
|
753
|
+
# instance variables set on it and is not a String subclass.
|
754
|
+
#
|
755
|
+
# Note that `-string` variant is more convenient for defining constants:
|
756
|
+
#
|
757
|
+
# FILENAME = -'config/database.yml'
|
758
|
+
#
|
759
|
+
# while `dedup` is better suitable for using the method in chains of
|
760
|
+
# calculations:
|
761
|
+
#
|
762
|
+
# @url_list.concat(urls.map(&:dedup))
|
763
|
+
#
|
764
|
+
def -@: () -> self
|
765
|
+
|
766
|
+
# <!--
|
767
|
+
# rdoc-file=string.c
|
768
|
+
# - string << object -> string
|
769
|
+
# -->
|
770
|
+
# Concatenates `object` to `self` and returns `self`:
|
771
|
+
#
|
772
|
+
# s = 'foo'
|
773
|
+
# s << 'bar' # => "foobar"
|
774
|
+
# s # => "foobar"
|
775
|
+
#
|
776
|
+
# If `object` is an Integer, the value is considered a codepoint and converted
|
777
|
+
# to a character before concatenation:
|
778
|
+
#
|
779
|
+
# s = 'foo'
|
780
|
+
# s << 33 # => "foo!"
|
781
|
+
#
|
782
|
+
# If that codepoint is not representable in the encoding of *string*, RangeError
|
783
|
+
# is raised.
|
784
|
+
#
|
785
|
+
# s = 'foo'
|
786
|
+
# s.encoding # => <Encoding:UTF-8>
|
787
|
+
# s << 0x00110000 # 1114112 out of char range (RangeError)
|
788
|
+
# s = 'foo'.encode('EUC-JP')
|
789
|
+
# s << 0x00800080 # invalid codepoint 0x800080 in EUC-JP (RangeError)
|
790
|
+
#
|
791
|
+
# If the encoding is US-ASCII and the codepoint is 0..0xff, *string* is
|
792
|
+
# automatically promoted to ASCII-8BIT.
|
793
|
+
#
|
794
|
+
# s = 'foo'.encode('US-ASCII')
|
795
|
+
# s << 0xff
|
796
|
+
# s.encoding # => #<Encoding:BINARY (ASCII-8BIT)>
|
797
|
+
#
|
798
|
+
# Related: String#concat, which takes multiple arguments.
|
799
|
+
#
|
800
|
+
def <<: (string | Integer str_or_codepoint) -> self
|
801
|
+
|
802
|
+
# <!--
|
803
|
+
# rdoc-file=string.c
|
804
|
+
# - string <=> other_string -> -1, 0, 1, or nil
|
805
|
+
# -->
|
806
|
+
# Compares `self` and `other_string`, returning:
|
807
|
+
#
|
808
|
+
# * -1 if `other_string` is larger.
|
809
|
+
# * 0 if the two are equal.
|
810
|
+
# * 1 if `other_string` is smaller.
|
811
|
+
# * `nil` if the two are incomparable.
|
812
|
+
#
|
813
|
+
# Examples:
|
814
|
+
#
|
815
|
+
# 'foo' <=> 'foo' # => 0
|
816
|
+
# 'foo' <=> 'food' # => -1
|
817
|
+
# 'food' <=> 'foo' # => 1
|
818
|
+
# 'FOO' <=> 'foo' # => -1
|
819
|
+
# 'foo' <=> 'FOO' # => 1
|
820
|
+
# 'foo' <=> 1 # => nil
|
821
|
+
#
|
822
|
+
def <=>: (string) -> (-1 | 0 | 1)
|
823
|
+
| (untyped) -> (-1 | 0 | 1)?
|
824
|
+
|
825
|
+
# <!--
|
826
|
+
# rdoc-file=string.c
|
827
|
+
# - string == object -> true or false
|
828
|
+
# - string === object -> true or false
|
829
|
+
# -->
|
830
|
+
# Returns `true` if `object` has the same length and content; as `self`; `false`
|
831
|
+
# otherwise:
|
832
|
+
#
|
833
|
+
# s = 'foo'
|
834
|
+
# s == 'foo' # => true
|
835
|
+
# s == 'food' # => false
|
836
|
+
# s == 'FOO' # => false
|
837
|
+
#
|
838
|
+
# Returns `false` if the two strings' encodings are not compatible:
|
839
|
+
# "\u{e4 f6 fc}".encode("ISO-8859-1") == ("\u{c4 d6 dc}") # => false
|
840
|
+
#
|
841
|
+
# If `object` is not an instance of `String` but responds to `to_str`, then the
|
842
|
+
# two strings are compared using `object.==`.
|
843
|
+
#
|
844
|
+
def ==: (untyped other) -> bool
|
845
|
+
|
846
|
+
# <!-- rdoc-file=string.c -->
|
847
|
+
# Returns `true` if `object` has the same length and content; as `self`; `false`
|
848
|
+
# otherwise:
|
849
|
+
#
|
850
|
+
# s = 'foo'
|
851
|
+
# s == 'foo' # => true
|
852
|
+
# s == 'food' # => false
|
853
|
+
# s == 'FOO' # => false
|
854
|
+
#
|
855
|
+
# Returns `false` if the two strings' encodings are not compatible:
|
856
|
+
# "\u{e4 f6 fc}".encode("ISO-8859-1") == ("\u{c4 d6 dc}") # => false
|
857
|
+
#
|
858
|
+
# If `object` is not an instance of `String` but responds to `to_str`, then the
|
859
|
+
# two strings are compared using `object.==`.
|
860
|
+
#
|
861
|
+
alias === ==
|
862
|
+
|
863
|
+
# <!--
|
864
|
+
# rdoc-file=string.c
|
865
|
+
# - string =~ regexp -> integer or nil
|
866
|
+
# - string =~ object -> integer or nil
|
867
|
+
# -->
|
868
|
+
# Returns the Integer index of the first substring that matches the given
|
869
|
+
# `regexp`, or `nil` if no match found:
|
870
|
+
#
|
871
|
+
# 'foo' =~ /f/ # => 0
|
872
|
+
# 'foo' =~ /o/ # => 1
|
873
|
+
# 'foo' =~ /x/ # => nil
|
874
|
+
#
|
875
|
+
# Note: also updates Regexp@Global+Variables.
|
876
|
+
#
|
877
|
+
# If the given `object` is not a Regexp, returns the value returned by `object
|
878
|
+
# =~ self`.
|
879
|
+
#
|
880
|
+
# Note that `string =~ regexp` is different from `regexp =~ string` (see
|
881
|
+
# Regexp#=~):
|
882
|
+
#
|
883
|
+
# number= nil
|
884
|
+
# "no. 9" =~ /(?<number>\d+)/
|
885
|
+
# number # => nil (not assigned)
|
886
|
+
# /(?<number>\d+)/ =~ "no. 9"
|
887
|
+
# number #=> "9"
|
888
|
+
#
|
889
|
+
def =~: (Regexp regex) -> Integer?
|
890
|
+
| [T] (_MatchAgainst[self, T] object) -> T
|
891
|
+
|
892
|
+
interface _MatchAgainst[O, T]
|
893
|
+
def =~: (O string) -> T
|
894
|
+
end
|
895
|
+
|
896
|
+
# <!--
|
897
|
+
# rdoc-file=string.c
|
898
|
+
# - string[index] -> new_string or nil
|
899
|
+
# - string[start, length] -> new_string or nil
|
900
|
+
# - string[range] -> new_string or nil
|
901
|
+
# - string[regexp, capture = 0] -> new_string or nil
|
902
|
+
# - string[substring] -> new_string or nil
|
903
|
+
# -->
|
904
|
+
# Returns the substring of `self` specified by the arguments. See examples at
|
905
|
+
# [String Slices](rdoc-ref:String@String+Slices).
|
906
|
+
#
|
907
|
+
def []: (int start, ?int length) -> String?
|
908
|
+
| (range[int?] range) -> String?
|
909
|
+
| (Regexp regexp, ?MatchData::capture backref) -> String?
|
910
|
+
| (String substring) -> String?
|
911
|
+
|
912
|
+
# <!--
|
913
|
+
# rdoc-file=string.c
|
914
|
+
# - string[index] = new_string
|
915
|
+
# - string[start, length] = new_string
|
916
|
+
# - string[range] = new_string
|
917
|
+
# - string[regexp, capture = 0] = new_string
|
918
|
+
# - string[substring] = new_string
|
919
|
+
# -->
|
920
|
+
# Replaces all, some, or none of the contents of `self`; returns `new_string`.
|
921
|
+
# See [String Slices](rdoc-ref:String@String+Slices).
|
922
|
+
#
|
923
|
+
# A few examples:
|
924
|
+
#
|
925
|
+
# s = 'foo'
|
926
|
+
# s[2] = 'rtune' # => "rtune"
|
927
|
+
# s # => "fortune"
|
928
|
+
# s[1, 5] = 'init' # => "init"
|
929
|
+
# s # => "finite"
|
930
|
+
# s[3..4] = 'al' # => "al"
|
931
|
+
# s # => "finale"
|
932
|
+
# s[/e$/] = 'ly' # => "ly"
|
933
|
+
# s # => "finally"
|
934
|
+
# s['lly'] = 'ncial' # => "ncial"
|
935
|
+
# s # => "financial"
|
936
|
+
#
|
937
|
+
def []=: [T < _ToStr] (int index, T replacement) -> T
|
938
|
+
| [T < _ToStr] (int start, int length, T replacement) -> T
|
939
|
+
| [T < _ToStr] (range[int?] range, T replacement) -> T
|
940
|
+
| [T < _ToStr] (Regexp regexp, T replacement) -> T
|
941
|
+
| [T < _ToStr] (Regexp regexp, MatchData::capture backref, T replacement) -> T
|
942
|
+
| [T < _ToStr] (String substring, T replacement) -> T
|
943
|
+
|
944
|
+
# <!--
|
945
|
+
# rdoc-file=string.c
|
946
|
+
# - append_as_bytes(*objects) -> string
|
947
|
+
# -->
|
948
|
+
# Concatenates each object in `objects` into `self` without any encoding
|
949
|
+
# validation or conversion and returns `self`:
|
950
|
+
#
|
951
|
+
# s = 'foo'
|
952
|
+
# s.append_as_bytes(" \xE2\x82") # => "foo \xE2\x82"
|
953
|
+
# s.valid_encoding? # => false
|
954
|
+
# s.append_as_bytes("\xAC 12")
|
955
|
+
# s.valid_encoding? # => true
|
956
|
+
#
|
957
|
+
# For each given object `object` that is an Integer, the value is considered a
|
958
|
+
# Byte. If the Integer is bigger than one byte, only the lower byte is
|
959
|
+
# considered, similar to String#setbyte:
|
960
|
+
#
|
961
|
+
# s = ""
|
962
|
+
# s.append_as_bytes(0, 257) # => "\u0000\u0001"
|
963
|
+
#
|
964
|
+
# Related: String#<<, String#concat, which do an encoding aware concatenation.
|
965
|
+
#
|
966
|
+
def append_as_bytes: (String) -> String
|
967
|
+
|
968
|
+
# <!--
|
969
|
+
# rdoc-file=string.c
|
970
|
+
# - ascii_only? -> true or false
|
971
|
+
# -->
|
972
|
+
# Returns `true` if `self` contains only ASCII characters, `false` otherwise:
|
973
|
+
#
|
974
|
+
# 'abc'.ascii_only? # => true
|
975
|
+
# "abc\u{6666}".ascii_only? # => false
|
976
|
+
#
|
977
|
+
def ascii_only?: () -> bool
|
978
|
+
|
979
|
+
# <!--
|
980
|
+
# rdoc-file=string.c
|
981
|
+
# - b -> string
|
982
|
+
# -->
|
983
|
+
# Returns a copy of `self` that has ASCII-8BIT encoding; the underlying bytes
|
984
|
+
# are not modified:
|
985
|
+
#
|
986
|
+
# s = "\x99"
|
987
|
+
# s.encoding # => #<Encoding:UTF-8>
|
988
|
+
# t = s.b # => "\x99"
|
989
|
+
# t.encoding # => #<Encoding:ASCII-8BIT>
|
990
|
+
#
|
991
|
+
# s = "\u4095" # => "䂕"
|
992
|
+
# s.encoding # => #<Encoding:UTF-8>
|
993
|
+
# s.bytes # => [228, 130, 149]
|
994
|
+
# t = s.b # => "\xE4\x82\x95"
|
995
|
+
# t.encoding # => #<Encoding:ASCII-8BIT>
|
996
|
+
# t.bytes # => [228, 130, 149]
|
997
|
+
#
|
998
|
+
def b: () -> String
|
999
|
+
|
1000
|
+
# <!--
|
1001
|
+
# rdoc-file=string.c
|
1002
|
+
# - byteindex(substring, offset = 0) -> integer or nil
|
1003
|
+
# - byteindex(regexp, offset = 0) -> integer or nil
|
1004
|
+
# -->
|
1005
|
+
# Returns the Integer byte-based index of the first occurrence of the given
|
1006
|
+
# `substring`, or `nil` if none found:
|
1007
|
+
#
|
1008
|
+
# 'foo'.byteindex('f') # => 0
|
1009
|
+
# 'foo'.byteindex('o') # => 1
|
1010
|
+
# 'foo'.byteindex('oo') # => 1
|
1011
|
+
# 'foo'.byteindex('ooo') # => nil
|
1012
|
+
#
|
1013
|
+
# Returns the Integer byte-based index of the first match for the given Regexp
|
1014
|
+
# `regexp`, or `nil` if none found:
|
1015
|
+
#
|
1016
|
+
# 'foo'.byteindex(/f/) # => 0
|
1017
|
+
# 'foo'.byteindex(/o/) # => 1
|
1018
|
+
# 'foo'.byteindex(/oo/) # => 1
|
1019
|
+
# 'foo'.byteindex(/ooo/) # => nil
|
1020
|
+
#
|
1021
|
+
# Integer argument `offset`, if given, specifies the byte-based position in the
|
1022
|
+
# string to begin the search:
|
1023
|
+
#
|
1024
|
+
# 'foo'.byteindex('o', 1) # => 1
|
1025
|
+
# 'foo'.byteindex('o', 2) # => 2
|
1026
|
+
# 'foo'.byteindex('o', 3) # => nil
|
1027
|
+
#
|
1028
|
+
# If `offset` is negative, counts backward from the end of `self`:
|
1029
|
+
#
|
1030
|
+
# 'foo'.byteindex('o', -1) # => 2
|
1031
|
+
# 'foo'.byteindex('o', -2) # => 1
|
1032
|
+
# 'foo'.byteindex('o', -3) # => 1
|
1033
|
+
# 'foo'.byteindex('o', -4) # => nil
|
1034
|
+
#
|
1035
|
+
# If `offset` does not land on character (codepoint) boundary, `IndexError` is
|
1036
|
+
# raised.
|
1037
|
+
#
|
1038
|
+
# Related: String#index, String#byterindex.
|
1039
|
+
#
|
1040
|
+
def byteindex: (Regexp | string pattern, ?int offset) -> Integer?
|
1041
|
+
|
1042
|
+
# <!--
|
1043
|
+
# rdoc-file=string.c
|
1044
|
+
# - byterindex(substring, offset = self.bytesize) -> integer or nil
|
1045
|
+
# - byterindex(regexp, offset = self.bytesize) -> integer or nil
|
1046
|
+
# -->
|
1047
|
+
# Returns the Integer byte-based index of the *last* occurrence of the given
|
1048
|
+
# `substring`, or `nil` if none found:
|
1049
|
+
#
|
1050
|
+
# 'foo'.byterindex('f') # => 0
|
1051
|
+
# 'foo'.byterindex('o') # => 2
|
1052
|
+
# 'foo'.byterindex('oo') # => 1
|
1053
|
+
# 'foo'.byterindex('ooo') # => nil
|
1054
|
+
#
|
1055
|
+
# Returns the Integer byte-based index of the *last* match for the given Regexp
|
1056
|
+
# `regexp`, or `nil` if none found:
|
1057
|
+
#
|
1058
|
+
# 'foo'.byterindex(/f/) # => 0
|
1059
|
+
# 'foo'.byterindex(/o/) # => 2
|
1060
|
+
# 'foo'.byterindex(/oo/) # => 1
|
1061
|
+
# 'foo'.byterindex(/ooo/) # => nil
|
1062
|
+
#
|
1063
|
+
# The *last* match means starting at the possible last position, not the last of
|
1064
|
+
# longest matches.
|
1065
|
+
#
|
1066
|
+
# 'foo'.byterindex(/o+/) # => 2
|
1067
|
+
# $~ #=> #<MatchData "o">
|
1068
|
+
#
|
1069
|
+
# To get the last longest match, needs to combine with negative lookbehind.
|
1070
|
+
#
|
1071
|
+
# 'foo'.byterindex(/(?<!o)o+/) # => 1
|
1072
|
+
# $~ #=> #<MatchData "oo">
|
1073
|
+
#
|
1074
|
+
# Or String#byteindex with negative lookforward.
|
1075
|
+
#
|
1076
|
+
# 'foo'.byteindex(/o+(?!.*o)/) # => 1
|
1077
|
+
# $~ #=> #<MatchData "oo">
|
1078
|
+
#
|
1079
|
+
# Integer argument `offset`, if given and non-negative, specifies the maximum
|
1080
|
+
# starting byte-based position in the string to *end* the search:
|
1081
|
+
#
|
1082
|
+
# 'foo'.byterindex('o', 0) # => nil
|
1083
|
+
# 'foo'.byterindex('o', 1) # => 1
|
1084
|
+
# 'foo'.byterindex('o', 2) # => 2
|
1085
|
+
# 'foo'.byterindex('o', 3) # => 2
|
1086
|
+
#
|
1087
|
+
# If `offset` is a negative Integer, the maximum starting position in the string
|
1088
|
+
# to *end* the search is the sum of the string's length and `offset`:
|
1089
|
+
#
|
1090
|
+
# 'foo'.byterindex('o', -1) # => 2
|
1091
|
+
# 'foo'.byterindex('o', -2) # => 1
|
1092
|
+
# 'foo'.byterindex('o', -3) # => nil
|
1093
|
+
# 'foo'.byterindex('o', -4) # => nil
|
1094
|
+
#
|
1095
|
+
# If `offset` does not land on character (codepoint) boundary, `IndexError` is
|
1096
|
+
# raised.
|
1097
|
+
#
|
1098
|
+
# Related: String#byteindex.
|
1099
|
+
#
|
1100
|
+
def byterindex: (Regexp | string pattern, ?int offset) -> Integer?
|
1101
|
+
|
1102
|
+
# <!--
|
1103
|
+
# rdoc-file=string.c
|
1104
|
+
# - bytes -> array_of_bytes
|
1105
|
+
# -->
|
1106
|
+
# Returns an array of the bytes in `self`:
|
1107
|
+
#
|
1108
|
+
# 'hello'.bytes # => [104, 101, 108, 108, 111]
|
1109
|
+
# 'тест'.bytes # => [209, 130, 208, 181, 209, 129, 209, 130]
|
1110
|
+
# 'こんにちは'.bytes
|
1111
|
+
# # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
|
1112
|
+
#
|
1113
|
+
def bytes: () -> Array[Integer]
|
1114
|
+
| () { (Integer byte) -> void } -> self
|
1115
|
+
|
1116
|
+
# <!--
|
1117
|
+
# rdoc-file=string.c
|
1118
|
+
# - bytesize -> integer
|
1119
|
+
# -->
|
1120
|
+
# Returns the count of bytes (not characters) in `self`:
|
1121
|
+
#
|
1122
|
+
# 'foo'.bytesize # => 3
|
1123
|
+
# 'тест'.bytesize # => 8
|
1124
|
+
# 'こんにちは'.bytesize # => 15
|
1125
|
+
#
|
1126
|
+
# Contrast with String#length:
|
1127
|
+
#
|
1128
|
+
# 'foo'.length # => 3
|
1129
|
+
# 'тест'.length # => 4
|
1130
|
+
# 'こんにちは'.length # => 5
|
1131
|
+
#
|
1132
|
+
def bytesize: () -> Integer
|
1133
|
+
|
1134
|
+
# <!--
|
1135
|
+
# rdoc-file=string.c
|
1136
|
+
# - byteslice(index, length = 1) -> string or nil
|
1137
|
+
# - byteslice(range) -> string or nil
|
1138
|
+
# -->
|
1139
|
+
# Returns a substring of `self`, or `nil` if the substring cannot be
|
1140
|
+
# constructed.
|
1141
|
+
#
|
1142
|
+
# With integer arguments `index` and `length` given, returns the substring
|
1143
|
+
# beginning at the given `index` of the given `length` (if possible), or `nil`
|
1144
|
+
# if `length` is negative or `index` falls outside of `self`:
|
1145
|
+
#
|
1146
|
+
# s = '0123456789' # => "0123456789"
|
1147
|
+
# s.byteslice(2) # => "2"
|
1148
|
+
# s.byteslice(200) # => nil
|
1149
|
+
# s.byteslice(4, 3) # => "456"
|
1150
|
+
# s.byteslice(4, 30) # => "456789"
|
1151
|
+
# s.byteslice(4, -1) # => nil
|
1152
|
+
# s.byteslice(40, 2) # => nil
|
1153
|
+
#
|
1154
|
+
# In either case above, counts backwards from the end of `self` if `index` is
|
1155
|
+
# negative:
|
1156
|
+
#
|
1157
|
+
# s = '0123456789' # => "0123456789"
|
1158
|
+
# s.byteslice(-4) # => "6"
|
1159
|
+
# s.byteslice(-4, 3) # => "678"
|
1160
|
+
#
|
1161
|
+
# With Range argument `range` given, returns `byteslice(range.begin,
|
1162
|
+
# range.size)`:
|
1163
|
+
#
|
1164
|
+
# s = '0123456789' # => "0123456789"
|
1165
|
+
# s.byteslice(4..6) # => "456"
|
1166
|
+
# s.byteslice(-6..-4) # => "456"
|
1167
|
+
# s.byteslice(5..2) # => "" # range.size is zero.
|
1168
|
+
# s.byteslice(40..42) # => nil
|
1169
|
+
#
|
1170
|
+
# In all cases, a returned string has the same encoding as `self`:
|
1171
|
+
#
|
1172
|
+
# s.encoding # => #<Encoding:UTF-8>
|
1173
|
+
# s.byteslice(4).encoding # => #<Encoding:UTF-8>
|
1174
|
+
#
|
1175
|
+
def byteslice: (int start, ?int length) -> String?
|
1176
|
+
| (range[int?] range) -> String?
|
1177
|
+
|
1178
|
+
# <!--
|
1179
|
+
# rdoc-file=string.c
|
1180
|
+
# - bytesplice(index, length, str) -> string
|
1181
|
+
# - bytesplice(index, length, str, str_index, str_length) -> string
|
1182
|
+
# - bytesplice(range, str) -> string
|
1183
|
+
# - bytesplice(range, str, str_range) -> string
|
1184
|
+
# -->
|
1185
|
+
# Replaces some or all of the content of `self` with `str`, and returns `self`.
|
1186
|
+
# The portion of the string affected is determined using the same criteria as
|
1187
|
+
# String#byteslice, except that `length` cannot be omitted. If the replacement
|
1188
|
+
# string is not the same length as the text it is replacing, the string will be
|
1189
|
+
# adjusted accordingly.
|
1190
|
+
#
|
1191
|
+
# If `str_index` and `str_length`, or `str_range` are given, the content of
|
1192
|
+
# `self` is replaced by str.byteslice(str_index, str_length) or
|
1193
|
+
# str.byteslice(str_range); however the substring of `str` is not allocated as a
|
1194
|
+
# new string.
|
1195
|
+
#
|
1196
|
+
# The form that take an Integer will raise an IndexError if the value is out of
|
1197
|
+
# range; the Range form will raise a RangeError. If the beginning or ending
|
1198
|
+
# offset does not land on character (codepoint) boundary, an IndexError will be
|
1199
|
+
# raised.
|
1200
|
+
#
|
1201
|
+
def bytesplice: (Integer start, int length, string str) -> String
|
1202
|
+
| (int start, int length, string str, int str_start, int str_length) -> String
|
1203
|
+
| (range[int?] range, string str, ?range[int?] str_range) -> String
|
1204
|
+
|
1205
|
+
# <!--
|
1206
|
+
# rdoc-file=string.c
|
1207
|
+
# - capitalize(*options) -> string
|
1208
|
+
# -->
|
1209
|
+
# Returns a string containing the characters in `self`; the first character is
|
1210
|
+
# upcased; the remaining characters are downcased:
|
1211
|
+
#
|
1212
|
+
# s = 'hello World!' # => "hello World!"
|
1213
|
+
# s.capitalize # => "Hello world!"
|
1214
|
+
#
|
1215
|
+
# The casing may be affected by the given `options`; see [Case
|
1216
|
+
# Mapping](rdoc-ref:case_mapping.rdoc).
|
1217
|
+
#
|
1218
|
+
# Related: String#capitalize!.
|
1219
|
+
#
|
1220
|
+
def capitalize: () -> String
|
1221
|
+
| (:ascii | :lithuanian | :turkic) -> String
|
1222
|
+
| (:lithuanian, :turkic) -> String
|
1223
|
+
| (:turkic, :lithuanian) -> String
|
1224
|
+
|
1225
|
+
# <!--
|
1226
|
+
# rdoc-file=string.c
|
1227
|
+
# - capitalize!(*options) -> self or nil
|
1228
|
+
# -->
|
1229
|
+
# Upcases the first character in `self`; downcases the remaining characters;
|
1230
|
+
# returns `self` if any changes were made, `nil` otherwise:
|
1231
|
+
#
|
1232
|
+
# s = 'hello World!' # => "hello World!"
|
1233
|
+
# s.capitalize! # => "Hello world!"
|
1234
|
+
# s # => "Hello world!"
|
1235
|
+
# s.capitalize! # => nil
|
1236
|
+
#
|
1237
|
+
# The casing may be affected by the given `options`; see [Case
|
1238
|
+
# Mapping](rdoc-ref:case_mapping.rdoc).
|
1239
|
+
#
|
1240
|
+
# Related: String#capitalize.
|
1241
|
+
#
|
1242
|
+
def capitalize!: () -> self?
|
1243
|
+
| (:ascii | :lithuanian | :turkic) -> self?
|
1244
|
+
| (:lithuanian, :turkic) -> self?
|
1245
|
+
| (:turkic, :lithuanian) -> self?
|
1246
|
+
|
1247
|
+
# <!--
|
1248
|
+
# rdoc-file=string.c
|
1249
|
+
# - casecmp(other_string) -> -1, 0, 1, or nil
|
1250
|
+
# -->
|
1251
|
+
# Compares `self.downcase` and `other_string.downcase`; returns:
|
1252
|
+
#
|
1253
|
+
# * -1 if `other_string.downcase` is larger.
|
1254
|
+
# * 0 if the two are equal.
|
1255
|
+
# * 1 if `other_string.downcase` is smaller.
|
1256
|
+
# * `nil` if the two are incomparable.
|
1257
|
+
#
|
1258
|
+
# Examples:
|
1259
|
+
#
|
1260
|
+
# 'foo'.casecmp('foo') # => 0
|
1261
|
+
# 'foo'.casecmp('food') # => -1
|
1262
|
+
# 'food'.casecmp('foo') # => 1
|
1263
|
+
# 'FOO'.casecmp('foo') # => 0
|
1264
|
+
# 'foo'.casecmp('FOO') # => 0
|
1265
|
+
# 'foo'.casecmp(1) # => nil
|
1266
|
+
#
|
1267
|
+
# See [Case Mapping](rdoc-ref:case_mapping.rdoc).
|
1268
|
+
#
|
1269
|
+
# Related: String#casecmp?.
|
1270
|
+
#
|
1271
|
+
def casecmp: (string other) -> (-1 | 0 | 1)
|
1272
|
+
| (untyped) -> (-1 | 0 | 1)?
|
1273
|
+
|
1274
|
+
# <!--
|
1275
|
+
# rdoc-file=string.c
|
1276
|
+
# - casecmp?(other_string) -> true, false, or nil
|
1277
|
+
# -->
|
1278
|
+
# Returns `true` if `self` and `other_string` are equal after Unicode case
|
1279
|
+
# folding, otherwise `false`:
|
1280
|
+
#
|
1281
|
+
# 'foo'.casecmp?('foo') # => true
|
1282
|
+
# 'foo'.casecmp?('food') # => false
|
1283
|
+
# 'food'.casecmp?('foo') # => false
|
1284
|
+
# 'FOO'.casecmp?('foo') # => true
|
1285
|
+
# 'foo'.casecmp?('FOO') # => true
|
1286
|
+
#
|
1287
|
+
# Returns `nil` if the two values are incomparable:
|
1288
|
+
#
|
1289
|
+
# 'foo'.casecmp?(1) # => nil
|
1290
|
+
#
|
1291
|
+
# See [Case Mapping](rdoc-ref:case_mapping.rdoc).
|
1292
|
+
#
|
1293
|
+
# Related: String#casecmp.
|
1294
|
+
#
|
1295
|
+
def casecmp?: (string other) -> bool
|
1296
|
+
| (untyped) -> bool?
|
1297
|
+
|
1298
|
+
# <!--
|
1299
|
+
# rdoc-file=string.c
|
1300
|
+
# - center(size, pad_string = ' ') -> new_string
|
1301
|
+
# -->
|
1302
|
+
# Returns a centered copy of `self`.
|
1303
|
+
#
|
1304
|
+
# If integer argument `size` is greater than the size (in characters) of `self`,
|
1305
|
+
# returns a new string of length `size` that is a copy of `self`, centered and
|
1306
|
+
# padded on both ends with `pad_string`:
|
1307
|
+
#
|
1308
|
+
# 'hello'.center(10) # => " hello "
|
1309
|
+
# ' hello'.center(10) # => " hello "
|
1310
|
+
# 'hello'.center(10, 'ab') # => "abhelloaba"
|
1311
|
+
# 'тест'.center(10) # => " тест "
|
1312
|
+
# 'こんにちは'.center(10) # => " こんにちは "
|
1313
|
+
#
|
1314
|
+
# If `size` is not greater than the size of `self`, returns a copy of `self`:
|
1315
|
+
#
|
1316
|
+
# 'hello'.center(5) # => "hello"
|
1317
|
+
# 'hello'.center(1) # => "hello"
|
1318
|
+
#
|
1319
|
+
# Related: String#ljust, String#rjust.
|
1320
|
+
#
|
1321
|
+
def center: (int width, ?string pad_string) -> String
|
1322
|
+
|
1323
|
+
# <!--
|
1324
|
+
# rdoc-file=string.c
|
1325
|
+
# - chars -> array_of_characters
|
1326
|
+
# -->
|
1327
|
+
# Returns an array of the characters in `self`:
|
1328
|
+
#
|
1329
|
+
# 'hello'.chars # => ["h", "e", "l", "l", "o"]
|
1330
|
+
# 'тест'.chars # => ["т", "е", "с", "т"]
|
1331
|
+
# 'こんにちは'.chars # => ["こ", "ん", "に", "ち", "は"]
|
1332
|
+
#
|
1333
|
+
def chars: () -> Array[String]
|
1334
|
+
| () { (String char) -> void } -> self
|
1335
|
+
|
1336
|
+
# <!--
|
1337
|
+
# rdoc-file=string.c
|
1338
|
+
# - chomp(line_sep = $/) -> new_string
|
1339
|
+
# -->
|
1340
|
+
# Returns a new string copied from `self`, with trailing characters possibly
|
1341
|
+
# removed:
|
1342
|
+
#
|
1343
|
+
# When `line_sep` is `"\n"`, removes the last one or two characters if they are
|
1344
|
+
# `"\r"`, `"\n"`, or `"\r\n"` (but not `"\n\r"`):
|
1345
|
+
#
|
1346
|
+
# $/ # => "\n"
|
1347
|
+
# "abc\r".chomp # => "abc"
|
1348
|
+
# "abc\n".chomp # => "abc"
|
1349
|
+
# "abc\r\n".chomp # => "abc"
|
1350
|
+
# "abc\n\r".chomp # => "abc\n"
|
1351
|
+
# "тест\r\n".chomp # => "тест"
|
1352
|
+
# "こんにちは\r\n".chomp # => "こんにちは"
|
1353
|
+
#
|
1354
|
+
# When `line_sep` is `''` (an empty string), removes multiple trailing
|
1355
|
+
# occurrences of `"\n"` or `"\r\n"` (but not `"\r"` or `"\n\r"`):
|
1356
|
+
#
|
1357
|
+
# "abc\n\n\n".chomp('') # => "abc"
|
1358
|
+
# "abc\r\n\r\n\r\n".chomp('') # => "abc"
|
1359
|
+
# "abc\n\n\r\n\r\n\n\n".chomp('') # => "abc"
|
1360
|
+
# "abc\n\r\n\r\n\r".chomp('') # => "abc\n\r\n\r\n\r"
|
1361
|
+
# "abc\r\r\r".chomp('') # => "abc\r\r\r"
|
1362
|
+
#
|
1363
|
+
# When `line_sep` is neither `"\n"` nor `''`, removes a single trailing line
|
1364
|
+
# separator if there is one:
|
1365
|
+
#
|
1366
|
+
# 'abcd'.chomp('d') # => "abc"
|
1367
|
+
# 'abcdd'.chomp('d') # => "abcd"
|
1368
|
+
#
|
1369
|
+
def chomp: (?string? separator) -> String
|
1370
|
+
|
1371
|
+
# <!--
|
1372
|
+
# rdoc-file=string.c
|
1373
|
+
# - chomp!(line_sep = $/) -> self or nil
|
1374
|
+
# -->
|
1375
|
+
# Like String#chomp, but modifies `self` in place; returns `nil` if no
|
1376
|
+
# modification made, `self` otherwise.
|
1377
|
+
#
|
1378
|
+
def chomp!: (nil) -> nil
|
1379
|
+
# | (?string separator) -> self? # https://github.com/ruby/rbs/pull/1672#discussion_r1423324796
|
1380
|
+
| (?string? separator) -> self?
|
1381
|
+
|
1382
|
+
# <!--
|
1383
|
+
# rdoc-file=string.c
|
1384
|
+
# - chop -> new_string
|
1385
|
+
# -->
|
1386
|
+
# Returns a new string copied from `self`, with trailing characters possibly
|
1387
|
+
# removed.
|
1388
|
+
#
|
1389
|
+
# Removes `"\r\n"` if those are the last two characters.
|
1390
|
+
#
|
1391
|
+
# "abc\r\n".chop # => "abc"
|
1392
|
+
# "тест\r\n".chop # => "тест"
|
1393
|
+
# "こんにちは\r\n".chop # => "こんにちは"
|
1394
|
+
#
|
1395
|
+
# Otherwise removes the last character if it exists.
|
1396
|
+
#
|
1397
|
+
# 'abcd'.chop # => "abc"
|
1398
|
+
# 'тест'.chop # => "тес"
|
1399
|
+
# 'こんにちは'.chop # => "こんにち"
|
1400
|
+
# ''.chop # => ""
|
1401
|
+
#
|
1402
|
+
# If you only need to remove the newline separator at the end of the string,
|
1403
|
+
# String#chomp is a better alternative.
|
1404
|
+
#
|
1405
|
+
def chop: () -> String
|
1406
|
+
|
1407
|
+
# <!--
|
1408
|
+
# rdoc-file=string.c
|
1409
|
+
# - chop! -> self or nil
|
1410
|
+
# -->
|
1411
|
+
# Like String#chop, but modifies `self` in place; returns `nil` if `self` is
|
1412
|
+
# empty, `self` otherwise.
|
1413
|
+
#
|
1414
|
+
# Related: String#chomp!.
|
1415
|
+
#
|
1416
|
+
def chop!: () -> self?
|
1417
|
+
|
1418
|
+
# <!--
|
1419
|
+
# rdoc-file=string.c
|
1420
|
+
# - chr -> string
|
1421
|
+
# -->
|
1422
|
+
# Returns a string containing the first character of `self`:
|
1423
|
+
#
|
1424
|
+
# s = 'foo' # => "foo"
|
1425
|
+
# s.chr # => "f"
|
1426
|
+
#
|
1427
|
+
def chr: () -> String
|
1428
|
+
|
1429
|
+
# <!--
|
1430
|
+
# rdoc-file=string.c
|
1431
|
+
# - clear -> self
|
1432
|
+
# -->
|
1433
|
+
# Removes the contents of `self`:
|
1434
|
+
#
|
1435
|
+
# s = 'foo' # => "foo"
|
1436
|
+
# s.clear # => ""
|
1437
|
+
#
|
1438
|
+
def clear: () -> self
|
1439
|
+
|
1440
|
+
# <!--
|
1441
|
+
# rdoc-file=string.c
|
1442
|
+
# - codepoints -> array_of_integers
|
1443
|
+
# -->
|
1444
|
+
# Returns an array of the codepoints in `self`; each codepoint is the integer
|
1445
|
+
# value for a character:
|
1446
|
+
#
|
1447
|
+
# 'hello'.codepoints # => [104, 101, 108, 108, 111]
|
1448
|
+
# 'тест'.codepoints # => [1090, 1077, 1089, 1090]
|
1449
|
+
# 'こんにちは'.codepoints # => [12371, 12435, 12395, 12385, 12399]
|
1450
|
+
#
|
1451
|
+
def codepoints: () -> Array[Integer]
|
1452
|
+
| () { (Integer codepoint) -> void } -> self
|
1453
|
+
|
1454
|
+
# <!--
|
1455
|
+
# rdoc-file=string.c
|
1456
|
+
# - concat(*objects) -> string
|
1457
|
+
# -->
|
1458
|
+
# Concatenates each object in `objects` to `self` and returns `self`:
|
1459
|
+
#
|
1460
|
+
# s = 'foo'
|
1461
|
+
# s.concat('bar', 'baz') # => "foobarbaz"
|
1462
|
+
# s # => "foobarbaz"
|
1463
|
+
#
|
1464
|
+
# For each given object `object` that is an Integer, the value is considered a
|
1465
|
+
# codepoint and converted to a character before concatenation:
|
1466
|
+
#
|
1467
|
+
# s = 'foo'
|
1468
|
+
# s.concat(32, 'bar', 32, 'baz') # => "foo bar baz"
|
1469
|
+
#
|
1470
|
+
# Related: String#<<, which takes a single argument.
|
1471
|
+
#
|
1472
|
+
def concat: (*string | Integer string_or_codepoints) -> self
|
1473
|
+
|
1474
|
+
# <!--
|
1475
|
+
# rdoc-file=string.c
|
1476
|
+
# - count(*selectors) -> integer
|
1477
|
+
# -->
|
1478
|
+
# Returns the total number of characters in `self` that are specified by the
|
1479
|
+
# given `selectors` (see [Multiple Character
|
1480
|
+
# Selectors](rdoc-ref:character_selectors.rdoc@Multiple+Character+Selectors)):
|
1481
|
+
#
|
1482
|
+
# a = "hello world"
|
1483
|
+
# a.count "lo" #=> 5
|
1484
|
+
# a.count "lo", "o" #=> 2
|
1485
|
+
# a.count "hello", "^l" #=> 4
|
1486
|
+
# a.count "ej-m" #=> 4
|
1487
|
+
#
|
1488
|
+
# "hello^world".count "\\^aeiou" #=> 4
|
1489
|
+
# "hello-world".count "a\\-eo" #=> 4
|
1490
|
+
#
|
1491
|
+
# c = "hello world\\r\\n"
|
1492
|
+
# c.count "\\" #=> 2
|
1493
|
+
# c.count "\\A" #=> 0
|
1494
|
+
# c.count "X-\\w" #=> 3
|
1495
|
+
#
|
1496
|
+
def count: (selector selector_0, *selector more_selectors) -> Integer
|
1497
|
+
|
1498
|
+
# <!--
|
1499
|
+
# rdoc-file=string.c
|
1500
|
+
# - crypt(salt_str) -> new_string
|
1501
|
+
# -->
|
1502
|
+
# Returns the string generated by calling `crypt(3)` standard library function
|
1503
|
+
# with `str` and `salt_str`, in this order, as its arguments. Please do not use
|
1504
|
+
# this method any longer. It is legacy; provided only for backward
|
1505
|
+
# compatibility with ruby scripts in earlier days. It is bad to use in
|
1506
|
+
# contemporary programs for several reasons:
|
1507
|
+
#
|
1508
|
+
# * Behaviour of C's `crypt(3)` depends on the OS it is run. The generated
|
1509
|
+
# string lacks data portability.
|
1510
|
+
#
|
1511
|
+
# * On some OSes such as Mac OS, `crypt(3)` never fails (i.e. silently ends up
|
1512
|
+
# in unexpected results).
|
1513
|
+
#
|
1514
|
+
# * On some OSes such as Mac OS, `crypt(3)` is not thread safe.
|
1515
|
+
#
|
1516
|
+
# * So-called "traditional" usage of `crypt(3)` is very very very weak.
|
1517
|
+
# According to its manpage, Linux's traditional `crypt(3)` output has only
|
1518
|
+
# 2**56 variations; too easy to brute force today. And this is the default
|
1519
|
+
# behaviour.
|
1520
|
+
#
|
1521
|
+
# * In order to make things robust some OSes implement so-called "modular"
|
1522
|
+
# usage. To go through, you have to do a complex build-up of the `salt_str`
|
1523
|
+
# parameter, by hand. Failure in generation of a proper salt string tends
|
1524
|
+
# not to yield any errors; typos in parameters are normally not detectable.
|
1525
|
+
#
|
1526
|
+
# * For instance, in the following example, the second invocation of
|
1527
|
+
# String#crypt is wrong; it has a typo in "round=" (lacks "s"). However
|
1528
|
+
# the call does not fail and something unexpected is generated.
|
1529
|
+
#
|
1530
|
+
# "foo".crypt("$5$rounds=1000$salt$") # OK, proper usage
|
1531
|
+
# "foo".crypt("$5$round=1000$salt$") # Typo not detected
|
1532
|
+
#
|
1533
|
+
# * Even in the "modular" mode, some hash functions are considered archaic and
|
1534
|
+
# no longer recommended at all; for instance module `$1$` is officially
|
1535
|
+
# abandoned by its author: see http://phk.freebsd.dk/sagas/md5crypt_eol/ .
|
1536
|
+
# For another instance module `$3$` is considered completely broken: see the
|
1537
|
+
# manpage of FreeBSD.
|
1538
|
+
#
|
1539
|
+
# * On some OS such as Mac OS, there is no modular mode. Yet, as written
|
1540
|
+
# above, `crypt(3)` on Mac OS never fails. This means even if you build up a
|
1541
|
+
# proper salt string it generates a traditional DES hash anyways, and there
|
1542
|
+
# is no way for you to be aware of.
|
1543
|
+
#
|
1544
|
+
# "foo".crypt("$5$rounds=1000$salt$") # => "$5fNPQMxC5j6."
|
1545
|
+
#
|
1546
|
+
# If for some reason you cannot migrate to other secure contemporary password
|
1547
|
+
# hashing algorithms, install the string-crypt gem and `require 'string/crypt'`
|
1548
|
+
# to continue using it.
|
1549
|
+
#
|
1550
|
+
def crypt: (string salt_str) -> String
|
1551
|
+
|
1552
|
+
# <!-- rdoc-file=string.c -->
|
1553
|
+
# Returns a frozen, possibly pre-existing copy of the string.
|
1554
|
+
#
|
1555
|
+
# The returned `String` will be deduplicated as long as it does not have any
|
1556
|
+
# instance variables set on it and is not a String subclass.
|
1557
|
+
#
|
1558
|
+
# Note that `-string` variant is more convenient for defining constants:
|
1559
|
+
#
|
1560
|
+
# FILENAME = -'config/database.yml'
|
1561
|
+
#
|
1562
|
+
# while `dedup` is better suitable for using the method in chains of
|
1563
|
+
# calculations:
|
1564
|
+
#
|
1565
|
+
# @url_list.concat(urls.map(&:dedup))
|
1566
|
+
#
|
1567
|
+
alias dedup -@
|
1568
|
+
|
1569
|
+
# <!--
|
1570
|
+
# rdoc-file=string.c
|
1571
|
+
# - delete(*selectors) -> new_string
|
1572
|
+
# -->
|
1573
|
+
# Returns a copy of `self` with characters specified by `selectors` removed (see
|
1574
|
+
# [Multiple Character
|
1575
|
+
# Selectors](rdoc-ref:character_selectors.rdoc@Multiple+Character+Selectors)):
|
1576
|
+
#
|
1577
|
+
# "hello".delete "l","lo" #=> "heo"
|
1578
|
+
# "hello".delete "lo" #=> "he"
|
1579
|
+
# "hello".delete "aeiou", "^e" #=> "hell"
|
1580
|
+
# "hello".delete "ej-m" #=> "ho"
|
1581
|
+
#
|
1582
|
+
def delete: (selector selector_0, *selector more_selectors) -> String
|
1583
|
+
|
1584
|
+
# <!--
|
1585
|
+
# rdoc-file=string.c
|
1586
|
+
# - delete!(*selectors) -> self or nil
|
1587
|
+
# -->
|
1588
|
+
# Like String#delete, but modifies `self` in place. Returns `self` if any
|
1589
|
+
# changes were made, `nil` otherwise.
|
1590
|
+
#
|
1591
|
+
def delete!: (selector selector_0, *selector more_selectors) -> self?
|
1592
|
+
|
1593
|
+
# <!--
|
1594
|
+
# rdoc-file=string.c
|
1595
|
+
# - delete_prefix(prefix) -> new_string
|
1596
|
+
# -->
|
1597
|
+
# Returns a copy of `self` with leading substring `prefix` removed:
|
1598
|
+
#
|
1599
|
+
# 'hello'.delete_prefix('hel') # => "lo"
|
1600
|
+
# 'hello'.delete_prefix('llo') # => "hello"
|
1601
|
+
# 'тест'.delete_prefix('те') # => "ст"
|
1602
|
+
# 'こんにちは'.delete_prefix('こん') # => "にちは"
|
1603
|
+
#
|
1604
|
+
# Related: String#delete_prefix!, String#delete_suffix.
|
1605
|
+
#
|
1606
|
+
def delete_prefix: (string prefix) -> String
|
1607
|
+
|
1608
|
+
# <!--
|
1609
|
+
# rdoc-file=string.c
|
1610
|
+
# - delete_prefix!(prefix) -> self or nil
|
1611
|
+
# -->
|
1612
|
+
# Like String#delete_prefix, except that `self` is modified in place. Returns
|
1613
|
+
# `self` if the prefix is removed, `nil` otherwise.
|
1614
|
+
#
|
1615
|
+
def delete_prefix!: (string prefix) -> self?
|
1616
|
+
|
1617
|
+
# <!--
|
1618
|
+
# rdoc-file=string.c
|
1619
|
+
# - delete_suffix(suffix) -> new_string
|
1620
|
+
# -->
|
1621
|
+
# Returns a copy of `self` with trailing substring `suffix` removed:
|
1622
|
+
#
|
1623
|
+
# 'hello'.delete_suffix('llo') # => "he"
|
1624
|
+
# 'hello'.delete_suffix('hel') # => "hello"
|
1625
|
+
# 'тест'.delete_suffix('ст') # => "те"
|
1626
|
+
# 'こんにちは'.delete_suffix('ちは') # => "こんに"
|
1627
|
+
#
|
1628
|
+
# Related: String#delete_suffix!, String#delete_prefix.
|
1629
|
+
#
|
1630
|
+
def delete_suffix: (string suffix) -> String
|
1631
|
+
|
1632
|
+
# <!--
|
1633
|
+
# rdoc-file=string.c
|
1634
|
+
# - delete_suffix!(suffix) -> self or nil
|
1635
|
+
# -->
|
1636
|
+
# Like String#delete_suffix, except that `self` is modified in place. Returns
|
1637
|
+
# `self` if the suffix is removed, `nil` otherwise.
|
1638
|
+
#
|
1639
|
+
def delete_suffix!: (string suffix) -> self?
|
1640
|
+
|
1641
|
+
# <!--
|
1642
|
+
# rdoc-file=string.c
|
1643
|
+
# - downcase(*options) -> string
|
1644
|
+
# -->
|
1645
|
+
# Returns a string containing the downcased characters in `self`:
|
1646
|
+
#
|
1647
|
+
# s = 'Hello World!' # => "Hello World!"
|
1648
|
+
# s.downcase # => "hello world!"
|
1649
|
+
#
|
1650
|
+
# The casing may be affected by the given `options`; see [Case
|
1651
|
+
# Mapping](rdoc-ref:case_mapping.rdoc).
|
1652
|
+
#
|
1653
|
+
# Related: String#downcase!, String#upcase, String#upcase!.
|
1654
|
+
#
|
1655
|
+
def downcase: () -> String
|
1656
|
+
| (:ascii | :fold | :lithuanian | :turkic) -> String
|
1657
|
+
| (:lithuanian, :turkic) -> String
|
1658
|
+
| (:turkic, :lithuanian) -> String
|
1659
|
+
|
1660
|
+
# <!--
|
1661
|
+
# rdoc-file=string.c
|
1662
|
+
# - downcase!(*options) -> self or nil
|
1663
|
+
# -->
|
1664
|
+
# Downcases the characters in `self`; returns `self` if any changes were made,
|
1665
|
+
# `nil` otherwise:
|
1666
|
+
#
|
1667
|
+
# s = 'Hello World!' # => "Hello World!"
|
1668
|
+
# s.downcase! # => "hello world!"
|
1669
|
+
# s # => "hello world!"
|
1670
|
+
# s.downcase! # => nil
|
1671
|
+
#
|
1672
|
+
# The casing may be affected by the given `options`; see [Case
|
1673
|
+
# Mapping](rdoc-ref:case_mapping.rdoc).
|
1674
|
+
#
|
1675
|
+
# Related: String#downcase, String#upcase, String#upcase!.
|
1676
|
+
#
|
1677
|
+
def downcase!: () -> self?
|
1678
|
+
| (:ascii | :fold | :lithuanian | :turkic) -> self?
|
1679
|
+
| (:lithuanian, :turkic) -> self?
|
1680
|
+
| (:turkic, :lithuanian) -> self?
|
1681
|
+
|
1682
|
+
# <!--
|
1683
|
+
# rdoc-file=string.c
|
1684
|
+
# - dump -> string
|
1685
|
+
# -->
|
1686
|
+
# Returns a printable version of `self`, enclosed in double-quotes, with special
|
1687
|
+
# characters escaped, and with non-printing characters replaced by hexadecimal
|
1688
|
+
# notation:
|
1689
|
+
#
|
1690
|
+
# "hello \n ''".dump # => "\"hello \\n ''\""
|
1691
|
+
# "\f\x00\xff\\\"".dump # => "\"\\f\\x00\\xFF\\\\\\\"\""
|
1692
|
+
#
|
1693
|
+
# Related: String#undump (inverse of String#dump).
|
1694
|
+
#
|
1695
|
+
def dump: () -> String
|
1696
|
+
|
1697
|
+
# <!--
|
1698
|
+
# rdoc-file=string.c
|
1699
|
+
# - each_byte {|byte| ... } -> self
|
1700
|
+
# - each_byte -> enumerator
|
1701
|
+
# -->
|
1702
|
+
# Calls the given block with each successive byte from `self`; returns `self`:
|
1703
|
+
#
|
1704
|
+
# 'hello'.each_byte {|byte| print byte, ' ' }
|
1705
|
+
# print "\n"
|
1706
|
+
# 'тест'.each_byte {|byte| print byte, ' ' }
|
1707
|
+
# print "\n"
|
1708
|
+
# 'こんにちは'.each_byte {|byte| print byte, ' ' }
|
1709
|
+
# print "\n"
|
1710
|
+
#
|
1711
|
+
# Output:
|
1712
|
+
#
|
1713
|
+
# 104 101 108 108 111
|
1714
|
+
# 209 130 208 181 209 129 209 130
|
1715
|
+
# 227 129 147 227 130 147 227 129 171 227 129 161 227 129 175
|
1716
|
+
#
|
1717
|
+
# Returns an enumerator if no block is given.
|
1718
|
+
#
|
1719
|
+
def each_byte: () -> Enumerator[Integer, self]
|
1720
|
+
| () { (Integer byte) -> void } -> self
|
1721
|
+
|
1722
|
+
# <!--
|
1723
|
+
# rdoc-file=string.c
|
1724
|
+
# - each_char {|c| ... } -> self
|
1725
|
+
# - each_char -> enumerator
|
1726
|
+
# -->
|
1727
|
+
# Calls the given block with each successive character from `self`; returns
|
1728
|
+
# `self`:
|
1729
|
+
#
|
1730
|
+
# 'hello'.each_char {|char| print char, ' ' }
|
1731
|
+
# print "\n"
|
1732
|
+
# 'тест'.each_char {|char| print char, ' ' }
|
1733
|
+
# print "\n"
|
1734
|
+
# 'こんにちは'.each_char {|char| print char, ' ' }
|
1735
|
+
# print "\n"
|
1736
|
+
#
|
1737
|
+
# Output:
|
1738
|
+
#
|
1739
|
+
# h e l l o
|
1740
|
+
# т е с т
|
1741
|
+
# こ ん に ち は
|
1742
|
+
#
|
1743
|
+
# Returns an enumerator if no block is given.
|
1744
|
+
#
|
1745
|
+
def each_char: () -> Enumerator[String, self]
|
1746
|
+
| () { (String char) -> void } -> self
|
1747
|
+
|
1748
|
+
# <!--
|
1749
|
+
# rdoc-file=string.c
|
1750
|
+
# - each_codepoint {|integer| ... } -> self
|
1751
|
+
# - each_codepoint -> enumerator
|
1752
|
+
# -->
|
1753
|
+
# Calls the given block with each successive codepoint from `self`; each
|
1754
|
+
# codepoint is the integer value for a character; returns `self`:
|
1755
|
+
#
|
1756
|
+
# 'hello'.each_codepoint {|codepoint| print codepoint, ' ' }
|
1757
|
+
# print "\n"
|
1758
|
+
# 'тест'.each_codepoint {|codepoint| print codepoint, ' ' }
|
1759
|
+
# print "\n"
|
1760
|
+
# 'こんにちは'.each_codepoint {|codepoint| print codepoint, ' ' }
|
1761
|
+
# print "\n"
|
1762
|
+
#
|
1763
|
+
# Output:
|
1764
|
+
#
|
1765
|
+
# 104 101 108 108 111
|
1766
|
+
# 1090 1077 1089 1090
|
1767
|
+
# 12371 12435 12395 12385 12399
|
1768
|
+
#
|
1769
|
+
# Returns an enumerator if no block is given.
|
1770
|
+
#
|
1771
|
+
def each_codepoint: () -> Enumerator[Integer, self]
|
1772
|
+
| () { (Integer codepoint) -> void } -> self
|
1773
|
+
|
1774
|
+
# <!--
|
1775
|
+
# rdoc-file=string.c
|
1776
|
+
# - each_grapheme_cluster {|gc| ... } -> self
|
1777
|
+
# - each_grapheme_cluster -> enumerator
|
1778
|
+
# -->
|
1779
|
+
# Calls the given block with each successive grapheme cluster from `self` (see
|
1780
|
+
# [Unicode Grapheme Cluster
|
1781
|
+
# Boundaries](https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries)
|
1782
|
+
# ); returns `self`:
|
1783
|
+
#
|
1784
|
+
# s = "\u0061\u0308-pqr-\u0062\u0308-xyz-\u0063\u0308" # => "ä-pqr-b̈-xyz-c̈"
|
1785
|
+
# s.each_grapheme_cluster {|gc| print gc, ' ' }
|
1786
|
+
#
|
1787
|
+
# Output:
|
1788
|
+
#
|
1789
|
+
# ä - p q r - b̈ - x y z - c̈
|
1790
|
+
#
|
1791
|
+
# Returns an enumerator if no block is given.
|
1792
|
+
#
|
1793
|
+
def each_grapheme_cluster: () -> Enumerator[String, self]
|
1794
|
+
| () { (String grapheme_cluter) -> void } -> self
|
1795
|
+
|
1796
|
+
# <!--
|
1797
|
+
# rdoc-file=string.c
|
1798
|
+
# - each_line(line_sep = $/, chomp: false) {|substring| ... } -> self
|
1799
|
+
# - each_line(line_sep = $/, chomp: false) -> enumerator
|
1800
|
+
# -->
|
1801
|
+
# With a block given, forms the substrings ("lines") that are the result of
|
1802
|
+
# splitting `self` at each occurrence of the given line separator `line_sep`;
|
1803
|
+
# passes each line to the block; returns `self`:
|
1804
|
+
#
|
1805
|
+
# s = <<~EOT
|
1806
|
+
# This is the first line.
|
1807
|
+
# This is line two.
|
1808
|
+
#
|
1809
|
+
# This is line four.
|
1810
|
+
# This is line five.
|
1811
|
+
# EOT
|
1812
|
+
#
|
1813
|
+
# s.each_line {|line| p line }
|
1814
|
+
#
|
1815
|
+
# Output:
|
1816
|
+
#
|
1817
|
+
# "This is the first line.\n"
|
1818
|
+
# "This is line two.\n"
|
1819
|
+
# "\n"
|
1820
|
+
# "This is line four.\n"
|
1821
|
+
# "This is line five.\n"
|
1822
|
+
#
|
1823
|
+
# With a different `line_sep`:
|
1824
|
+
#
|
1825
|
+
# s.each_line(' is ') {|line| p line }
|
1826
|
+
#
|
1827
|
+
# Output:
|
1828
|
+
#
|
1829
|
+
# "This is "
|
1830
|
+
# "the first line.\nThis is "
|
1831
|
+
# "line two.\n\nThis is "
|
1832
|
+
# "line four.\nThis is "
|
1833
|
+
# "line five.\n"
|
1834
|
+
#
|
1835
|
+
# With `chomp` as `true`, removes the trailing `line_sep` from each line:
|
1836
|
+
#
|
1837
|
+
# s.each_line(chomp: true) {|line| p line }
|
1838
|
+
#
|
1839
|
+
# Output:
|
1840
|
+
#
|
1841
|
+
# "This is the first line."
|
1842
|
+
# "This is line two."
|
1843
|
+
# ""
|
1844
|
+
# "This is line four."
|
1845
|
+
# "This is line five."
|
1846
|
+
#
|
1847
|
+
# With an empty string as `line_sep`, forms and passes "paragraphs" by splitting
|
1848
|
+
# at each occurrence of two or more newlines:
|
1849
|
+
#
|
1850
|
+
# s.each_line('') {|line| p line }
|
1851
|
+
#
|
1852
|
+
# Output:
|
1853
|
+
#
|
1854
|
+
# "This is the first line.\nThis is line two.\n\n"
|
1855
|
+
# "This is line four.\nThis is line five.\n"
|
1856
|
+
#
|
1857
|
+
# With no block given, returns an enumerator.
|
1858
|
+
#
|
1859
|
+
def each_line: (?string? separator, ?chomp: boolish) -> Enumerator[String, self]
|
1860
|
+
| (?string? separator, ?chomp: boolish) { (String line) -> void } -> self
|
1861
|
+
|
1862
|
+
# <!--
|
1863
|
+
# rdoc-file=string.c
|
1864
|
+
# - empty? -> true or false
|
1865
|
+
# -->
|
1866
|
+
# Returns `true` if the length of `self` is zero, `false` otherwise:
|
1867
|
+
#
|
1868
|
+
# "hello".empty? # => false
|
1869
|
+
# " ".empty? # => false
|
1870
|
+
# "".empty? # => true
|
1871
|
+
#
|
1872
|
+
def empty?: () -> bool
|
1873
|
+
|
1874
|
+
# <!--
|
1875
|
+
# rdoc-file=transcode.c
|
1876
|
+
# - encode(dst_encoding = Encoding.default_internal, **enc_opts) -> string
|
1877
|
+
# - encode(dst_encoding, src_encoding, **enc_opts) -> string
|
1878
|
+
# -->
|
1879
|
+
# Returns a copy of `self` transcoded as determined by `dst_encoding`. By
|
1880
|
+
# default, raises an exception if `self` contains an invalid byte or a character
|
1881
|
+
# not defined in `dst_encoding`; that behavior may be modified by encoding
|
1882
|
+
# options; see below.
|
1883
|
+
#
|
1884
|
+
# With no arguments:
|
1885
|
+
#
|
1886
|
+
# * Uses the same encoding if `Encoding.default_internal` is `nil` (the
|
1887
|
+
# default):
|
1888
|
+
#
|
1889
|
+
# Encoding.default_internal # => nil
|
1890
|
+
# s = "Ruby\x99".force_encoding('Windows-1252')
|
1891
|
+
# s.encoding # => #<Encoding:Windows-1252>
|
1892
|
+
# s.bytes # => [82, 117, 98, 121, 153]
|
1893
|
+
# t = s.encode # => "Ruby\x99"
|
1894
|
+
# t.encoding # => #<Encoding:Windows-1252>
|
1895
|
+
# t.bytes # => [82, 117, 98, 121, 226, 132, 162]
|
1896
|
+
#
|
1897
|
+
# * Otherwise, uses the encoding `Encoding.default_internal`:
|
1898
|
+
#
|
1899
|
+
# Encoding.default_internal = 'UTF-8'
|
1900
|
+
# t = s.encode # => "Ruby™"
|
1901
|
+
# t.encoding # => #<Encoding:UTF-8>
|
1902
|
+
#
|
1903
|
+
# With only argument `dst_encoding` given, uses that encoding:
|
1904
|
+
#
|
1905
|
+
# s = "Ruby\x99".force_encoding('Windows-1252')
|
1906
|
+
# s.encoding # => #<Encoding:Windows-1252>
|
1907
|
+
# t = s.encode('UTF-8') # => "Ruby™"
|
1908
|
+
# t.encoding # => #<Encoding:UTF-8>
|
1909
|
+
#
|
1910
|
+
# With arguments `dst_encoding` and `src_encoding` given, interprets `self`
|
1911
|
+
# using `src_encoding`, encodes the new string using `dst_encoding`:
|
1912
|
+
#
|
1913
|
+
# s = "Ruby\x99"
|
1914
|
+
# t = s.encode('UTF-8', 'Windows-1252') # => "Ruby™"
|
1915
|
+
# t.encoding # => #<Encoding:UTF-8>
|
1916
|
+
#
|
1917
|
+
# Optional keyword arguments `enc_opts` specify encoding options; see [Encoding
|
1918
|
+
# Options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
1919
|
+
#
|
1920
|
+
# Please note that, unless `invalid: :replace` option is given, conversion from
|
1921
|
+
# an encoding `enc` to the same encoding `enc` (independent of whether `enc` is
|
1922
|
+
# given explicitly or implicitly) is a no-op, i.e. the string is simply copied
|
1923
|
+
# without any changes, and no exceptions are raised, even if there are invalid
|
1924
|
+
# bytes.
|
1925
|
+
#
|
1926
|
+
def encode: (
|
1927
|
+
?encoding source_encoding,
|
1928
|
+
?encoding? from_encoding,
|
1929
|
+
?invalid: :replace ?,
|
1930
|
+
?undef: :replace ?,
|
1931
|
+
?replace: string?,
|
1932
|
+
?xml: (:text | :attr)?,
|
1933
|
+
?newline: (:universal | :crlf | :cr | :lf)?,
|
1934
|
+
?universal_newline: boolish,
|
1935
|
+
?cr_newline: boolish,
|
1936
|
+
?crlf_newline: boolish,
|
1937
|
+
?lf_newline: boolish,
|
1938
|
+
?fallback: ^(String) -> string? | Method | _EncodeFallbackAref
|
1939
|
+
) -> instance
|
1940
|
+
|
1941
|
+
interface _EncodeFallbackAref
|
1942
|
+
def []: (String) -> string?
|
1943
|
+
end
|
1944
|
+
|
1945
|
+
# <!--
|
1946
|
+
# rdoc-file=transcode.c
|
1947
|
+
# - encode!(dst_encoding = Encoding.default_internal, **enc_opts) -> self
|
1948
|
+
# - encode!(dst_encoding, src_encoding, **enc_opts) -> self
|
1949
|
+
# -->
|
1950
|
+
# Like #encode, but applies encoding changes to `self`; returns `self`.
|
1951
|
+
#
|
1952
|
+
def encode!: (
|
1953
|
+
?encoding source_encoding,
|
1954
|
+
?encoding? from_encoding,
|
1955
|
+
?invalid: :replace ?,
|
1956
|
+
?undef: :replace ?,
|
1957
|
+
?replace: string?,
|
1958
|
+
?xml: (:text | :attr)?,
|
1959
|
+
?newline: (:universal | :crlf | :cr | :lf)?,
|
1960
|
+
?universal_newline: boolish,
|
1961
|
+
?cr_newline: boolish,
|
1962
|
+
?crlf_newline: boolish,
|
1963
|
+
?lf_newline: boolish,
|
1964
|
+
?fallback: ^(String) -> string? | Method | _EncodeFallbackAref
|
1965
|
+
) -> self
|
1966
|
+
|
1967
|
+
# <!--
|
1968
|
+
# rdoc-file=string.c
|
1969
|
+
# - obj.encoding -> encoding
|
1970
|
+
# -->
|
1971
|
+
# Returns the Encoding object that represents the encoding of obj.
|
1972
|
+
#
|
1973
|
+
def encoding: () -> Encoding
|
1974
|
+
|
1975
|
+
# <!--
|
1976
|
+
# rdoc-file=string.c
|
1977
|
+
# - end_with?(*strings) -> true or false
|
1978
|
+
# -->
|
1979
|
+
# Returns whether `self` ends with any of the given `strings`.
|
1980
|
+
#
|
1981
|
+
# Returns `true` if any given string matches the end, `false` otherwise:
|
1982
|
+
#
|
1983
|
+
# 'hello'.end_with?('ello') #=> true
|
1984
|
+
# 'hello'.end_with?('heaven', 'ello') #=> true
|
1985
|
+
# 'hello'.end_with?('heaven', 'paradise') #=> false
|
1986
|
+
# 'тест'.end_with?('т') # => true
|
1987
|
+
# 'こんにちは'.end_with?('は') # => true
|
1988
|
+
#
|
1989
|
+
# Related: String#start_with?.
|
1990
|
+
#
|
1991
|
+
def end_with?: (*string suffixes) -> bool
|
1992
|
+
|
1993
|
+
# <!--
|
1994
|
+
# rdoc-file=string.c
|
1995
|
+
# - eql?(object) -> true or false
|
1996
|
+
# -->
|
1997
|
+
# Returns `true` if `object` has the same length and content; as `self`; `false`
|
1998
|
+
# otherwise:
|
1999
|
+
#
|
2000
|
+
# s = 'foo'
|
2001
|
+
# s.eql?('foo') # => true
|
2002
|
+
# s.eql?('food') # => false
|
2003
|
+
# s.eql?('FOO') # => false
|
2004
|
+
#
|
2005
|
+
# Returns `false` if the two strings' encodings are not compatible:
|
2006
|
+
#
|
2007
|
+
# "\u{e4 f6 fc}".encode("ISO-8859-1").eql?("\u{c4 d6 dc}") # => false
|
2008
|
+
#
|
2009
|
+
def eql?: (untyped other) -> bool
|
2010
|
+
|
2011
|
+
# <!--
|
2012
|
+
# rdoc-file=string.c
|
2013
|
+
# - force_encoding(encoding) -> self
|
2014
|
+
# -->
|
2015
|
+
# Changes the encoding of `self` to `encoding`, which may be a string encoding
|
2016
|
+
# name or an Encoding object; returns self:
|
2017
|
+
#
|
2018
|
+
# s = 'łał'
|
2019
|
+
# s.bytes # => [197, 130, 97, 197, 130]
|
2020
|
+
# s.encoding # => #<Encoding:UTF-8>
|
2021
|
+
# s.force_encoding('ascii') # => "\xC5\x82a\xC5\x82"
|
2022
|
+
# s.encoding # => #<Encoding:US-ASCII>
|
2023
|
+
#
|
2024
|
+
# Does not change the underlying bytes:
|
2025
|
+
#
|
2026
|
+
# s.bytes # => [197, 130, 97, 197, 130]
|
2027
|
+
#
|
2028
|
+
# Makes the change even if the given `encoding` is invalid for `self` (as is the
|
2029
|
+
# change above):
|
2030
|
+
#
|
2031
|
+
# s.valid_encoding? # => false
|
2032
|
+
# s.force_encoding(Encoding::UTF_8) # => "łał"
|
2033
|
+
# s.valid_encoding? # => true
|
2034
|
+
#
|
2035
|
+
def force_encoding: (encoding enc) -> self
|
2036
|
+
|
2037
|
+
# <!--
|
2038
|
+
# rdoc-file=string.c
|
2039
|
+
# - freeze()
|
2040
|
+
# -->
|
2041
|
+
#
|
2042
|
+
def freeze: () -> self
|
2043
|
+
|
2044
|
+
# <!--
|
2045
|
+
# rdoc-file=string.c
|
2046
|
+
# - getbyte(index) -> integer or nil
|
2047
|
+
# -->
|
2048
|
+
# Returns the byte at zero-based `index` as an integer, or `nil` if `index` is
|
2049
|
+
# out of range:
|
2050
|
+
#
|
2051
|
+
# s = 'abcde' # => "abcde"
|
2052
|
+
# s.getbyte(0) # => 97
|
2053
|
+
# s.getbyte(-1) # => 101
|
2054
|
+
# s.getbyte(5) # => nil
|
2055
|
+
#
|
2056
|
+
# Related: String#setbyte.
|
2057
|
+
#
|
2058
|
+
def getbyte: (int index) -> Integer?
|
2059
|
+
|
2060
|
+
# <!--
|
2061
|
+
# rdoc-file=string.c
|
2062
|
+
# - grapheme_clusters -> array_of_grapheme_clusters
|
2063
|
+
# -->
|
2064
|
+
# Returns an array of the grapheme clusters in `self` (see [Unicode Grapheme
|
2065
|
+
# Cluster
|
2066
|
+
# Boundaries](https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries)
|
2067
|
+
# ):
|
2068
|
+
#
|
2069
|
+
# s = "\u0061\u0308-pqr-\u0062\u0308-xyz-\u0063\u0308" # => "ä-pqr-b̈-xyz-c̈"
|
2070
|
+
# s.grapheme_clusters
|
2071
|
+
# # => ["ä", "-", "p", "q", "r", "-", "b̈", "-", "x", "y", "z", "-", "c̈"]
|
2072
|
+
#
|
2073
|
+
def grapheme_clusters: () -> Array[String]
|
2074
|
+
| () { (String grapheme_cluter) -> void } -> self
|
2075
|
+
|
2076
|
+
# <!--
|
2077
|
+
# rdoc-file=string.c
|
2078
|
+
# - gsub(pattern, replacement) -> new_string
|
2079
|
+
# - gsub(pattern) {|match| ... } -> new_string
|
2080
|
+
# - gsub(pattern) -> enumerator
|
2081
|
+
# -->
|
2082
|
+
# Returns a copy of `self` with all occurrences of the given `pattern` replaced.
|
2083
|
+
#
|
2084
|
+
# See [Substitution Methods](rdoc-ref:String@Substitution+Methods).
|
2085
|
+
#
|
2086
|
+
# Returns an Enumerator if no `replacement` and no block given.
|
2087
|
+
#
|
2088
|
+
# Related: String#sub, String#sub!, String#gsub!.
|
2089
|
+
#
|
2090
|
+
def gsub: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> String
|
2091
|
+
| (Regexp | string pattern) -> Enumerator[String, String]
|
2092
|
+
| (Regexp | string pattern) { (String match) -> _ToS } -> String
|
2093
|
+
|
2094
|
+
# <!--
|
2095
|
+
# rdoc-file=string.c
|
2096
|
+
# - gsub!(pattern, replacement) -> self or nil
|
2097
|
+
# - gsub!(pattern) {|match| ... } -> self or nil
|
2098
|
+
# - gsub!(pattern) -> an_enumerator
|
2099
|
+
# -->
|
2100
|
+
# Performs the specified substring replacement(s) on `self`; returns `self` if
|
2101
|
+
# any replacement occurred, `nil` otherwise.
|
2102
|
+
#
|
2103
|
+
# See [Substitution Methods](rdoc-ref:String@Substitution+Methods).
|
2104
|
+
#
|
2105
|
+
# Returns an Enumerator if no `replacement` and no block given.
|
2106
|
+
#
|
2107
|
+
# Related: String#sub, String#gsub, String#sub!.
|
2108
|
+
#
|
2109
|
+
def gsub!: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> self?
|
2110
|
+
| (Regexp | string pattern) -> Enumerator[String, self?]
|
2111
|
+
| (Regexp | string pattern) { (String match) -> _ToS } -> self?
|
2112
|
+
|
2113
|
+
# <!--
|
2114
|
+
# rdoc-file=string.c
|
2115
|
+
# - hash -> integer
|
2116
|
+
# -->
|
2117
|
+
# Returns the integer hash value for `self`. The value is based on the length,
|
2118
|
+
# content and encoding of `self`.
|
2119
|
+
#
|
2120
|
+
# Related: Object#hash.
|
2121
|
+
#
|
2122
|
+
def hash: () -> Integer
|
2123
|
+
|
2124
|
+
# <!--
|
2125
|
+
# rdoc-file=string.c
|
2126
|
+
# - hex -> integer
|
2127
|
+
# -->
|
2128
|
+
# Interprets the leading substring of `self` as a string of hexadecimal digits
|
2129
|
+
# (with an optional sign and an optional `0x`) and returns the corresponding
|
2130
|
+
# number; returns zero if there is no such leading substring:
|
2131
|
+
#
|
2132
|
+
# '0x0a'.hex # => 10
|
2133
|
+
# '-1234'.hex # => -4660
|
2134
|
+
# '0'.hex # => 0
|
2135
|
+
# 'non-numeric'.hex # => 0
|
2136
|
+
#
|
2137
|
+
# Related: String#oct.
|
2138
|
+
#
|
2139
|
+
def hex: () -> Integer
|
2140
|
+
|
2141
|
+
# <!--
|
2142
|
+
# rdoc-file=string.c
|
2143
|
+
# - include?(other_string) -> true or false
|
2144
|
+
# -->
|
2145
|
+
# Returns `true` if `self` contains `other_string`, `false` otherwise:
|
2146
|
+
#
|
2147
|
+
# s = 'foo'
|
2148
|
+
# s.include?('f') # => true
|
2149
|
+
# s.include?('fo') # => true
|
2150
|
+
# s.include?('food') # => false
|
2151
|
+
#
|
2152
|
+
def include?: (string other_string) -> bool
|
2153
|
+
|
2154
|
+
# <!--
|
2155
|
+
# rdoc-file=string.c
|
2156
|
+
# - index(substring, offset = 0) -> integer or nil
|
2157
|
+
# - index(regexp, offset = 0) -> integer or nil
|
2158
|
+
# -->
|
2159
|
+
# Returns the integer index of the first match for the given argument, or `nil`
|
2160
|
+
# if none found; the search of `self` is forward, and begins at position
|
2161
|
+
# `offset` (in characters).
|
2162
|
+
#
|
2163
|
+
# With string argument `substring`, returns the index of the first matching
|
2164
|
+
# substring in `self`:
|
2165
|
+
#
|
2166
|
+
# 'foo'.index('f') # => 0
|
2167
|
+
# 'foo'.index('o') # => 1
|
2168
|
+
# 'foo'.index('oo') # => 1
|
2169
|
+
# 'foo'.index('ooo') # => nil
|
2170
|
+
# 'тест'.index('с') # => 2
|
2171
|
+
# 'こんにちは'.index('ち') # => 3
|
2172
|
+
#
|
2173
|
+
# With Regexp argument `regexp`, returns the index of the first match in `self`:
|
2174
|
+
#
|
2175
|
+
# 'foo'.index(/o./) # => 1
|
2176
|
+
# 'foo'.index(/.o/) # => 0
|
2177
|
+
#
|
2178
|
+
# With positive integer `offset`, begins the search at position `offset`:
|
2179
|
+
#
|
2180
|
+
# 'foo'.index('o', 1) # => 1
|
2181
|
+
# 'foo'.index('o', 2) # => 2
|
2182
|
+
# 'foo'.index('o', 3) # => nil
|
2183
|
+
# 'тест'.index('с', 1) # => 2
|
2184
|
+
# 'こんにちは'.index('ち', 2) # => 3
|
2185
|
+
#
|
2186
|
+
# With negative integer `offset`, selects the search position by counting
|
2187
|
+
# backward from the end of `self`:
|
2188
|
+
#
|
2189
|
+
# 'foo'.index('o', -1) # => 2
|
2190
|
+
# 'foo'.index('o', -2) # => 1
|
2191
|
+
# 'foo'.index('o', -3) # => 1
|
2192
|
+
# 'foo'.index('o', -4) # => nil
|
2193
|
+
# 'foo'.index(/o./, -2) # => 1
|
2194
|
+
# 'foo'.index(/.o/, -2) # => 1
|
2195
|
+
#
|
2196
|
+
# Related: String#rindex.
|
2197
|
+
#
|
2198
|
+
def index: (Regexp | string pattern, ?int offset) -> Integer?
|
2199
|
+
|
2200
|
+
# <!--
|
2201
|
+
# rdoc-file=string.c
|
2202
|
+
# - insert(index, other_string) -> self
|
2203
|
+
# -->
|
2204
|
+
# Inserts the given `other_string` into `self`; returns `self`.
|
2205
|
+
#
|
2206
|
+
# If the Integer `index` is positive, inserts `other_string` at offset `index`:
|
2207
|
+
#
|
2208
|
+
# 'foo'.insert(1, 'bar') # => "fbaroo"
|
2209
|
+
#
|
2210
|
+
# If the Integer `index` is negative, counts backward from the end of `self` and
|
2211
|
+
# inserts `other_string` at offset `index+1` (that is, *after* `self[index]`):
|
2212
|
+
#
|
2213
|
+
# 'foo'.insert(-2, 'bar') # => "fobaro"
|
2214
|
+
#
|
2215
|
+
def insert: (int index, string other_str) -> self
|
2216
|
+
|
2217
|
+
# <!--
|
2218
|
+
# rdoc-file=string.c
|
2219
|
+
# - inspect -> string
|
2220
|
+
# -->
|
2221
|
+
# Returns a printable version of `self`, enclosed in double-quotes, and with
|
2222
|
+
# special characters escaped:
|
2223
|
+
#
|
2224
|
+
# s = "foo\tbar\tbaz\n"
|
2225
|
+
# s.inspect
|
2226
|
+
# # => "\"foo\\tbar\\tbaz\\n\""
|
2227
|
+
#
|
2228
|
+
def inspect: () -> String
|
2229
|
+
|
2230
|
+
# <!--
|
2231
|
+
# rdoc-file=string.c
|
2232
|
+
# - str.intern -> symbol
|
2233
|
+
# - str.to_sym -> symbol
|
2234
|
+
# -->
|
2235
|
+
# Returns the `Symbol` corresponding to *str*, creating the symbol if it did not
|
2236
|
+
# previously exist. See Symbol#id2name.
|
2237
|
+
#
|
2238
|
+
# "Koala".intern #=> :Koala
|
2239
|
+
# s = 'cat'.to_sym #=> :cat
|
2240
|
+
# s == :cat #=> true
|
2241
|
+
# s = '@cat'.to_sym #=> :@cat
|
2242
|
+
# s == :@cat #=> true
|
2243
|
+
#
|
2244
|
+
# This can also be used to create symbols that cannot be represented using the
|
2245
|
+
# `:xxx` notation.
|
2246
|
+
#
|
2247
|
+
# 'cat and dog'.to_sym #=> :"cat and dog"
|
2248
|
+
#
|
2249
|
+
def intern: () -> Symbol
|
2250
|
+
|
2251
|
+
# <!--
|
2252
|
+
# rdoc-file=string.c
|
2253
|
+
# - length -> integer
|
2254
|
+
# -->
|
2255
|
+
# Returns the count of characters (not bytes) in `self`:
|
2256
|
+
#
|
2257
|
+
# 'foo'.length # => 3
|
2258
|
+
# 'тест'.length # => 4
|
2259
|
+
# 'こんにちは'.length # => 5
|
2260
|
+
#
|
2261
|
+
# Contrast with String#bytesize:
|
2262
|
+
#
|
2263
|
+
# 'foo'.bytesize # => 3
|
2264
|
+
# 'тест'.bytesize # => 8
|
2265
|
+
# 'こんにちは'.bytesize # => 15
|
2266
|
+
#
|
2267
|
+
def length: () -> Integer
|
2268
|
+
|
2269
|
+
# <!--
|
2270
|
+
# rdoc-file=string.c
|
2271
|
+
# - lines(Line_sep = $/, chomp: false) -> array_of_strings
|
2272
|
+
# -->
|
2273
|
+
# Forms substrings ("lines") of `self` according to the given arguments (see
|
2274
|
+
# String#each_line for details); returns the lines in an array.
|
2275
|
+
#
|
2276
|
+
def lines: (?string? separator, ?chomp: boolish) -> Array[String]
|
2277
|
+
| (?string? separator, ?chomp: boolish) { (String line) -> void } -> self
|
2278
|
+
|
2279
|
+
# <!--
|
2280
|
+
# rdoc-file=string.c
|
2281
|
+
# - ljust(size, pad_string = ' ') -> new_string
|
2282
|
+
# -->
|
2283
|
+
# Returns a left-justified copy of `self`.
|
2284
|
+
#
|
2285
|
+
# If integer argument `size` is greater than the size (in characters) of `self`,
|
2286
|
+
# returns a new string of length `size` that is a copy of `self`, left justified
|
2287
|
+
# and padded on the right with `pad_string`:
|
2288
|
+
#
|
2289
|
+
# 'hello'.ljust(10) # => "hello "
|
2290
|
+
# ' hello'.ljust(10) # => " hello "
|
2291
|
+
# 'hello'.ljust(10, 'ab') # => "helloababa"
|
2292
|
+
# 'тест'.ljust(10) # => "тест "
|
2293
|
+
# 'こんにちは'.ljust(10) # => "こんにちは "
|
2294
|
+
#
|
2295
|
+
# If `size` is not greater than the size of `self`, returns a copy of `self`:
|
2296
|
+
#
|
2297
|
+
# 'hello'.ljust(5) # => "hello"
|
2298
|
+
# 'hello'.ljust(1) # => "hello"
|
2299
|
+
#
|
2300
|
+
# Related: String#rjust, String#center.
|
2301
|
+
#
|
2302
|
+
def ljust: (int size, ?string pad_string) -> String
|
2303
|
+
|
2304
|
+
# <!--
|
2305
|
+
# rdoc-file=string.c
|
2306
|
+
# - lstrip -> new_string
|
2307
|
+
# -->
|
2308
|
+
# Returns a copy of `self` with leading whitespace removed; see [Whitespace in
|
2309
|
+
# Strings](rdoc-ref:String@Whitespace+in+Strings):
|
2310
|
+
#
|
2311
|
+
# whitespace = "\x00\t\n\v\f\r "
|
2312
|
+
# s = whitespace + 'abc' + whitespace
|
2313
|
+
# s # => "\u0000\t\n\v\f\r abc\u0000\t\n\v\f\r "
|
2314
|
+
# s.lstrip # => "abc\u0000\t\n\v\f\r "
|
2315
|
+
#
|
2316
|
+
# Related: String#rstrip, String#strip.
|
2317
|
+
#
|
2318
|
+
def lstrip: () -> String
|
2319
|
+
|
2320
|
+
# <!--
|
2321
|
+
# rdoc-file=string.c
|
2322
|
+
# - lstrip! -> self or nil
|
2323
|
+
# -->
|
2324
|
+
# Like String#lstrip, except that any modifications are made in `self`; returns
|
2325
|
+
# `self` if any modification are made, `nil` otherwise.
|
2326
|
+
#
|
2327
|
+
# Related: String#rstrip!, String#strip!.
|
2328
|
+
#
|
2329
|
+
def lstrip!: () -> self?
|
2330
|
+
|
2331
|
+
# <!--
|
2332
|
+
# rdoc-file=string.c
|
2333
|
+
# - match(pattern, offset = 0) -> matchdata or nil
|
2334
|
+
# - match(pattern, offset = 0) {|matchdata| ... } -> object
|
2335
|
+
# -->
|
2336
|
+
# Returns a MatchData object (or `nil`) based on `self` and the given `pattern`.
|
2337
|
+
#
|
2338
|
+
# Note: also updates Regexp@Global+Variables.
|
2339
|
+
#
|
2340
|
+
# * Computes `regexp` by converting `pattern` (if not already a Regexp).
|
2341
|
+
# regexp = Regexp.new(pattern)
|
2342
|
+
#
|
2343
|
+
# * Computes `matchdata`, which will be either a MatchData object or `nil`
|
2344
|
+
# (see Regexp#match):
|
2345
|
+
# matchdata = <tt>regexp.match(self)
|
2346
|
+
#
|
2347
|
+
# With no block given, returns the computed `matchdata`:
|
2348
|
+
#
|
2349
|
+
# 'foo'.match('f') # => #<MatchData "f">
|
2350
|
+
# 'foo'.match('o') # => #<MatchData "o">
|
2351
|
+
# 'foo'.match('x') # => nil
|
2352
|
+
#
|
2353
|
+
# If Integer argument `offset` is given, the search begins at index `offset`:
|
2354
|
+
#
|
2355
|
+
# 'foo'.match('f', 1) # => nil
|
2356
|
+
# 'foo'.match('o', 1) # => #<MatchData "o">
|
2357
|
+
#
|
2358
|
+
# With a block given, calls the block with the computed `matchdata` and returns
|
2359
|
+
# the block's return value:
|
2360
|
+
#
|
2361
|
+
# 'foo'.match(/o/) {|matchdata| matchdata } # => #<MatchData "o">
|
2362
|
+
# 'foo'.match(/x/) {|matchdata| matchdata } # => nil
|
2363
|
+
# 'foo'.match(/f/, 1) {|matchdata| matchdata } # => nil
|
2364
|
+
#
|
2365
|
+
def match: (Regexp | string pattern, ?int offset) -> MatchData?
|
2366
|
+
| [T] (Regexp | string pattern, ?int offset) { (MatchData matchdata) -> T } -> T?
|
2367
|
+
|
2368
|
+
# <!--
|
2369
|
+
# rdoc-file=string.c
|
2370
|
+
# - match?(pattern, offset = 0) -> true or false
|
2371
|
+
# -->
|
2372
|
+
# Returns `true` or `false` based on whether a match is found for `self` and
|
2373
|
+
# `pattern`.
|
2374
|
+
#
|
2375
|
+
# Note: does not update Regexp@Global+Variables.
|
2376
|
+
#
|
2377
|
+
# Computes `regexp` by converting `pattern` (if not already a Regexp).
|
2378
|
+
# regexp = Regexp.new(pattern)
|
2379
|
+
#
|
2380
|
+
# Returns `true` if `self+.match(regexp)` returns a MatchData object, `false`
|
2381
|
+
# otherwise:
|
2382
|
+
#
|
2383
|
+
# 'foo'.match?(/o/) # => true
|
2384
|
+
# 'foo'.match?('o') # => true
|
2385
|
+
# 'foo'.match?(/x/) # => false
|
2386
|
+
#
|
2387
|
+
# If Integer argument `offset` is given, the search begins at index `offset`:
|
2388
|
+
# 'foo'.match?('f', 1) # => false
|
2389
|
+
# 'foo'.match?('o', 1) # => true
|
2390
|
+
#
|
2391
|
+
def match?: (Regexp | string pattern, ?int offset) -> bool
|
2392
|
+
|
2393
|
+
# <!-- rdoc-file=string.c -->
|
2394
|
+
# Returns the successor to `self`. The successor is calculated by incrementing
|
2395
|
+
# characters.
|
2396
|
+
#
|
2397
|
+
# The first character to be incremented is the rightmost alphanumeric: or, if no
|
2398
|
+
# alphanumerics, the rightmost character:
|
2399
|
+
#
|
2400
|
+
# 'THX1138'.succ # => "THX1139"
|
2401
|
+
# '<<koala>>'.succ # => "<<koalb>>"
|
2402
|
+
# '***'.succ # => '**+'
|
2403
|
+
#
|
2404
|
+
# The successor to a digit is another digit, "carrying" to the next-left
|
2405
|
+
# character for a "rollover" from 9 to 0, and prepending another digit if
|
2406
|
+
# necessary:
|
2407
|
+
#
|
2408
|
+
# '00'.succ # => "01"
|
2409
|
+
# '09'.succ # => "10"
|
2410
|
+
# '99'.succ # => "100"
|
2411
|
+
#
|
2412
|
+
# The successor to a letter is another letter of the same case, carrying to the
|
2413
|
+
# next-left character for a rollover, and prepending another same-case letter if
|
2414
|
+
# necessary:
|
2415
|
+
#
|
2416
|
+
# 'aa'.succ # => "ab"
|
2417
|
+
# 'az'.succ # => "ba"
|
2418
|
+
# 'zz'.succ # => "aaa"
|
2419
|
+
# 'AA'.succ # => "AB"
|
2420
|
+
# 'AZ'.succ # => "BA"
|
2421
|
+
# 'ZZ'.succ # => "AAA"
|
2422
|
+
#
|
2423
|
+
# The successor to a non-alphanumeric character is the next character in the
|
2424
|
+
# underlying character set's collating sequence, carrying to the next-left
|
2425
|
+
# character for a rollover, and prepending another character if necessary:
|
2426
|
+
#
|
2427
|
+
# s = 0.chr * 3
|
2428
|
+
# s # => "\x00\x00\x00"
|
2429
|
+
# s.succ # => "\x00\x00\x01"
|
2430
|
+
# s = 255.chr * 3
|
2431
|
+
# s # => "\xFF\xFF\xFF"
|
2432
|
+
# s.succ # => "\x01\x00\x00\x00"
|
2433
|
+
#
|
2434
|
+
# Carrying can occur between and among mixtures of alphanumeric characters:
|
2435
|
+
#
|
2436
|
+
# s = 'zz99zz99'
|
2437
|
+
# s.succ # => "aaa00aa00"
|
2438
|
+
# s = '99zz99zz'
|
2439
|
+
# s.succ # => "100aa00aa"
|
2440
|
+
#
|
2441
|
+
# The successor to an empty `String` is a new empty `String`:
|
2442
|
+
#
|
2443
|
+
# ''.succ # => ""
|
2444
|
+
#
|
2445
|
+
alias next succ
|
2446
|
+
|
2447
|
+
# <!-- rdoc-file=string.c -->
|
2448
|
+
# Equivalent to String#succ, but modifies `self` in place; returns `self`.
|
2449
|
+
#
|
2450
|
+
alias next! succ!
|
2451
|
+
|
2452
|
+
# <!--
|
2453
|
+
# rdoc-file=string.c
|
2454
|
+
# - oct -> integer
|
2455
|
+
# -->
|
2456
|
+
# Interprets the leading substring of `self` as a string of octal digits (with
|
2457
|
+
# an optional sign) and returns the corresponding number; returns zero if there
|
2458
|
+
# is no such leading substring:
|
2459
|
+
#
|
2460
|
+
# '123'.oct # => 83
|
2461
|
+
# '-377'.oct # => -255
|
2462
|
+
# '0377non-numeric'.oct # => 255
|
2463
|
+
# 'non-numeric'.oct # => 0
|
2464
|
+
#
|
2465
|
+
# If `self` starts with `0`, radix indicators are honored; see Kernel#Integer.
|
2466
|
+
#
|
2467
|
+
# Related: String#hex.
|
2468
|
+
#
|
2469
|
+
def oct: () -> Integer
|
2470
|
+
|
2471
|
+
# <!--
|
2472
|
+
# rdoc-file=string.c
|
2473
|
+
# - ord -> integer
|
2474
|
+
# -->
|
2475
|
+
# Returns the integer ordinal of the first character of `self`:
|
2476
|
+
#
|
2477
|
+
# 'h'.ord # => 104
|
2478
|
+
# 'hello'.ord # => 104
|
2479
|
+
# 'тест'.ord # => 1090
|
2480
|
+
# 'こんにちは'.ord # => 12371
|
2481
|
+
#
|
2482
|
+
def ord: () -> Integer
|
2483
|
+
|
2484
|
+
# <!--
|
2485
|
+
# rdoc-file=string.c
|
2486
|
+
# - partition(string_or_regexp) -> [head, match, tail]
|
2487
|
+
# -->
|
2488
|
+
# Returns a 3-element array of substrings of `self`.
|
2489
|
+
#
|
2490
|
+
# Matches a pattern against `self`, scanning from the beginning. The pattern is:
|
2491
|
+
#
|
2492
|
+
# * `string_or_regexp` itself, if it is a Regexp.
|
2493
|
+
# * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
|
2494
|
+
#
|
2495
|
+
# If the pattern is matched, returns pre-match, first-match, post-match:
|
2496
|
+
#
|
2497
|
+
# 'hello'.partition('l') # => ["he", "l", "lo"]
|
2498
|
+
# 'hello'.partition('ll') # => ["he", "ll", "o"]
|
2499
|
+
# 'hello'.partition('h') # => ["", "h", "ello"]
|
2500
|
+
# 'hello'.partition('o') # => ["hell", "o", ""]
|
2501
|
+
# 'hello'.partition(/l+/) #=> ["he", "ll", "o"]
|
2502
|
+
# 'hello'.partition('') # => ["", "", "hello"]
|
2503
|
+
# 'тест'.partition('т') # => ["", "т", "ест"]
|
2504
|
+
# 'こんにちは'.partition('に') # => ["こん", "に", "ちは"]
|
2505
|
+
#
|
2506
|
+
# If the pattern is not matched, returns a copy of `self` and two empty strings:
|
2507
|
+
#
|
2508
|
+
# 'hello'.partition('x') # => ["hello", "", ""]
|
2509
|
+
#
|
2510
|
+
# Related: String#rpartition, String#split.
|
2511
|
+
#
|
2512
|
+
def partition: (Regexp | string pattern) -> [String, String, String]
|
2513
|
+
|
2514
|
+
# <!--
|
2515
|
+
# rdoc-file=string.c
|
2516
|
+
# - prepend(*other_strings) -> string
|
2517
|
+
# -->
|
2518
|
+
# Prepends each string in `other_strings` to `self` and returns `self`:
|
2519
|
+
#
|
2520
|
+
# s = 'foo'
|
2521
|
+
# s.prepend('bar', 'baz') # => "barbazfoo"
|
2522
|
+
# s # => "barbazfoo"
|
2523
|
+
#
|
2524
|
+
# Related: String#concat.
|
2525
|
+
#
|
2526
|
+
def prepend: (*string other_strings) -> self
|
2527
|
+
|
2528
|
+
# <!-- rdoc-file=string.c -->
|
2529
|
+
# Replaces the contents of `self` with the contents of `other_string`:
|
2530
|
+
#
|
2531
|
+
# s = 'foo' # => "foo"
|
2532
|
+
# s.replace('bar') # => "bar"
|
2533
|
+
#
|
2534
|
+
def replace: (string other_string) -> self
|
2535
|
+
|
2536
|
+
# <!--
|
2537
|
+
# rdoc-file=string.c
|
2538
|
+
# - reverse -> string
|
2539
|
+
# -->
|
2540
|
+
# Returns a new string with the characters from `self` in reverse order.
|
2541
|
+
#
|
2542
|
+
# 'stressed'.reverse # => "desserts"
|
2543
|
+
#
|
2544
|
+
def reverse: () -> String
|
2545
|
+
|
2546
|
+
# <!--
|
2547
|
+
# rdoc-file=string.c
|
2548
|
+
# - reverse! -> self
|
2549
|
+
# -->
|
2550
|
+
# Returns `self` with its characters reversed:
|
2551
|
+
#
|
2552
|
+
# s = 'stressed'
|
2553
|
+
# s.reverse! # => "desserts"
|
2554
|
+
# s # => "desserts"
|
2555
|
+
#
|
2556
|
+
def reverse!: () -> self
|
2557
|
+
|
2558
|
+
# <!--
|
2559
|
+
# rdoc-file=string.c
|
2560
|
+
# - rindex(substring, offset = self.length) -> integer or nil
|
2561
|
+
# - rindex(regexp, offset = self.length) -> integer or nil
|
2562
|
+
# -->
|
2563
|
+
# Returns the Integer index of the *last* occurrence of the given `substring`,
|
2564
|
+
# or `nil` if none found:
|
2565
|
+
#
|
2566
|
+
# 'foo'.rindex('f') # => 0
|
2567
|
+
# 'foo'.rindex('o') # => 2
|
2568
|
+
# 'foo'.rindex('oo') # => 1
|
2569
|
+
# 'foo'.rindex('ooo') # => nil
|
2570
|
+
#
|
2571
|
+
# Returns the Integer index of the *last* match for the given Regexp `regexp`,
|
2572
|
+
# or `nil` if none found:
|
2573
|
+
#
|
2574
|
+
# 'foo'.rindex(/f/) # => 0
|
2575
|
+
# 'foo'.rindex(/o/) # => 2
|
2576
|
+
# 'foo'.rindex(/oo/) # => 1
|
2577
|
+
# 'foo'.rindex(/ooo/) # => nil
|
2578
|
+
#
|
2579
|
+
# The *last* match means starting at the possible last position, not the last of
|
2580
|
+
# longest matches.
|
2581
|
+
#
|
2582
|
+
# 'foo'.rindex(/o+/) # => 2
|
2583
|
+
# $~ #=> #<MatchData "o">
|
2584
|
+
#
|
2585
|
+
# To get the last longest match, needs to combine with negative lookbehind.
|
2586
|
+
#
|
2587
|
+
# 'foo'.rindex(/(?<!o)o+/) # => 1
|
2588
|
+
# $~ #=> #<MatchData "oo">
|
2589
|
+
#
|
2590
|
+
# Or String#index with negative lookforward.
|
2591
|
+
#
|
2592
|
+
# 'foo'.index(/o+(?!.*o)/) # => 1
|
2593
|
+
# $~ #=> #<MatchData "oo">
|
2594
|
+
#
|
2595
|
+
# Integer argument `offset`, if given and non-negative, specifies the maximum
|
2596
|
+
# starting position in the string to *end* the search:
|
2597
|
+
#
|
2598
|
+
# 'foo'.rindex('o', 0) # => nil
|
2599
|
+
# 'foo'.rindex('o', 1) # => 1
|
2600
|
+
# 'foo'.rindex('o', 2) # => 2
|
2601
|
+
# 'foo'.rindex('o', 3) # => 2
|
2602
|
+
#
|
2603
|
+
# If `offset` is a negative Integer, the maximum starting position in the string
|
2604
|
+
# to *end* the search is the sum of the string's length and `offset`:
|
2605
|
+
#
|
2606
|
+
# 'foo'.rindex('o', -1) # => 2
|
2607
|
+
# 'foo'.rindex('o', -2) # => 1
|
2608
|
+
# 'foo'.rindex('o', -3) # => nil
|
2609
|
+
# 'foo'.rindex('o', -4) # => nil
|
2610
|
+
#
|
2611
|
+
# Related: String#index.
|
2612
|
+
#
|
2613
|
+
def rindex: (Regexp | string pattern, ?int offset) -> Integer?
|
2614
|
+
|
2615
|
+
# <!--
|
2616
|
+
# rdoc-file=string.c
|
2617
|
+
# - rjust(size, pad_string = ' ') -> new_string
|
2618
|
+
# -->
|
2619
|
+
# Returns a right-justified copy of `self`.
|
2620
|
+
#
|
2621
|
+
# If integer argument `size` is greater than the size (in characters) of `self`,
|
2622
|
+
# returns a new string of length `size` that is a copy of `self`, right
|
2623
|
+
# justified and padded on the left with `pad_string`:
|
2624
|
+
#
|
2625
|
+
# 'hello'.rjust(10) # => " hello"
|
2626
|
+
# 'hello '.rjust(10) # => " hello "
|
2627
|
+
# 'hello'.rjust(10, 'ab') # => "ababahello"
|
2628
|
+
# 'тест'.rjust(10) # => " тест"
|
2629
|
+
# 'こんにちは'.rjust(10) # => " こんにちは"
|
2630
|
+
#
|
2631
|
+
# If `size` is not greater than the size of `self`, returns a copy of `self`:
|
2632
|
+
#
|
2633
|
+
# 'hello'.rjust(5, 'ab') # => "hello"
|
2634
|
+
# 'hello'.rjust(1, 'ab') # => "hello"
|
2635
|
+
#
|
2636
|
+
# Related: String#ljust, String#center.
|
2637
|
+
#
|
2638
|
+
def rjust: (int size, ?string pad_string) -> String
|
2639
|
+
|
2640
|
+
# <!--
|
2641
|
+
# rdoc-file=string.c
|
2642
|
+
# - rpartition(sep) -> [head, match, tail]
|
2643
|
+
# -->
|
2644
|
+
# Returns a 3-element array of substrings of `self`.
|
2645
|
+
#
|
2646
|
+
# Matches a pattern against `self`, scanning backwards from the end. The pattern
|
2647
|
+
# is:
|
2648
|
+
#
|
2649
|
+
# * `string_or_regexp` itself, if it is a Regexp.
|
2650
|
+
# * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
|
2651
|
+
#
|
2652
|
+
# If the pattern is matched, returns pre-match, last-match, post-match:
|
2653
|
+
#
|
2654
|
+
# 'hello'.rpartition('l') # => ["hel", "l", "o"]
|
2655
|
+
# 'hello'.rpartition('ll') # => ["he", "ll", "o"]
|
2656
|
+
# 'hello'.rpartition('h') # => ["", "h", "ello"]
|
2657
|
+
# 'hello'.rpartition('o') # => ["hell", "o", ""]
|
2658
|
+
# 'hello'.rpartition(/l+/) # => ["hel", "l", "o"]
|
2659
|
+
# 'hello'.rpartition('') # => ["hello", "", ""]
|
2660
|
+
# 'тест'.rpartition('т') # => ["тес", "т", ""]
|
2661
|
+
# 'こんにちは'.rpartition('に') # => ["こん", "に", "ちは"]
|
2662
|
+
#
|
2663
|
+
# If the pattern is not matched, returns two empty strings and a copy of `self`:
|
2664
|
+
#
|
2665
|
+
# 'hello'.rpartition('x') # => ["", "", "hello"]
|
2666
|
+
#
|
2667
|
+
# Related: String#partition, String#split.
|
2668
|
+
#
|
2669
|
+
def rpartition: (Regexp | string pattern) -> [String, String, String]
|
2670
|
+
|
2671
|
+
# <!--
|
2672
|
+
# rdoc-file=string.c
|
2673
|
+
# - rstrip -> new_string
|
2674
|
+
# -->
|
2675
|
+
# Returns a copy of the receiver with trailing whitespace removed; see
|
2676
|
+
# [Whitespace in Strings](rdoc-ref:String@Whitespace+in+Strings):
|
2677
|
+
#
|
2678
|
+
# whitespace = "\x00\t\n\v\f\r "
|
2679
|
+
# s = whitespace + 'abc' + whitespace
|
2680
|
+
# s # => "\u0000\t\n\v\f\r abc\u0000\t\n\v\f\r "
|
2681
|
+
# s.rstrip # => "\u0000\t\n\v\f\r abc"
|
2682
|
+
#
|
2683
|
+
# Related: String#lstrip, String#strip.
|
2684
|
+
#
|
2685
|
+
def rstrip: () -> String
|
2686
|
+
|
2687
|
+
# <!--
|
2688
|
+
# rdoc-file=string.c
|
2689
|
+
# - rstrip! -> self or nil
|
2690
|
+
# -->
|
2691
|
+
# Like String#rstrip, except that any modifications are made in `self`; returns
|
2692
|
+
# `self` if any modification are made, `nil` otherwise.
|
2693
|
+
#
|
2694
|
+
# Related: String#lstrip!, String#strip!.
|
2695
|
+
#
|
2696
|
+
def rstrip!: () -> self?
|
2697
|
+
|
2698
|
+
# <!--
|
2699
|
+
# rdoc-file=string.c
|
2700
|
+
# - scan(string_or_regexp) -> array
|
2701
|
+
# - scan(string_or_regexp) {|matches| ... } -> self
|
2702
|
+
# -->
|
2703
|
+
# Matches a pattern against `self`; the pattern is:
|
2704
|
+
#
|
2705
|
+
# * `string_or_regexp` itself, if it is a Regexp.
|
2706
|
+
# * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
|
2707
|
+
#
|
2708
|
+
# Iterates through `self`, generating a collection of matching results:
|
2709
|
+
#
|
2710
|
+
# * If the pattern contains no groups, each result is the matched string,
|
2711
|
+
# `$&`.
|
2712
|
+
# * If the pattern contains groups, each result is an array containing one
|
2713
|
+
# entry per group.
|
2714
|
+
#
|
2715
|
+
# With no block given, returns an array of the results:
|
2716
|
+
#
|
2717
|
+
# s = 'cruel world'
|
2718
|
+
# s.scan(/\w+/) # => ["cruel", "world"]
|
2719
|
+
# s.scan(/.../) # => ["cru", "el ", "wor"]
|
2720
|
+
# s.scan(/(...)/) # => [["cru"], ["el "], ["wor"]]
|
2721
|
+
# s.scan(/(..)(..)/) # => [["cr", "ue"], ["l ", "wo"]]
|
2722
|
+
#
|
2723
|
+
# With a block given, calls the block with each result; returns `self`:
|
2724
|
+
#
|
2725
|
+
# s.scan(/\w+/) {|w| print "<<#{w}>> " }
|
2726
|
+
# print "\n"
|
2727
|
+
# s.scan(/(.)(.)/) {|x,y| print y, x }
|
2728
|
+
# print "\n"
|
2729
|
+
#
|
2730
|
+
# Output:
|
2731
|
+
#
|
2732
|
+
# <<cruel>> <<world>>
|
2733
|
+
# rceu lowlr
|
2734
|
+
#
|
2735
|
+
def scan: (Regexp pattern) -> Array[String | Array[String?]]
|
2736
|
+
| (Regexp pattern) { (String | Array[String?] matches) -> void } -> self
|
2737
|
+
| (string pattern) -> Array[String]
|
2738
|
+
| (string pattern) { (String match) -> void } -> self
|
2739
|
+
|
2740
|
+
# <!--
|
2741
|
+
# rdoc-file=string.c
|
2742
|
+
# - scrub(replacement_string = default_replacement) -> new_string
|
2743
|
+
# - scrub{|bytes| ... } -> new_string
|
2744
|
+
# -->
|
2745
|
+
# Returns a copy of `self` with each invalid byte sequence replaced by the given
|
2746
|
+
# `replacement_string`.
|
2747
|
+
#
|
2748
|
+
# With no block given and no argument, replaces each invalid sequence with the
|
2749
|
+
# default replacement string (`"�"` for a Unicode encoding, `'?'` otherwise):
|
2750
|
+
#
|
2751
|
+
# s = "foo\x81\x81bar"
|
2752
|
+
# s.scrub # => "foo��bar"
|
2753
|
+
#
|
2754
|
+
# With no block given and argument `replacement_string` given, replaces each
|
2755
|
+
# invalid sequence with that string:
|
2756
|
+
#
|
2757
|
+
# "foo\x81\x81bar".scrub('xyzzy') # => "fooxyzzyxyzzybar"
|
2758
|
+
#
|
2759
|
+
# With a block given, replaces each invalid sequence with the value of the
|
2760
|
+
# block:
|
2761
|
+
#
|
2762
|
+
# "foo\x81\x81bar".scrub {|bytes| p bytes; 'XYZZY' }
|
2763
|
+
# # => "fooXYZZYXYZZYbar"
|
2764
|
+
#
|
2765
|
+
# Output:
|
2766
|
+
#
|
2767
|
+
# "\x81"
|
2768
|
+
# "\x81"
|
2769
|
+
#
|
2770
|
+
def scrub: (?string? replacement) -> String
|
2771
|
+
| (?nil) { (String bytes) -> string } -> String
|
2772
|
+
|
2773
|
+
# <!--
|
2774
|
+
# rdoc-file=string.c
|
2775
|
+
# - scrub! -> self
|
2776
|
+
# - scrub!(replacement_string = default_replacement) -> self
|
2777
|
+
# - scrub!{|bytes| ... } -> self
|
2778
|
+
# -->
|
2779
|
+
# Like String#scrub, except that any replacements are made in `self`.
|
2780
|
+
#
|
2781
|
+
def scrub!: (?string? replacement) -> self
|
2782
|
+
| (?nil) { (String bytes) -> string } -> self
|
2783
|
+
|
2784
|
+
# <!--
|
2785
|
+
# rdoc-file=string.c
|
2786
|
+
# - setbyte(index, integer) -> integer
|
2787
|
+
# -->
|
2788
|
+
# Sets the byte at zero-based `index` to `integer`; returns `integer`:
|
2789
|
+
#
|
2790
|
+
# s = 'abcde' # => "abcde"
|
2791
|
+
# s.setbyte(0, 98) # => 98
|
2792
|
+
# s # => "bbcde"
|
2793
|
+
#
|
2794
|
+
# Related: String#getbyte.
|
2795
|
+
#
|
2796
|
+
def setbyte: [T < _ToInt] (int index, T byte) -> T
|
2797
|
+
|
2798
|
+
# <!-- rdoc-file=string.c -->
|
2799
|
+
# Returns the count of characters (not bytes) in `self`:
|
2800
|
+
#
|
2801
|
+
# 'foo'.length # => 3
|
2802
|
+
# 'тест'.length # => 4
|
2803
|
+
# 'こんにちは'.length # => 5
|
2804
|
+
#
|
2805
|
+
# Contrast with String#bytesize:
|
2806
|
+
#
|
2807
|
+
# 'foo'.bytesize # => 3
|
2808
|
+
# 'тест'.bytesize # => 8
|
2809
|
+
# 'こんにちは'.bytesize # => 15
|
2810
|
+
#
|
2811
|
+
alias size length
|
2812
|
+
|
2813
|
+
# <!-- rdoc-file=string.c -->
|
2814
|
+
# Returns the substring of `self` specified by the arguments. See examples at
|
2815
|
+
# [String Slices](rdoc-ref:String@String+Slices).
|
2816
|
+
#
|
2817
|
+
alias slice []
|
2818
|
+
|
2819
|
+
# <!--
|
2820
|
+
# rdoc-file=string.c
|
2821
|
+
# - slice!(index) -> new_string or nil
|
2822
|
+
# - slice!(start, length) -> new_string or nil
|
2823
|
+
# - slice!(range) -> new_string or nil
|
2824
|
+
# - slice!(regexp, capture = 0) -> new_string or nil
|
2825
|
+
# - slice!(substring) -> new_string or nil
|
2826
|
+
# -->
|
2827
|
+
# Removes and returns the substring of `self` specified by the arguments. See
|
2828
|
+
# [String Slices](rdoc-ref:String@String+Slices).
|
2829
|
+
#
|
2830
|
+
# A few examples:
|
2831
|
+
#
|
2832
|
+
# string = "This is a string"
|
2833
|
+
# string.slice!(2) #=> "i"
|
2834
|
+
# string.slice!(3..6) #=> " is "
|
2835
|
+
# string.slice!(/s.*t/) #=> "sa st"
|
2836
|
+
# string.slice!("r") #=> "r"
|
2837
|
+
# string #=> "Thing"
|
2838
|
+
#
|
2839
|
+
def slice!: (int index, ?int length) -> String?
|
2840
|
+
| (range[int?] range) -> String?
|
2841
|
+
| (String substring) -> String?
|
2842
|
+
| (Regexp regexp, ?MatchData::capture backref) -> String?
|
2843
|
+
|
2844
|
+
# <!--
|
2845
|
+
# rdoc-file=string.c
|
2846
|
+
# - split(field_sep = $;, limit = 0) -> array
|
2847
|
+
# - split(field_sep = $;, limit = 0) {|substring| ... } -> self
|
2848
|
+
# -->
|
2849
|
+
# Returns an array of substrings of `self` that are the result of splitting
|
2850
|
+
# `self` at each occurrence of the given field separator `field_sep`.
|
2851
|
+
#
|
2852
|
+
# When `field_sep` is `$;`:
|
2853
|
+
#
|
2854
|
+
# * If `$;` is `nil` (its default value), the split occurs just as if
|
2855
|
+
# `field_sep` were given as a space character (see below).
|
2856
|
+
#
|
2857
|
+
# * If `$;` is a string, the split occurs just as if `field_sep` were given as
|
2858
|
+
# that string (see below).
|
2859
|
+
#
|
2860
|
+
# When `field_sep` is `' '` and `limit` is `0` (its default value), the split
|
2861
|
+
# occurs at each sequence of whitespace:
|
2862
|
+
#
|
2863
|
+
# 'abc def ghi'.split(' ') => ["abc", "def", "ghi"]
|
2864
|
+
# "abc \n\tdef\t\n ghi".split(' ') # => ["abc", "def", "ghi"]
|
2865
|
+
# 'abc def ghi'.split(' ') => ["abc", "def", "ghi"]
|
2866
|
+
# ''.split(' ') => []
|
2867
|
+
#
|
2868
|
+
# When `field_sep` is a string different from `' '` and `limit` is `0`, the
|
2869
|
+
# split occurs at each occurrence of `field_sep`; trailing empty substrings are
|
2870
|
+
# not returned:
|
2871
|
+
#
|
2872
|
+
# 'abracadabra'.split('ab') => ["", "racad", "ra"]
|
2873
|
+
# 'aaabcdaaa'.split('a') => ["", "", "", "bcd"]
|
2874
|
+
# ''.split('a') => []
|
2875
|
+
# '3.14159'.split('1') => ["3.", "4", "59"]
|
2876
|
+
# '!@#$%^$&*($)_+'.split('$') # => ["!@#", "%^", "&*(", ")_+"]
|
2877
|
+
# 'тест'.split('т') => ["", "ес"]
|
2878
|
+
# 'こんにちは'.split('に') => ["こん", "ちは"]
|
2879
|
+
#
|
2880
|
+
# When `field_sep` is a Regexp and `limit` is `0`, the split occurs at each
|
2881
|
+
# occurrence of a match; trailing empty substrings are not returned:
|
2882
|
+
#
|
2883
|
+
# 'abracadabra'.split(/ab/) # => ["", "racad", "ra"]
|
2884
|
+
# 'aaabcdaaa'.split(/a/) => ["", "", "", "bcd"]
|
2885
|
+
# 'aaabcdaaa'.split(//) => ["a", "a", "a", "b", "c", "d", "a", "a", "a"]
|
2886
|
+
# '1 + 1 == 2'.split(/\W+/) # => ["1", "1", "2"]
|
2887
|
+
#
|
2888
|
+
# If the Regexp contains groups, their matches are also included in the returned
|
2889
|
+
# array:
|
2890
|
+
#
|
2891
|
+
# '1:2:3'.split(/(:)()()/, 2) # => ["1", ":", "", "", "2:3"]
|
2892
|
+
#
|
2893
|
+
# As seen above, if `limit` is `0`, trailing empty substrings are not returned:
|
2894
|
+
#
|
2895
|
+
# 'aaabcdaaa'.split('a') => ["", "", "", "bcd"]
|
2896
|
+
#
|
2897
|
+
# If `limit` is positive integer `n`, no more than `n - 1-` splits occur, so
|
2898
|
+
# that at most `n` substrings are returned, and trailing empty substrings are
|
2899
|
+
# included:
|
2900
|
+
#
|
2901
|
+
# 'aaabcdaaa'.split('a', 1) # => ["aaabcdaaa"]
|
2902
|
+
# 'aaabcdaaa'.split('a', 2) # => ["", "aabcdaaa"]
|
2903
|
+
# 'aaabcdaaa'.split('a', 5) # => ["", "", "", "bcd", "aa"]
|
2904
|
+
# 'aaabcdaaa'.split('a', 7) # => ["", "", "", "bcd", "", "", ""]
|
2905
|
+
# 'aaabcdaaa'.split('a', 8) # => ["", "", "", "bcd", "", "", ""]
|
2906
|
+
#
|
2907
|
+
# Note that if `field_sep` is a Regexp containing groups, their matches are in
|
2908
|
+
# the returned array, but do not count toward the limit.
|
2909
|
+
#
|
2910
|
+
# If `limit` is negative, it behaves the same as if `limit` was zero, meaning
|
2911
|
+
# that there is no limit, and trailing empty substrings are included:
|
2912
|
+
#
|
2913
|
+
# 'aaabcdaaa'.split('a', -1) # => ["", "", "", "bcd", "", "", ""]
|
2914
|
+
#
|
2915
|
+
# If a block is given, it is called with each substring:
|
2916
|
+
#
|
2917
|
+
# 'abc def ghi'.split(' ') {|substring| p substring }
|
2918
|
+
#
|
2919
|
+
# Output:
|
2920
|
+
#
|
2921
|
+
# "abc"
|
2922
|
+
# "def"
|
2923
|
+
# "ghi"
|
2924
|
+
#
|
2925
|
+
# Related: String#partition, String#rpartition.
|
2926
|
+
#
|
2927
|
+
def split: (?Regexp | string | nil pattern, ?int limit) -> Array[String]
|
2928
|
+
| (?Regexp | string | nil pattern, ?int limit) { (String substring) -> void } -> self
|
2929
|
+
|
2930
|
+
# <!--
|
2931
|
+
# rdoc-file=string.c
|
2932
|
+
# - squeeze(*selectors) -> new_string
|
2933
|
+
# -->
|
2934
|
+
# Returns a copy of `self` with characters specified by `selectors` "squeezed"
|
2935
|
+
# (see [Multiple Character
|
2936
|
+
# Selectors](rdoc-ref:character_selectors.rdoc@Multiple+Character+Selectors)):
|
2937
|
+
#
|
2938
|
+
# "Squeezed" means that each multiple-character run of a selected character is
|
2939
|
+
# squeezed down to a single character; with no arguments given, squeezes all
|
2940
|
+
# characters:
|
2941
|
+
#
|
2942
|
+
# "yellow moon".squeeze #=> "yelow mon"
|
2943
|
+
# " now is the".squeeze(" ") #=> " now is the"
|
2944
|
+
# "putters shoot balls".squeeze("m-z") #=> "puters shot balls"
|
2945
|
+
#
|
2946
|
+
def squeeze: (*selector selectors) -> String
|
2947
|
+
|
2948
|
+
# <!--
|
2949
|
+
# rdoc-file=string.c
|
2950
|
+
# - squeeze!(*selectors) -> self or nil
|
2951
|
+
# -->
|
2952
|
+
# Like String#squeeze, but modifies `self` in place. Returns `self` if any
|
2953
|
+
# changes were made, `nil` otherwise.
|
2954
|
+
#
|
2955
|
+
def squeeze!: (*selector selectors) -> self?
|
2956
|
+
|
2957
|
+
# <!--
|
2958
|
+
# rdoc-file=string.c
|
2959
|
+
# - start_with?(*string_or_regexp) -> true or false
|
2960
|
+
# -->
|
2961
|
+
# Returns whether `self` starts with any of the given `string_or_regexp`.
|
2962
|
+
#
|
2963
|
+
# Matches patterns against the beginning of `self`. For each given
|
2964
|
+
# `string_or_regexp`, the pattern is:
|
2965
|
+
#
|
2966
|
+
# * `string_or_regexp` itself, if it is a Regexp.
|
2967
|
+
# * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
|
2968
|
+
#
|
2969
|
+
# Returns `true` if any pattern matches the beginning, `false` otherwise:
|
2970
|
+
#
|
2971
|
+
# 'hello'.start_with?('hell') # => true
|
2972
|
+
# 'hello'.start_with?(/H/i) # => true
|
2973
|
+
# 'hello'.start_with?('heaven', 'hell') # => true
|
2974
|
+
# 'hello'.start_with?('heaven', 'paradise') # => false
|
2975
|
+
# 'тест'.start_with?('т') # => true
|
2976
|
+
# 'こんにちは'.start_with?('こ') # => true
|
2977
|
+
#
|
2978
|
+
# Related: String#end_with?.
|
2979
|
+
#
|
2980
|
+
def start_with?: (*Regexp | string prefixes) -> bool
|
2981
|
+
|
2982
|
+
# <!--
|
2983
|
+
# rdoc-file=string.c
|
2984
|
+
# - strip -> new_string
|
2985
|
+
# -->
|
2986
|
+
# Returns a copy of the receiver with leading and trailing whitespace removed;
|
2987
|
+
# see [Whitespace in Strings](rdoc-ref:String@Whitespace+in+Strings):
|
2988
|
+
#
|
2989
|
+
# whitespace = "\x00\t\n\v\f\r "
|
2990
|
+
# s = whitespace + 'abc' + whitespace
|
2991
|
+
# s # => "\u0000\t\n\v\f\r abc\u0000\t\n\v\f\r "
|
2992
|
+
# s.strip # => "abc"
|
2993
|
+
#
|
2994
|
+
# Related: String#lstrip, String#rstrip.
|
2995
|
+
#
|
2996
|
+
def strip: () -> String
|
2997
|
+
|
2998
|
+
# <!--
|
2999
|
+
# rdoc-file=string.c
|
3000
|
+
# - strip! -> self or nil
|
3001
|
+
# -->
|
3002
|
+
# Like String#strip, except that any modifications are made in `self`; returns
|
3003
|
+
# `self` if any modification are made, `nil` otherwise.
|
3004
|
+
#
|
3005
|
+
# Related: String#lstrip!, String#strip!.
|
3006
|
+
#
|
3007
|
+
def strip!: () -> self?
|
3008
|
+
|
3009
|
+
# <!--
|
3010
|
+
# rdoc-file=string.c
|
3011
|
+
# - sub(pattern, replacement) -> new_string
|
3012
|
+
# - sub(pattern) {|match| ... } -> new_string
|
3013
|
+
# -->
|
3014
|
+
# Returns a copy of `self` with only the first occurrence (not all occurrences)
|
3015
|
+
# of the given `pattern` replaced.
|
3016
|
+
#
|
3017
|
+
# See [Substitution Methods](rdoc-ref:String@Substitution+Methods).
|
3018
|
+
#
|
3019
|
+
# Related: String#sub!, String#gsub, String#gsub!.
|
3020
|
+
#
|
3021
|
+
def sub: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> String
|
3022
|
+
| (Regexp | string pattern) { (String match) -> _ToS } -> String
|
3023
|
+
|
3024
|
+
# <!--
|
3025
|
+
# rdoc-file=string.c
|
3026
|
+
# - sub!(pattern, replacement) -> self or nil
|
3027
|
+
# - sub!(pattern) {|match| ... } -> self or nil
|
3028
|
+
# -->
|
3029
|
+
# Replaces the first occurrence (not all occurrences) of the given `pattern` on
|
3030
|
+
# `self`; returns `self` if a replacement occurred, `nil` otherwise.
|
3031
|
+
#
|
3032
|
+
# See [Substitution Methods](rdoc-ref:String@Substitution+Methods).
|
3033
|
+
#
|
3034
|
+
# Related: String#sub, String#gsub, String#gsub!.
|
3035
|
+
#
|
3036
|
+
def sub!: (Regexp | string pattern, string | hash[String, _ToS] replacement) -> self?
|
3037
|
+
| (Regexp | string pattern) { (String match) -> _ToS } -> self?
|
3038
|
+
|
3039
|
+
# <!--
|
3040
|
+
# rdoc-file=string.c
|
3041
|
+
# - succ -> new_str
|
3042
|
+
# -->
|
3043
|
+
# Returns the successor to `self`. The successor is calculated by incrementing
|
3044
|
+
# characters.
|
3045
|
+
#
|
3046
|
+
# The first character to be incremented is the rightmost alphanumeric: or, if no
|
3047
|
+
# alphanumerics, the rightmost character:
|
3048
|
+
#
|
3049
|
+
# 'THX1138'.succ # => "THX1139"
|
3050
|
+
# '<<koala>>'.succ # => "<<koalb>>"
|
3051
|
+
# '***'.succ # => '**+'
|
3052
|
+
#
|
3053
|
+
# The successor to a digit is another digit, "carrying" to the next-left
|
3054
|
+
# character for a "rollover" from 9 to 0, and prepending another digit if
|
3055
|
+
# necessary:
|
3056
|
+
#
|
3057
|
+
# '00'.succ # => "01"
|
3058
|
+
# '09'.succ # => "10"
|
3059
|
+
# '99'.succ # => "100"
|
3060
|
+
#
|
3061
|
+
# The successor to a letter is another letter of the same case, carrying to the
|
3062
|
+
# next-left character for a rollover, and prepending another same-case letter if
|
3063
|
+
# necessary:
|
3064
|
+
#
|
3065
|
+
# 'aa'.succ # => "ab"
|
3066
|
+
# 'az'.succ # => "ba"
|
3067
|
+
# 'zz'.succ # => "aaa"
|
3068
|
+
# 'AA'.succ # => "AB"
|
3069
|
+
# 'AZ'.succ # => "BA"
|
3070
|
+
# 'ZZ'.succ # => "AAA"
|
3071
|
+
#
|
3072
|
+
# The successor to a non-alphanumeric character is the next character in the
|
3073
|
+
# underlying character set's collating sequence, carrying to the next-left
|
3074
|
+
# character for a rollover, and prepending another character if necessary:
|
3075
|
+
#
|
3076
|
+
# s = 0.chr * 3
|
3077
|
+
# s # => "\x00\x00\x00"
|
3078
|
+
# s.succ # => "\x00\x00\x01"
|
3079
|
+
# s = 255.chr * 3
|
3080
|
+
# s # => "\xFF\xFF\xFF"
|
3081
|
+
# s.succ # => "\x01\x00\x00\x00"
|
3082
|
+
#
|
3083
|
+
# Carrying can occur between and among mixtures of alphanumeric characters:
|
3084
|
+
#
|
3085
|
+
# s = 'zz99zz99'
|
3086
|
+
# s.succ # => "aaa00aa00"
|
3087
|
+
# s = '99zz99zz'
|
3088
|
+
# s.succ # => "100aa00aa"
|
3089
|
+
#
|
3090
|
+
# The successor to an empty `String` is a new empty `String`:
|
3091
|
+
#
|
3092
|
+
# ''.succ # => ""
|
3093
|
+
#
|
3094
|
+
def succ: () -> String
|
3095
|
+
|
3096
|
+
# <!--
|
3097
|
+
# rdoc-file=string.c
|
3098
|
+
# - succ! -> self
|
3099
|
+
# -->
|
3100
|
+
# Equivalent to String#succ, but modifies `self` in place; returns `self`.
|
3101
|
+
#
|
3102
|
+
def succ!: () -> self
|
3103
|
+
|
3104
|
+
# <!--
|
3105
|
+
# rdoc-file=string.c
|
3106
|
+
# - sum(n = 16) -> integer
|
3107
|
+
# -->
|
3108
|
+
# Returns a basic `n`-bit checksum of the characters in `self`; the checksum is
|
3109
|
+
# the sum of the binary value of each byte in `self`, modulo `2**n - 1`:
|
3110
|
+
#
|
3111
|
+
# 'hello'.sum # => 532
|
3112
|
+
# 'hello'.sum(4) # => 4
|
3113
|
+
# 'hello'.sum(64) # => 532
|
3114
|
+
# 'тест'.sum # => 1405
|
3115
|
+
# 'こんにちは'.sum # => 2582
|
3116
|
+
#
|
3117
|
+
# This is not a particularly strong checksum.
|
3118
|
+
#
|
3119
|
+
def sum: (?int bits) -> Integer
|
3120
|
+
|
3121
|
+
# <!--
|
3122
|
+
# rdoc-file=string.c
|
3123
|
+
# - swapcase(*options) -> string
|
3124
|
+
# -->
|
3125
|
+
# Returns a string containing the characters in `self`, with cases reversed;
|
3126
|
+
# each uppercase character is downcased; each lowercase character is upcased:
|
3127
|
+
#
|
3128
|
+
# s = 'Hello World!' # => "Hello World!"
|
3129
|
+
# s.swapcase # => "hELLO wORLD!"
|
3130
|
+
#
|
3131
|
+
# The casing may be affected by the given `options`; see [Case
|
3132
|
+
# Mapping](rdoc-ref:case_mapping.rdoc).
|
3133
|
+
#
|
3134
|
+
# Related: String#swapcase!.
|
3135
|
+
#
|
3136
|
+
def swapcase: () -> String
|
3137
|
+
| (:ascii | :lithuanian | :turkic) -> String
|
3138
|
+
| (:lithuanian, :turkic) -> String
|
3139
|
+
| (:turkic, :lithuanian) -> String
|
3140
|
+
|
3141
|
+
# <!--
|
3142
|
+
# rdoc-file=string.c
|
3143
|
+
# - swapcase!(*options) -> self or nil
|
3144
|
+
# -->
|
3145
|
+
# Upcases each lowercase character in `self`; downcases uppercase character;
|
3146
|
+
# returns `self` if any changes were made, `nil` otherwise:
|
3147
|
+
#
|
3148
|
+
# s = 'Hello World!' # => "Hello World!"
|
3149
|
+
# s.swapcase! # => "hELLO wORLD!"
|
3150
|
+
# s # => "hELLO wORLD!"
|
3151
|
+
# ''.swapcase! # => nil
|
3152
|
+
#
|
3153
|
+
# The casing may be affected by the given `options`; see [Case
|
3154
|
+
# Mapping](rdoc-ref:case_mapping.rdoc).
|
3155
|
+
#
|
3156
|
+
# Related: String#swapcase.
|
3157
|
+
#
|
3158
|
+
def swapcase!: () -> self?
|
3159
|
+
| (:ascii | :lithuanian | :turkic) -> self?
|
3160
|
+
| (:lithuanian, :turkic) -> self?
|
3161
|
+
| (:turkic, :lithuanian) -> self?
|
3162
|
+
|
3163
|
+
# <!--
|
3164
|
+
# rdoc-file=complex.c
|
3165
|
+
# - to_c -> complex
|
3166
|
+
# -->
|
3167
|
+
# Returns `self` interpreted as a Complex object; leading whitespace and
|
3168
|
+
# trailing garbage are ignored:
|
3169
|
+
#
|
3170
|
+
# '9'.to_c # => (9+0i)
|
3171
|
+
# '2.5'.to_c # => (2.5+0i)
|
3172
|
+
# '2.5/1'.to_c # => ((5/2)+0i)
|
3173
|
+
# '-3/2'.to_c # => ((-3/2)+0i)
|
3174
|
+
# '-i'.to_c # => (0-1i)
|
3175
|
+
# '45i'.to_c # => (0+45i)
|
3176
|
+
# '3-4i'.to_c # => (3-4i)
|
3177
|
+
# '-4e2-4e-2i'.to_c # => (-400.0-0.04i)
|
3178
|
+
# '-0.0-0.0i'.to_c # => (-0.0-0.0i)
|
3179
|
+
# '1/2+3/4i'.to_c # => ((1/2)+(3/4)*i)
|
3180
|
+
# '1.0@0'.to_c # => (1+0.0i)
|
3181
|
+
# "1.0@#{Math::PI/2}".to_c # => (0.0+1i)
|
3182
|
+
# "1.0@#{Math::PI}".to_c # => (-1+0.0i)
|
3183
|
+
#
|
3184
|
+
# Returns Complex zero if the string cannot be converted:
|
3185
|
+
#
|
3186
|
+
# 'ruby'.to_c # => (0+0i)
|
3187
|
+
#
|
3188
|
+
# See Kernel#Complex.
|
3189
|
+
#
|
3190
|
+
def to_c: () -> Complex
|
3191
|
+
|
3192
|
+
# <!--
|
3193
|
+
# rdoc-file=string.c
|
3194
|
+
# - to_f -> float
|
3195
|
+
# -->
|
3196
|
+
# Returns the result of interpreting leading characters in `self` as a Float:
|
3197
|
+
#
|
3198
|
+
# '3.14159'.to_f # => 3.14159
|
3199
|
+
# '1.234e-2'.to_f # => 0.01234
|
3200
|
+
#
|
3201
|
+
# Characters past a leading valid number (in the given `base`) are ignored:
|
3202
|
+
#
|
3203
|
+
# '3.14 (pi to two places)'.to_f # => 3.14
|
3204
|
+
#
|
3205
|
+
# Returns zero if there is no leading valid number:
|
3206
|
+
#
|
3207
|
+
# 'abcdef'.to_f # => 0.0
|
3208
|
+
#
|
3209
|
+
def to_f: () -> Float
|
3210
|
+
|
3211
|
+
# <!--
|
3212
|
+
# rdoc-file=string.c
|
3213
|
+
# - to_i(base = 10) -> integer
|
3214
|
+
# -->
|
3215
|
+
# Returns the result of interpreting leading characters in `self` as an integer
|
3216
|
+
# in the given `base` (which must be in (0, 2..36)):
|
3217
|
+
#
|
3218
|
+
# '123456'.to_i # => 123456
|
3219
|
+
# '123def'.to_i(16) # => 1195503
|
3220
|
+
#
|
3221
|
+
# With `base` zero, string `object` may contain leading characters to specify
|
3222
|
+
# the actual base:
|
3223
|
+
#
|
3224
|
+
# '123def'.to_i(0) # => 123
|
3225
|
+
# '0123def'.to_i(0) # => 83
|
3226
|
+
# '0b123def'.to_i(0) # => 1
|
3227
|
+
# '0o123def'.to_i(0) # => 83
|
3228
|
+
# '0d123def'.to_i(0) # => 123
|
3229
|
+
# '0x123def'.to_i(0) # => 1195503
|
3230
|
+
#
|
3231
|
+
# Characters past a leading valid number (in the given `base`) are ignored:
|
3232
|
+
#
|
3233
|
+
# '12.345'.to_i # => 12
|
3234
|
+
# '12345'.to_i(2) # => 1
|
3235
|
+
#
|
3236
|
+
# Returns zero if there is no leading valid number:
|
3237
|
+
#
|
3238
|
+
# 'abcdef'.to_i # => 0
|
3239
|
+
# '2'.to_i(2) # => 0
|
3240
|
+
#
|
3241
|
+
def to_i: (?int radix) -> Integer
|
3242
|
+
|
3243
|
+
# <!--
|
3244
|
+
# rdoc-file=rational.c
|
3245
|
+
# - str.to_r -> rational
|
3246
|
+
# -->
|
3247
|
+
# Returns the result of interpreting leading characters in `str` as a rational.
|
3248
|
+
# Leading whitespace and extraneous characters past the end of a valid number
|
3249
|
+
# are ignored. Digit sequences can be separated by an underscore. If there is
|
3250
|
+
# not a valid number at the start of `str`, zero is returned. This method never
|
3251
|
+
# raises an exception.
|
3252
|
+
#
|
3253
|
+
# ' 2 '.to_r #=> (2/1)
|
3254
|
+
# '300/2'.to_r #=> (150/1)
|
3255
|
+
# '-9.2'.to_r #=> (-46/5)
|
3256
|
+
# '-9.2e2'.to_r #=> (-920/1)
|
3257
|
+
# '1_234_567'.to_r #=> (1234567/1)
|
3258
|
+
# '21 June 09'.to_r #=> (21/1)
|
3259
|
+
# '21/06/09'.to_r #=> (7/2)
|
3260
|
+
# 'BWV 1079'.to_r #=> (0/1)
|
3261
|
+
#
|
3262
|
+
# NOTE: "0.3".to_r isn't the same as 0.3.to_r. The former is equivalent to
|
3263
|
+
# "3/10".to_r, but the latter isn't so.
|
3264
|
+
#
|
3265
|
+
# "0.3".to_r == 3/10r #=> true
|
3266
|
+
# 0.3.to_r == 3/10r #=> false
|
3267
|
+
#
|
3268
|
+
# See also Kernel#Rational.
|
3269
|
+
#
|
3270
|
+
def to_r: () -> Rational
|
3271
|
+
|
3272
|
+
# <!--
|
3273
|
+
# rdoc-file=string.c
|
3274
|
+
# - to_s -> self or string
|
3275
|
+
# -->
|
3276
|
+
# Returns `self` if `self` is a `String`, or `self` converted to a `String` if
|
3277
|
+
# `self` is a subclass of `String`.
|
3278
|
+
#
|
3279
|
+
def to_s: () -> String
|
3280
|
+
|
3281
|
+
# <!-- rdoc-file=string.c -->
|
3282
|
+
# Returns `self` if `self` is a `String`, or `self` converted to a `String` if
|
3283
|
+
# `self` is a subclass of `String`.
|
3284
|
+
#
|
3285
|
+
alias to_str to_s
|
3286
|
+
|
3287
|
+
# <!-- rdoc-file=string.c -->
|
3288
|
+
# Returns the `Symbol` corresponding to *str*, creating the symbol if it did not
|
3289
|
+
# previously exist. See Symbol#id2name.
|
3290
|
+
#
|
3291
|
+
# "Koala".intern #=> :Koala
|
3292
|
+
# s = 'cat'.to_sym #=> :cat
|
3293
|
+
# s == :cat #=> true
|
3294
|
+
# s = '@cat'.to_sym #=> :@cat
|
3295
|
+
# s == :@cat #=> true
|
3296
|
+
#
|
3297
|
+
# This can also be used to create symbols that cannot be represented using the
|
3298
|
+
# `:xxx` notation.
|
3299
|
+
#
|
3300
|
+
# 'cat and dog'.to_sym #=> :"cat and dog"
|
3301
|
+
#
|
3302
|
+
alias to_sym intern
|
3303
|
+
|
3304
|
+
# <!--
|
3305
|
+
# rdoc-file=string.c
|
3306
|
+
# - tr(selector, replacements) -> new_string
|
3307
|
+
# -->
|
3308
|
+
# Returns a copy of `self` with each character specified by string `selector`
|
3309
|
+
# translated to the corresponding character in string `replacements`. The
|
3310
|
+
# correspondence is *positional*:
|
3311
|
+
#
|
3312
|
+
# * Each occurrence of the first character specified by `selector` is
|
3313
|
+
# translated to the first character in `replacements`.
|
3314
|
+
# * Each occurrence of the second character specified by `selector` is
|
3315
|
+
# translated to the second character in `replacements`.
|
3316
|
+
# * And so on.
|
3317
|
+
#
|
3318
|
+
# Example:
|
3319
|
+
#
|
3320
|
+
# 'hello'.tr('el', 'ip') #=> "hippo"
|
3321
|
+
#
|
3322
|
+
# If `replacements` is shorter than `selector`, it is implicitly padded with its
|
3323
|
+
# own last character:
|
3324
|
+
#
|
3325
|
+
# 'hello'.tr('aeiou', '-') # => "h-ll-"
|
3326
|
+
# 'hello'.tr('aeiou', 'AA-') # => "hAll-"
|
3327
|
+
#
|
3328
|
+
# Arguments `selector` and `replacements` must be valid character selectors (see
|
3329
|
+
# [Character Selectors](rdoc-ref:character_selectors.rdoc)), and may use any of
|
3330
|
+
# its valid forms, including negation, ranges, and escaping:
|
3331
|
+
#
|
3332
|
+
# # Negation.
|
3333
|
+
# 'hello'.tr('^aeiou', '-') # => "-e--o"
|
3334
|
+
# # Ranges.
|
3335
|
+
# 'ibm'.tr('b-z', 'a-z') # => "hal"
|
3336
|
+
# # Escapes.
|
3337
|
+
# 'hel^lo'.tr('\^aeiou', '-') # => "h-l-l-" # Escaped leading caret.
|
3338
|
+
# 'i-b-m'.tr('b\-z', 'a-z') # => "ibabm" # Escaped embedded hyphen.
|
3339
|
+
# 'foo\\bar'.tr('ab\\', 'XYZ') # => "fooZYXr" # Escaped backslash.
|
3340
|
+
#
|
3341
|
+
def tr: (selector source, string relpacement) -> String
|
3342
|
+
|
3343
|
+
# <!--
|
3344
|
+
# rdoc-file=string.c
|
3345
|
+
# - tr!(selector, replacements) -> self or nil
|
3346
|
+
# -->
|
3347
|
+
# Like String#tr, but modifies `self` in place. Returns `self` if any changes
|
3348
|
+
# were made, `nil` otherwise.
|
3349
|
+
#
|
3350
|
+
def tr!: (selector source, string relpacement) -> self?
|
3351
|
+
|
3352
|
+
# <!--
|
3353
|
+
# rdoc-file=string.c
|
3354
|
+
# - tr_s(selector, replacements) -> string
|
3355
|
+
# -->
|
3356
|
+
# Like String#tr, but also squeezes the modified portions of the translated
|
3357
|
+
# string; returns a new string (translated and squeezed).
|
3358
|
+
#
|
3359
|
+
# 'hello'.tr_s('l', 'r') #=> "hero"
|
3360
|
+
# 'hello'.tr_s('el', '-') #=> "h-o"
|
3361
|
+
# 'hello'.tr_s('el', 'hx') #=> "hhxo"
|
3362
|
+
#
|
3363
|
+
# Related: String#squeeze.
|
3364
|
+
#
|
3365
|
+
def tr_s: (selector source, string replacement) -> String
|
3366
|
+
|
3367
|
+
# <!--
|
3368
|
+
# rdoc-file=string.c
|
3369
|
+
# - tr_s!(selector, replacements) -> self or nil
|
3370
|
+
# -->
|
3371
|
+
# Like String#tr_s, but modifies `self` in place. Returns `self` if any changes
|
3372
|
+
# were made, `nil` otherwise.
|
3373
|
+
#
|
3374
|
+
# Related: String#squeeze!.
|
3375
|
+
#
|
3376
|
+
def tr_s!: (selector source, string replacement) -> self?
|
3377
|
+
|
3378
|
+
# <!--
|
3379
|
+
# rdoc-file=string.c
|
3380
|
+
# - undump -> string
|
3381
|
+
# -->
|
3382
|
+
# Returns an unescaped version of `self`:
|
3383
|
+
#
|
3384
|
+
# s_orig = "\f\x00\xff\\\"" # => "\f\u0000\xFF\\\""
|
3385
|
+
# s_dumped = s_orig.dump # => "\"\\f\\x00\\xFF\\\\\\\"\""
|
3386
|
+
# s_undumped = s_dumped.undump # => "\f\u0000\xFF\\\""
|
3387
|
+
# s_undumped == s_orig # => true
|
3388
|
+
#
|
3389
|
+
# Related: String#dump (inverse of String#undump).
|
3390
|
+
#
|
3391
|
+
def undump: () -> String
|
3392
|
+
|
3393
|
+
# <!--
|
3394
|
+
# rdoc-file=string.c
|
3395
|
+
# - unicode_normalize(form = :nfc) -> string
|
3396
|
+
# -->
|
3397
|
+
# Returns a copy of `self` with [Unicode
|
3398
|
+
# normalization](https://unicode.org/reports/tr15) applied.
|
3399
|
+
#
|
3400
|
+
# Argument `form` must be one of the following symbols (see [Unicode
|
3401
|
+
# normalization forms](https://unicode.org/reports/tr15/#Norm_Forms)):
|
3402
|
+
#
|
3403
|
+
# * `:nfc`: Canonical decomposition, followed by canonical composition.
|
3404
|
+
# * `:nfd`: Canonical decomposition.
|
3405
|
+
# * `:nfkc`: Compatibility decomposition, followed by canonical composition.
|
3406
|
+
# * `:nfkd`: Compatibility decomposition.
|
3407
|
+
#
|
3408
|
+
# The encoding of `self` must be one of:
|
3409
|
+
#
|
3410
|
+
# * Encoding::UTF_8
|
3411
|
+
# * Encoding::UTF_16BE
|
3412
|
+
# * Encoding::UTF_16LE
|
3413
|
+
# * Encoding::UTF_32BE
|
3414
|
+
# * Encoding::UTF_32LE
|
3415
|
+
# * Encoding::GB18030
|
3416
|
+
# * Encoding::UCS_2BE
|
3417
|
+
# * Encoding::UCS_4BE
|
3418
|
+
#
|
3419
|
+
# Examples:
|
3420
|
+
#
|
3421
|
+
# "a\u0300".unicode_normalize # => "a"
|
3422
|
+
# "\u00E0".unicode_normalize(:nfd) # => "a "
|
3423
|
+
#
|
3424
|
+
# Related: String#unicode_normalize!, String#unicode_normalized?.
|
3425
|
+
#
|
3426
|
+
def unicode_normalize: (?:nfc | :nfd | :nfkc | :nfkd form) -> self
|
3427
|
+
|
3428
|
+
# <!--
|
3429
|
+
# rdoc-file=string.c
|
3430
|
+
# - unicode_normalize!(form = :nfc) -> self
|
3431
|
+
# -->
|
3432
|
+
# Like String#unicode_normalize, except that the normalization is performed on
|
3433
|
+
# `self`.
|
3434
|
+
#
|
3435
|
+
# Related String#unicode_normalized?.
|
3436
|
+
#
|
3437
|
+
def unicode_normalize!: (?:nfc | :nfd | :nfkc | :nfkd form) -> self
|
3438
|
+
|
3439
|
+
# <!--
|
3440
|
+
# rdoc-file=string.c
|
3441
|
+
# - unicode_normalized?(form = :nfc) -> true or false
|
3442
|
+
# -->
|
3443
|
+
# Returns `true` if `self` is in the given `form` of Unicode normalization,
|
3444
|
+
# `false` otherwise. The `form` must be one of `:nfc`, `:nfd`, `:nfkc`, or
|
3445
|
+
# `:nfkd`.
|
3446
|
+
#
|
3447
|
+
# Examples:
|
3448
|
+
#
|
3449
|
+
# "a\u0300".unicode_normalized? # => false
|
3450
|
+
# "a\u0300".unicode_normalized?(:nfd) # => true
|
3451
|
+
# "\u00E0".unicode_normalized? # => true
|
3452
|
+
# "\u00E0".unicode_normalized?(:nfd) # => false
|
3453
|
+
#
|
3454
|
+
# Raises an exception if `self` is not in a Unicode encoding:
|
3455
|
+
#
|
3456
|
+
# s = "\xE0".force_encoding('ISO-8859-1')
|
3457
|
+
# s.unicode_normalized? # Raises Encoding::CompatibilityError.
|
3458
|
+
#
|
3459
|
+
# Related: String#unicode_normalize, String#unicode_normalize!.
|
3460
|
+
#
|
3461
|
+
def unicode_normalized?: (?:nfc | :nfd | :nfkc | :nfkd) -> bool
|
3462
|
+
|
3463
|
+
# <!--
|
3464
|
+
# rdoc-file=pack.rb
|
3465
|
+
# - unpack(template, offset: 0, &block) -> array
|
3466
|
+
# -->
|
3467
|
+
# Extracts data from `self`.
|
3468
|
+
#
|
3469
|
+
# If `block` is not given, forming objects that become the elements of a new
|
3470
|
+
# array, and returns that array. Otherwise, yields each object.
|
3471
|
+
#
|
3472
|
+
# See [Packed Data](rdoc-ref:packed_data.rdoc).
|
3473
|
+
#
|
3474
|
+
def unpack: (string template, ?offset: int) -> Array[Integer | Float | String | nil]
|
3475
|
+
| (string template, ?offset: int) { (Integer | Float | String | nil value) -> void } -> nil
|
3476
|
+
|
3477
|
+
# <!--
|
3478
|
+
# rdoc-file=pack.rb
|
3479
|
+
# - unpack1(template, offset: 0) -> object
|
3480
|
+
# -->
|
3481
|
+
# Like String#unpack, but unpacks and returns only the first extracted object.
|
3482
|
+
# See [Packed Data](rdoc-ref:packed_data.rdoc).
|
3483
|
+
#
|
3484
|
+
def unpack1: (string template, ?offset: int) -> (Integer | Float | String)?
|
3485
|
+
|
3486
|
+
# <!--
|
3487
|
+
# rdoc-file=string.c
|
3488
|
+
# - upcase(*options) -> string
|
3489
|
+
# -->
|
3490
|
+
# Returns a string containing the upcased characters in `self`:
|
3491
|
+
#
|
3492
|
+
# s = 'Hello World!' # => "Hello World!"
|
3493
|
+
# s.upcase # => "HELLO WORLD!"
|
3494
|
+
#
|
3495
|
+
# The casing may be affected by the given `options`; see [Case
|
3496
|
+
# Mapping](rdoc-ref:case_mapping.rdoc).
|
3497
|
+
#
|
3498
|
+
# Related: String#upcase!, String#downcase, String#downcase!.
|
3499
|
+
#
|
3500
|
+
def upcase: () -> String
|
3501
|
+
| (:ascii | :lithuanian | :turkic) -> String
|
3502
|
+
| (:lithuanian, :turkic) -> String
|
3503
|
+
| (:turkic, :lithuanian) -> String
|
3504
|
+
|
3505
|
+
# <!--
|
3506
|
+
# rdoc-file=string.c
|
3507
|
+
# - upcase!(*options) -> self or nil
|
3508
|
+
# -->
|
3509
|
+
# Upcases the characters in `self`; returns `self` if any changes were made,
|
3510
|
+
# `nil` otherwise:
|
3511
|
+
#
|
3512
|
+
# s = 'Hello World!' # => "Hello World!"
|
3513
|
+
# s.upcase! # => "HELLO WORLD!"
|
3514
|
+
# s # => "HELLO WORLD!"
|
3515
|
+
# s.upcase! # => nil
|
3516
|
+
#
|
3517
|
+
# The casing may be affected by the given `options`; see [Case
|
3518
|
+
# Mapping](rdoc-ref:case_mapping.rdoc).
|
3519
|
+
#
|
3520
|
+
# Related: String#upcase, String#downcase, String#downcase!.
|
3521
|
+
#
|
3522
|
+
def upcase!: () -> self?
|
3523
|
+
| (:ascii | :lithuanian | :turkic) -> self?
|
3524
|
+
| (:lithuanian, :turkic) -> self?
|
3525
|
+
| (:turkic, :lithuanian) -> self?
|
3526
|
+
|
3527
|
+
# <!--
|
3528
|
+
# rdoc-file=string.c
|
3529
|
+
# - upto(other_string, exclusive = false) {|string| ... } -> self
|
3530
|
+
# - upto(other_string, exclusive = false) -> new_enumerator
|
3531
|
+
# -->
|
3532
|
+
# With a block given, calls the block with each `String` value returned by
|
3533
|
+
# successive calls to String#succ; the first value is `self`, the next is
|
3534
|
+
# `self.succ`, and so on; the sequence terminates when value `other_string` is
|
3535
|
+
# reached; returns `self`:
|
3536
|
+
#
|
3537
|
+
# 'a8'.upto('b6') {|s| print s, ' ' } # => "a8"
|
3538
|
+
#
|
3539
|
+
# Output:
|
3540
|
+
#
|
3541
|
+
# a8 a9 b0 b1 b2 b3 b4 b5 b6
|
3542
|
+
#
|
3543
|
+
# If argument `exclusive` is given as a truthy object, the last value is
|
3544
|
+
# omitted:
|
3545
|
+
#
|
3546
|
+
# 'a8'.upto('b6', true) {|s| print s, ' ' } # => "a8"
|
3547
|
+
#
|
3548
|
+
# Output:
|
3549
|
+
#
|
3550
|
+
# a8 a9 b0 b1 b2 b3 b4 b5
|
3551
|
+
#
|
3552
|
+
# If `other_string` would not be reached, does not call the block:
|
3553
|
+
#
|
3554
|
+
# '25'.upto('5') {|s| fail s }
|
3555
|
+
# 'aa'.upto('a') {|s| fail s }
|
3556
|
+
#
|
3557
|
+
# With no block given, returns a new Enumerator:
|
3558
|
+
#
|
3559
|
+
# 'a8'.upto('b6') # => #<Enumerator: "a8":upto("b6")>
|
3560
|
+
#
|
3561
|
+
def upto: (string other_string, ?boolish exclusive) -> Enumerator[String, self]
|
3562
|
+
| (string other_string, ?boolish exclusive) { (String s) -> void } -> self
|
3563
|
+
|
3564
|
+
# <!--
|
3565
|
+
# rdoc-file=string.c
|
3566
|
+
# - valid_encoding? -> true or false
|
3567
|
+
# -->
|
3568
|
+
# Returns `true` if `self` is encoded correctly, `false` otherwise:
|
3569
|
+
#
|
3570
|
+
# "\xc2\xa1".force_encoding("UTF-8").valid_encoding? # => true
|
3571
|
+
# "\xc2".force_encoding("UTF-8").valid_encoding? # => false
|
3572
|
+
# "\x80".force_encoding("UTF-8").valid_encoding? # => false
|
3573
|
+
#
|
3574
|
+
def valid_encoding?: () -> bool
|
3575
|
+
end
|
3576
|
+
|
3577
|
+
%a{steep:deprecated}
|
3578
|
+
interface _ArefFromStringToString
|
3579
|
+
def []: (String) -> String
|
3580
|
+
end
|
3581
|
+
|
3582
|
+
%a{steep:deprecated}
|
3583
|
+
type String::encode_fallback = Hash[String, String] | Proc | Method | _ArefFromStringToString
|