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/kernel.rbs
ADDED
@@ -0,0 +1,3096 @@
|
|
1
|
+
# <!-- rdoc-file=object.c -->
|
2
|
+
# The Kernel module is included by class Object, so its methods are available in
|
3
|
+
# every Ruby object.
|
4
|
+
#
|
5
|
+
# The Kernel instance methods are documented in class Object while the module
|
6
|
+
# methods are documented here. These methods are called without a receiver and
|
7
|
+
# thus can be called in functional form:
|
8
|
+
#
|
9
|
+
# sprintf "%.1f", 1.234 #=> "1.2"
|
10
|
+
#
|
11
|
+
# ## What's Here
|
12
|
+
#
|
13
|
+
# Module Kernel provides methods that are useful for:
|
14
|
+
#
|
15
|
+
# * [Converting](rdoc-ref:Kernel@Converting)
|
16
|
+
# * [Querying](rdoc-ref:Kernel@Querying)
|
17
|
+
# * [Exiting](rdoc-ref:Kernel@Exiting)
|
18
|
+
# * [Exceptions](rdoc-ref:Kernel@Exceptions)
|
19
|
+
# * [IO](rdoc-ref:Kernel@IO)
|
20
|
+
# * [Procs](rdoc-ref:Kernel@Procs)
|
21
|
+
# * [Tracing](rdoc-ref:Kernel@Tracing)
|
22
|
+
# * [Subprocesses](rdoc-ref:Kernel@Subprocesses)
|
23
|
+
# * [Loading](rdoc-ref:Kernel@Loading)
|
24
|
+
# * [Yielding](rdoc-ref:Kernel@Yielding)
|
25
|
+
# * [Random Values](rdoc-ref:Kernel@Random+Values)
|
26
|
+
# * [Other](rdoc-ref:Kernel@Other)
|
27
|
+
#
|
28
|
+
# ### Converting
|
29
|
+
#
|
30
|
+
# * #Array: Returns an Array based on the given argument.
|
31
|
+
# * #Complex: Returns a Complex based on the given arguments.
|
32
|
+
# * #Float: Returns a Float based on the given arguments.
|
33
|
+
# * #Hash: Returns a Hash based on the given argument.
|
34
|
+
# * #Integer: Returns an Integer based on the given arguments.
|
35
|
+
# * #Rational: Returns a Rational based on the given arguments.
|
36
|
+
# * #String: Returns a String based on the given argument.
|
37
|
+
#
|
38
|
+
# ### Querying
|
39
|
+
#
|
40
|
+
# * #__callee__: Returns the called name of the current method as a symbol.
|
41
|
+
# * #__dir__: Returns the path to the directory from which the current method
|
42
|
+
# is called.
|
43
|
+
# * #__method__: Returns the name of the current method as a symbol.
|
44
|
+
# * #autoload?: Returns the file to be loaded when the given module is
|
45
|
+
# referenced.
|
46
|
+
# * #binding: Returns a Binding for the context at the point of call.
|
47
|
+
# * #block_given?: Returns `true` if a block was passed to the calling method.
|
48
|
+
# * #caller: Returns the current execution stack as an array of strings.
|
49
|
+
# * #caller_locations: Returns the current execution stack as an array of
|
50
|
+
# Thread::Backtrace::Location objects.
|
51
|
+
# * #class: Returns the class of `self`.
|
52
|
+
# * #frozen?: Returns whether `self` is frozen.
|
53
|
+
# * #global_variables: Returns an array of global variables as symbols.
|
54
|
+
# * #local_variables: Returns an array of local variables as symbols.
|
55
|
+
# * #test: Performs specified tests on the given single file or pair of files.
|
56
|
+
#
|
57
|
+
# ### Exiting
|
58
|
+
#
|
59
|
+
# * #abort: Exits the current process after printing the given arguments.
|
60
|
+
# * #at_exit: Executes the given block when the process exits.
|
61
|
+
# * #exit: Exits the current process after calling any registered `at_exit`
|
62
|
+
# handlers.
|
63
|
+
# * #exit!: Exits the current process without calling any registered `at_exit`
|
64
|
+
# handlers.
|
65
|
+
#
|
66
|
+
# ### Exceptions
|
67
|
+
#
|
68
|
+
# * #catch: Executes the given block, possibly catching a thrown object.
|
69
|
+
# * #raise (aliased as #fail): Raises an exception based on the given
|
70
|
+
# arguments.
|
71
|
+
# * #throw: Returns from the active catch block waiting for the given tag.
|
72
|
+
#
|
73
|
+
# ### IO
|
74
|
+
#
|
75
|
+
# * ::pp: Prints the given objects in pretty form.
|
76
|
+
# * #gets: Returns and assigns to `$_` the next line from the current input.
|
77
|
+
# * #open: Creates an IO object connected to the given stream, file, or
|
78
|
+
# subprocess.
|
79
|
+
# * #p: Prints the given objects' inspect output to the standard output.
|
80
|
+
# * #print: Prints the given objects to standard output without a newline.
|
81
|
+
# * #printf: Prints the string resulting from applying the given format string
|
82
|
+
# to any additional arguments.
|
83
|
+
# * #putc: Equivalent to <tt.$stdout.putc(object)</tt> for the given object.
|
84
|
+
# * #puts: Equivalent to `$stdout.puts(*objects)` for the given objects.
|
85
|
+
# * #readline: Similar to #gets, but raises an exception at the end of file.
|
86
|
+
# * #readlines: Returns an array of the remaining lines from the current
|
87
|
+
# input.
|
88
|
+
# * #select: Same as IO.select.
|
89
|
+
#
|
90
|
+
# ### Procs
|
91
|
+
#
|
92
|
+
# * #lambda: Returns a lambda proc for the given block.
|
93
|
+
# * #proc: Returns a new Proc; equivalent to Proc.new.
|
94
|
+
#
|
95
|
+
# ### Tracing
|
96
|
+
#
|
97
|
+
# * #set_trace_func: Sets the given proc as the handler for tracing, or
|
98
|
+
# disables tracing if given `nil`.
|
99
|
+
# * #trace_var: Starts tracing assignments to the given global variable.
|
100
|
+
# * #untrace_var: Disables tracing of assignments to the given global
|
101
|
+
# variable.
|
102
|
+
#
|
103
|
+
# ### Subprocesses
|
104
|
+
#
|
105
|
+
# * [\`command`](rdoc-ref:Kernel#`): Returns the standard output of running
|
106
|
+
# `command` in a subshell.
|
107
|
+
# * #exec: Replaces current process with a new process.
|
108
|
+
# * #fork: Forks the current process into two processes.
|
109
|
+
# * #spawn: Executes the given command and returns its pid without waiting for
|
110
|
+
# completion.
|
111
|
+
# * #system: Executes the given command in a subshell.
|
112
|
+
#
|
113
|
+
# ### Loading
|
114
|
+
#
|
115
|
+
# * #autoload: Registers the given file to be loaded when the given constant
|
116
|
+
# is first referenced.
|
117
|
+
# * #load: Loads the given Ruby file.
|
118
|
+
# * #require: Loads the given Ruby file unless it has already been loaded.
|
119
|
+
# * #require_relative: Loads the Ruby file path relative to the calling file,
|
120
|
+
# unless it has already been loaded.
|
121
|
+
#
|
122
|
+
# ### Yielding
|
123
|
+
#
|
124
|
+
# * #tap: Yields `self` to the given block; returns `self`.
|
125
|
+
# * #then (aliased as #yield_self): Yields `self` to the block and returns the
|
126
|
+
# result of the block.
|
127
|
+
#
|
128
|
+
# ### Random Values
|
129
|
+
#
|
130
|
+
# * #rand: Returns a pseudo-random floating point number strictly between 0.0
|
131
|
+
# and 1.0.
|
132
|
+
# * #srand: Seeds the pseudo-random number generator with the given number.
|
133
|
+
#
|
134
|
+
# ### Other
|
135
|
+
#
|
136
|
+
# * #eval: Evaluates the given string as Ruby code.
|
137
|
+
# * #loop: Repeatedly executes the given block.
|
138
|
+
# * #sleep: Suspends the current thread for the given number of seconds.
|
139
|
+
# * #sprintf (aliased as #format): Returns the string resulting from applying
|
140
|
+
# the given format string to any additional arguments.
|
141
|
+
# * #syscall: Runs an operating system call.
|
142
|
+
# * #trap: Specifies the handling of system signals.
|
143
|
+
# * #warn: Issue a warning based on the given messages and options.
|
144
|
+
#
|
145
|
+
%a{annotate:rdoc:source:from=object.c}
|
146
|
+
module Kernel : BasicObject
|
147
|
+
# <!--
|
148
|
+
# rdoc-file=vm_backtrace.c
|
149
|
+
# - caller(start=1, length=nil) -> array or nil
|
150
|
+
# - caller(range) -> array or nil
|
151
|
+
# -->
|
152
|
+
# Returns the current execution stack---an array containing strings in the form
|
153
|
+
# `file:line` or `file:line: in `method'`.
|
154
|
+
#
|
155
|
+
# The optional *start* parameter determines the number of initial stack entries
|
156
|
+
# to omit from the top of the stack.
|
157
|
+
#
|
158
|
+
# A second optional `length` parameter can be used to limit how many entries are
|
159
|
+
# returned from the stack.
|
160
|
+
#
|
161
|
+
# Returns `nil` if *start* is greater than the size of current execution stack.
|
162
|
+
#
|
163
|
+
# Optionally you can pass a range, which will return an array containing the
|
164
|
+
# entries within the specified range.
|
165
|
+
#
|
166
|
+
# def a(skip)
|
167
|
+
# caller(skip)
|
168
|
+
# end
|
169
|
+
# def b(skip)
|
170
|
+
# a(skip)
|
171
|
+
# end
|
172
|
+
# def c(skip)
|
173
|
+
# b(skip)
|
174
|
+
# end
|
175
|
+
# c(0) #=> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10:in `<main>'"]
|
176
|
+
# c(1) #=> ["prog:5:in `b'", "prog:8:in `c'", "prog:11:in `<main>'"]
|
177
|
+
# c(2) #=> ["prog:8:in `c'", "prog:12:in `<main>'"]
|
178
|
+
# c(3) #=> ["prog:13:in `<main>'"]
|
179
|
+
# c(4) #=> []
|
180
|
+
# c(5) #=> nil
|
181
|
+
#
|
182
|
+
def self?.caller: (Integer start_or_range, ?Integer length) -> ::Array[String]?
|
183
|
+
| (::Range[Integer] start_or_range) -> ::Array[String]?
|
184
|
+
| () -> ::Array[String]
|
185
|
+
|
186
|
+
# <!--
|
187
|
+
# rdoc-file=vm_backtrace.c
|
188
|
+
# - caller_locations(start=1, length=nil) -> array or nil
|
189
|
+
# - caller_locations(range) -> array or nil
|
190
|
+
# -->
|
191
|
+
# Returns the current execution stack---an array containing backtrace location
|
192
|
+
# objects.
|
193
|
+
#
|
194
|
+
# See Thread::Backtrace::Location for more information.
|
195
|
+
#
|
196
|
+
# The optional *start* parameter determines the number of initial stack entries
|
197
|
+
# to omit from the top of the stack.
|
198
|
+
#
|
199
|
+
# A second optional `length` parameter can be used to limit how many entries are
|
200
|
+
# returned from the stack.
|
201
|
+
#
|
202
|
+
# Returns `nil` if *start* is greater than the size of current execution stack.
|
203
|
+
#
|
204
|
+
# Optionally you can pass a range, which will return an array containing the
|
205
|
+
# entries within the specified range.
|
206
|
+
#
|
207
|
+
def self?.caller_locations: (?Integer start_or_range, ?Integer length) -> ::Array[Thread::Backtrace::Location]?
|
208
|
+
| (?::Range[Integer] start_or_range) -> ::Array[Thread::Backtrace::Location]?
|
209
|
+
|
210
|
+
# <!--
|
211
|
+
# rdoc-file=vm_eval.c
|
212
|
+
# - catch([tag]) {|tag| block } -> obj
|
213
|
+
# -->
|
214
|
+
# `catch` executes its block. If `throw` is not called, the block executes
|
215
|
+
# normally, and `catch` returns the value of the last expression evaluated.
|
216
|
+
#
|
217
|
+
# catch(1) { 123 } # => 123
|
218
|
+
#
|
219
|
+
# If `throw(tag2, val)` is called, Ruby searches up its stack for a `catch`
|
220
|
+
# block whose `tag` has the same `object_id` as *tag2*. When found, the block
|
221
|
+
# stops executing and returns *val* (or `nil` if no second argument was given to
|
222
|
+
# `throw`).
|
223
|
+
#
|
224
|
+
# catch(1) { throw(1, 456) } # => 456
|
225
|
+
# catch(1) { throw(1) } # => nil
|
226
|
+
#
|
227
|
+
# When `tag` is passed as the first argument, `catch` yields it as the parameter
|
228
|
+
# of the block.
|
229
|
+
#
|
230
|
+
# catch(1) {|x| x + 2 } # => 3
|
231
|
+
#
|
232
|
+
# When no `tag` is given, `catch` yields a new unique object (as from
|
233
|
+
# `Object.new`) as the block parameter. This object can then be used as the
|
234
|
+
# argument to `throw`, and will match the correct `catch` block.
|
235
|
+
#
|
236
|
+
# catch do |obj_A|
|
237
|
+
# catch do |obj_B|
|
238
|
+
# throw(obj_B, 123)
|
239
|
+
# puts "This puts is not reached"
|
240
|
+
# end
|
241
|
+
#
|
242
|
+
# puts "This puts is displayed"
|
243
|
+
# 456
|
244
|
+
# end
|
245
|
+
#
|
246
|
+
# # => 456
|
247
|
+
#
|
248
|
+
# catch do |obj_A|
|
249
|
+
# catch do |obj_B|
|
250
|
+
# throw(obj_A, 123)
|
251
|
+
# puts "This puts is still not reached"
|
252
|
+
# end
|
253
|
+
#
|
254
|
+
# puts "Now this puts is also not reached"
|
255
|
+
# 456
|
256
|
+
# end
|
257
|
+
#
|
258
|
+
# # => 123
|
259
|
+
#
|
260
|
+
def self?.catch: [T] (T tag) { (T tag) -> untyped } -> untyped
|
261
|
+
| () { (Object tag) -> untyped } -> untyped
|
262
|
+
|
263
|
+
# <!--
|
264
|
+
# rdoc-file=kernel.rb
|
265
|
+
# - obj.class -> class
|
266
|
+
# -->
|
267
|
+
# Returns the class of *obj*. This method must always be called with an explicit
|
268
|
+
# receiver, as #class is also a reserved word in Ruby.
|
269
|
+
#
|
270
|
+
# 1.class #=> Integer
|
271
|
+
# self.class #=> Object
|
272
|
+
#
|
273
|
+
def class: () -> Class
|
274
|
+
|
275
|
+
# <!--
|
276
|
+
# rdoc-file=vm_eval.c
|
277
|
+
# - eval(string [, binding [, filename [,lineno]]]) -> obj
|
278
|
+
# -->
|
279
|
+
# Evaluates the Ruby expression(s) in *string*. If *binding* is given, which
|
280
|
+
# must be a Binding object, the evaluation is performed in its context. If the
|
281
|
+
# optional *filename* and *lineno* parameters are present, they will be used
|
282
|
+
# when reporting syntax errors.
|
283
|
+
#
|
284
|
+
# def get_binding(str)
|
285
|
+
# return binding
|
286
|
+
# end
|
287
|
+
# str = "hello"
|
288
|
+
# eval "str + ' Fred'" #=> "hello Fred"
|
289
|
+
# eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
|
290
|
+
#
|
291
|
+
def self?.eval: (string src, ?Binding? scope, ?string filename, ?int lineno) -> untyped
|
292
|
+
|
293
|
+
# <!--
|
294
|
+
# rdoc-file=vm_eval.c
|
295
|
+
# - block_given? -> true or false
|
296
|
+
# -->
|
297
|
+
# Returns `true` if `yield` would execute a block in the current context. The
|
298
|
+
# `iterator?` form is mildly deprecated.
|
299
|
+
#
|
300
|
+
# def try
|
301
|
+
# if block_given?
|
302
|
+
# yield
|
303
|
+
# else
|
304
|
+
# "no block"
|
305
|
+
# end
|
306
|
+
# end
|
307
|
+
# try #=> "no block"
|
308
|
+
# try { "hello" } #=> "hello"
|
309
|
+
# try do "hello" end #=> "hello"
|
310
|
+
#
|
311
|
+
def self?.block_given?: () -> bool
|
312
|
+
|
313
|
+
# <!--
|
314
|
+
# rdoc-file=vm_eval.c
|
315
|
+
# - local_variables -> array
|
316
|
+
# -->
|
317
|
+
# Returns the names of the current local variables.
|
318
|
+
#
|
319
|
+
# fred = 1
|
320
|
+
# for i in 1..10
|
321
|
+
# # ...
|
322
|
+
# end
|
323
|
+
# local_variables #=> [:fred, :i]
|
324
|
+
#
|
325
|
+
def self?.local_variables: () -> ::Array[Symbol]
|
326
|
+
|
327
|
+
# <!--
|
328
|
+
# rdoc-file=random.c
|
329
|
+
# - srand(number = Random.new_seed) -> old_seed
|
330
|
+
# -->
|
331
|
+
# Seeds the system pseudo-random number generator, with `number`. The previous
|
332
|
+
# seed value is returned.
|
333
|
+
#
|
334
|
+
# If `number` is omitted, seeds the generator using a source of entropy provided
|
335
|
+
# by the operating system, if available (/dev/urandom on Unix systems or the RSA
|
336
|
+
# cryptographic provider on Windows), which is then combined with the time, the
|
337
|
+
# process id, and a sequence number.
|
338
|
+
#
|
339
|
+
# srand may be used to ensure repeatable sequences of pseudo-random numbers
|
340
|
+
# between different runs of the program. By setting the seed to a known value,
|
341
|
+
# programs can be made deterministic during testing.
|
342
|
+
#
|
343
|
+
# srand 1234 # => 268519324636777531569100071560086917274
|
344
|
+
# [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
|
345
|
+
# [ rand(10), rand(1000) ] # => [4, 664]
|
346
|
+
# srand 1234 # => 1234
|
347
|
+
# [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
|
348
|
+
#
|
349
|
+
def self?.srand: (?int number) -> Integer
|
350
|
+
|
351
|
+
# <!--
|
352
|
+
# rdoc-file=process.c
|
353
|
+
# - Process.fork { ... } -> integer or nil
|
354
|
+
# - Process.fork -> integer or nil
|
355
|
+
# -->
|
356
|
+
# Creates a child process.
|
357
|
+
#
|
358
|
+
# With a block given, runs the block in the child process; on block exit, the
|
359
|
+
# child terminates with a status of zero:
|
360
|
+
#
|
361
|
+
# puts "Before the fork: #{Process.pid}"
|
362
|
+
# fork do
|
363
|
+
# puts "In the child process: #{Process.pid}"
|
364
|
+
# end # => 382141
|
365
|
+
# puts "After the fork: #{Process.pid}"
|
366
|
+
#
|
367
|
+
# Output:
|
368
|
+
#
|
369
|
+
# Before the fork: 420496
|
370
|
+
# After the fork: 420496
|
371
|
+
# In the child process: 420520
|
372
|
+
#
|
373
|
+
# With no block given, the `fork` call returns twice:
|
374
|
+
#
|
375
|
+
# * Once in the parent process, returning the pid of the child process.
|
376
|
+
# * Once in the child process, returning `nil`.
|
377
|
+
#
|
378
|
+
# Example:
|
379
|
+
#
|
380
|
+
# puts "This is the first line before the fork (pid #{Process.pid})"
|
381
|
+
# puts fork
|
382
|
+
# puts "This is the second line after the fork (pid #{Process.pid})"
|
383
|
+
#
|
384
|
+
# Output:
|
385
|
+
#
|
386
|
+
# This is the first line before the fork (pid 420199)
|
387
|
+
# 420223
|
388
|
+
# This is the second line after the fork (pid 420199)
|
389
|
+
#
|
390
|
+
# This is the second line after the fork (pid 420223)
|
391
|
+
#
|
392
|
+
# In either case, the child process may exit using Kernel.exit! to avoid the
|
393
|
+
# call to Kernel#at_exit.
|
394
|
+
#
|
395
|
+
# To avoid zombie processes, the parent process should call either:
|
396
|
+
#
|
397
|
+
# * Process.wait, to collect the termination statuses of its children.
|
398
|
+
# * Process.detach, to register disinterest in their status.
|
399
|
+
#
|
400
|
+
# The thread calling `fork` is the only thread in the created child process;
|
401
|
+
# `fork` doesn't copy other threads.
|
402
|
+
#
|
403
|
+
# Note that method `fork` is available on some platforms, but not on others:
|
404
|
+
#
|
405
|
+
# Process.respond_to?(:fork) # => true # Would be false on some.
|
406
|
+
#
|
407
|
+
# If not, you may use ::spawn instead of `fork`.
|
408
|
+
#
|
409
|
+
def self?.fork: () -> Integer?
|
410
|
+
| () { () -> void } -> Integer
|
411
|
+
|
412
|
+
# <!--
|
413
|
+
# rdoc-file=object.c
|
414
|
+
# - Array(object) -> object or new_array
|
415
|
+
# -->
|
416
|
+
# Returns an array converted from `object`.
|
417
|
+
#
|
418
|
+
# Tries to convert `object` to an array using `to_ary` first and `to_a` second:
|
419
|
+
#
|
420
|
+
# Array([0, 1, 2]) # => [0, 1, 2]
|
421
|
+
# Array({foo: 0, bar: 1}) # => [[:foo, 0], [:bar, 1]]
|
422
|
+
# Array(0..4) # => [0, 1, 2, 3, 4]
|
423
|
+
#
|
424
|
+
# Returns `object` in an array, `[object]`, if `object` cannot be converted:
|
425
|
+
#
|
426
|
+
# Array(:foo) # => [:foo]
|
427
|
+
#
|
428
|
+
def self?.Array: (nil) -> []
|
429
|
+
| [T] (array[T] | _ToA[T] array_like) -> Array[T]
|
430
|
+
| [T] (T ele) -> [T]
|
431
|
+
|
432
|
+
# <!--
|
433
|
+
# rdoc-file=complex.c
|
434
|
+
# - Complex(real, imag = 0, exception: true) -> complex or nil
|
435
|
+
# - Complex(s, exception: true) -> complex or nil
|
436
|
+
# -->
|
437
|
+
# Returns a new Complex object if the arguments are valid; otherwise raises an
|
438
|
+
# exception if `exception` is `true`; otherwise returns `nil`.
|
439
|
+
#
|
440
|
+
# With Numeric arguments `real` and `imag`, returns `Complex.rect(real, imag)`
|
441
|
+
# if the arguments are valid.
|
442
|
+
#
|
443
|
+
# With string argument `s`, returns a new Complex object if the argument is
|
444
|
+
# valid; the string may have:
|
445
|
+
#
|
446
|
+
# * One or two numeric substrings, each of which specifies a Complex, Float,
|
447
|
+
# Integer, Numeric, or Rational value, specifying [rectangular
|
448
|
+
# coordinates](rdoc-ref:Complex@Rectangular+Coordinates):
|
449
|
+
#
|
450
|
+
# * Sign-separated real and imaginary numeric substrings (with trailing
|
451
|
+
# character `'i'`):
|
452
|
+
#
|
453
|
+
# Complex('1+2i') # => (1+2i)
|
454
|
+
# Complex('+1+2i') # => (1+2i)
|
455
|
+
# Complex('+1-2i') # => (1-2i)
|
456
|
+
# Complex('-1+2i') # => (-1+2i)
|
457
|
+
# Complex('-1-2i') # => (-1-2i)
|
458
|
+
#
|
459
|
+
# * Real-only numeric string (without trailing character `'i'`):
|
460
|
+
#
|
461
|
+
# Complex('1') # => (1+0i)
|
462
|
+
# Complex('+1') # => (1+0i)
|
463
|
+
# Complex('-1') # => (-1+0i)
|
464
|
+
#
|
465
|
+
# * Imaginary-only numeric string (with trailing character `'i'`):
|
466
|
+
#
|
467
|
+
# Complex('1i') # => (0+1i)
|
468
|
+
# Complex('+1i') # => (0+1i)
|
469
|
+
# Complex('-1i') # => (0-1i)
|
470
|
+
#
|
471
|
+
# * At-sign separated real and imaginary rational substrings, each of which
|
472
|
+
# specifies a Rational value, specifying [polar
|
473
|
+
# coordinates](rdoc-ref:Complex@Polar+Coordinates):
|
474
|
+
#
|
475
|
+
# Complex('1/2@3/4') # => (0.36584443443691045+0.34081938001166706i)
|
476
|
+
# Complex('+1/2@+3/4') # => (0.36584443443691045+0.34081938001166706i)
|
477
|
+
# Complex('+1/2@-3/4') # => (0.36584443443691045-0.34081938001166706i)
|
478
|
+
# Complex('-1/2@+3/4') # => (-0.36584443443691045-0.34081938001166706i)
|
479
|
+
# Complex('-1/2@-3/4') # => (-0.36584443443691045+0.34081938001166706i)
|
480
|
+
#
|
481
|
+
def self?.Complex: (_ToC complex_like, ?exception: true) -> Complex
|
482
|
+
| (_ToC complex_like, exception: bool) -> Complex?
|
483
|
+
| (Numeric | String real, ?Numeric | String imag, ?exception: true) -> Complex
|
484
|
+
| (Numeric | String real, ?Numeric | String imag, exception: bool) -> Complex?
|
485
|
+
| (untyped, ?untyped, ?exception: bool) -> Complex?
|
486
|
+
|
487
|
+
# <!--
|
488
|
+
# rdoc-file=kernel.rb
|
489
|
+
# - Float(arg, exception: true) -> float or nil
|
490
|
+
# -->
|
491
|
+
# Returns *arg* converted to a float. Numeric types are converted directly, and
|
492
|
+
# with exception to String and `nil`, the rest are converted using *arg*`.to_f`.
|
493
|
+
# Converting a String with invalid characters will result in an ArgumentError.
|
494
|
+
# Converting `nil` generates a TypeError. Exceptions can be suppressed by
|
495
|
+
# passing `exception: false`.
|
496
|
+
#
|
497
|
+
# Float(1) #=> 1.0
|
498
|
+
# Float("123.456") #=> 123.456
|
499
|
+
# Float("123.0_badstring") #=> ArgumentError: invalid value for Float(): "123.0_badstring"
|
500
|
+
# Float(nil) #=> TypeError: can't convert nil into Float
|
501
|
+
# Float("123.0_badstring", exception: false) #=> nil
|
502
|
+
#
|
503
|
+
def self?.Float: (_ToF float_like, ?exception: true) -> Float
|
504
|
+
| (_ToF float_like, exception: bool) -> Float?
|
505
|
+
| (untyped, ?exception: bool) -> Float?
|
506
|
+
|
507
|
+
# <!--
|
508
|
+
# rdoc-file=object.c
|
509
|
+
# - Hash(object) -> object or new_hash
|
510
|
+
# -->
|
511
|
+
# Returns a hash converted from `object`.
|
512
|
+
#
|
513
|
+
# * If `object` is:
|
514
|
+
#
|
515
|
+
# * A hash, returns `object`.
|
516
|
+
# * An empty array or `nil`, returns an empty hash.
|
517
|
+
#
|
518
|
+
# * Otherwise, if `object.to_hash` returns a hash, returns that hash.
|
519
|
+
# * Otherwise, returns TypeError.
|
520
|
+
#
|
521
|
+
# Examples:
|
522
|
+
#
|
523
|
+
# Hash({foo: 0, bar: 1}) # => {:foo=>0, :bar=>1}
|
524
|
+
# Hash(nil) # => {}
|
525
|
+
# Hash([]) # => {}
|
526
|
+
#
|
527
|
+
def self?.Hash: [K, V] (nil | [] _empty) -> Hash[K, V]
|
528
|
+
| [K, V] (hash[K, V] hash_like) -> Hash[K, V]
|
529
|
+
|
530
|
+
# <!--
|
531
|
+
# rdoc-file=kernel.rb
|
532
|
+
# - Integer(object, base = 0, exception: true) -> integer or nil
|
533
|
+
# -->
|
534
|
+
# Returns an integer converted from `object`.
|
535
|
+
#
|
536
|
+
# Tries to convert `object` to an integer using `to_int` first and `to_i`
|
537
|
+
# second; see below for exceptions.
|
538
|
+
#
|
539
|
+
# With a non-zero `base`, `object` must be a string or convertible to a string.
|
540
|
+
#
|
541
|
+
# #### Numeric objects
|
542
|
+
#
|
543
|
+
# With an integer argument `object` given, returns `object`:
|
544
|
+
#
|
545
|
+
# Integer(1) # => 1
|
546
|
+
# Integer(-1) # => -1
|
547
|
+
#
|
548
|
+
# With a floating-point argument `object` given, returns `object` truncated to
|
549
|
+
# an integer:
|
550
|
+
#
|
551
|
+
# Integer(1.9) # => 1 # Rounds toward zero.
|
552
|
+
# Integer(-1.9) # => -1 # Rounds toward zero.
|
553
|
+
#
|
554
|
+
# #### String objects
|
555
|
+
#
|
556
|
+
# With a string argument `object` and zero `base` given, returns `object`
|
557
|
+
# converted to an integer in base 10:
|
558
|
+
#
|
559
|
+
# Integer('100') # => 100
|
560
|
+
# Integer('-100') # => -100
|
561
|
+
#
|
562
|
+
# With `base` zero, string `object` may contain leading characters to specify
|
563
|
+
# the actual base (radix indicator):
|
564
|
+
#
|
565
|
+
# Integer('0100') # => 64 # Leading '0' specifies base 8.
|
566
|
+
# Integer('0b100') # => 4 # Leading '0b' specifies base 2.
|
567
|
+
# Integer('0x100') # => 256 # Leading '0x' specifies base 16.
|
568
|
+
#
|
569
|
+
# With a positive `base` (in range 2..36) given, returns `object` converted to
|
570
|
+
# an integer in the given base:
|
571
|
+
#
|
572
|
+
# Integer('100', 2) # => 4
|
573
|
+
# Integer('100', 8) # => 64
|
574
|
+
# Integer('-100', 16) # => -256
|
575
|
+
#
|
576
|
+
# With a negative `base` (in range -36..-2) given, returns `object` converted to
|
577
|
+
# the radix indicator if it exists or `base`:
|
578
|
+
#
|
579
|
+
# Integer('0x100', -2) # => 256
|
580
|
+
# Integer('100', -2) # => 4
|
581
|
+
# Integer('0b100', -8) # => 4
|
582
|
+
# Integer('100', -8) # => 64
|
583
|
+
# Integer('0o100', -10) # => 64
|
584
|
+
# Integer('100', -10) # => 100
|
585
|
+
#
|
586
|
+
# `base` -1 is equivalent to the -10 case.
|
587
|
+
#
|
588
|
+
# When converting strings, surrounding whitespace and embedded underscores are
|
589
|
+
# allowed and ignored:
|
590
|
+
#
|
591
|
+
# Integer(' 100 ') # => 100
|
592
|
+
# Integer('-1_0_0', 16) # => -256
|
593
|
+
#
|
594
|
+
# #### Other classes
|
595
|
+
#
|
596
|
+
# Examples with `object` of various other classes:
|
597
|
+
#
|
598
|
+
# Integer(Rational(9, 10)) # => 0 # Rounds toward zero.
|
599
|
+
# Integer(Complex(2, 0)) # => 2 # Imaginary part must be zero.
|
600
|
+
# Integer(Time.now) # => 1650974042
|
601
|
+
#
|
602
|
+
# #### Keywords
|
603
|
+
#
|
604
|
+
# With the optional keyword argument `exception` given as `true` (the default):
|
605
|
+
#
|
606
|
+
# * Raises TypeError if `object` does not respond to `to_int` or `to_i`.
|
607
|
+
# * Raises TypeError if `object` is `nil`.
|
608
|
+
# * Raises ArgumentError if `object` is an invalid string.
|
609
|
+
#
|
610
|
+
# With `exception` given as `false`, an exception of any kind is suppressed and
|
611
|
+
# `nil` is returned.
|
612
|
+
#
|
613
|
+
def self?.Integer: (int | _ToI int_like, ?exception: true) -> Integer
|
614
|
+
| (int | _ToI int_like, exception: bool) -> Integer?
|
615
|
+
| (string str, int base, ?exception: true) -> Integer
|
616
|
+
| (string str, int base, exception: bool) -> Integer?
|
617
|
+
| (untyped, ?untyped, ?exception: bool) -> Integer?
|
618
|
+
|
619
|
+
# <!--
|
620
|
+
# rdoc-file=rational.c
|
621
|
+
# - Rational(x, y, exception: true) -> rational or nil
|
622
|
+
# - Rational(arg, exception: true) -> rational or nil
|
623
|
+
# -->
|
624
|
+
# Returns `x/y` or `arg` as a Rational.
|
625
|
+
#
|
626
|
+
# Rational(2, 3) #=> (2/3)
|
627
|
+
# Rational(5) #=> (5/1)
|
628
|
+
# Rational(0.5) #=> (1/2)
|
629
|
+
# Rational(0.3) #=> (5404319552844595/18014398509481984)
|
630
|
+
#
|
631
|
+
# Rational("2/3") #=> (2/3)
|
632
|
+
# Rational("0.3") #=> (3/10)
|
633
|
+
#
|
634
|
+
# Rational("10 cents") #=> ArgumentError
|
635
|
+
# Rational(nil) #=> TypeError
|
636
|
+
# Rational(1, nil) #=> TypeError
|
637
|
+
#
|
638
|
+
# Rational("10 cents", exception: false) #=> nil
|
639
|
+
#
|
640
|
+
# Syntax of the string form:
|
641
|
+
#
|
642
|
+
# string form = extra spaces , rational , extra spaces ;
|
643
|
+
# rational = [ sign ] , unsigned rational ;
|
644
|
+
# unsigned rational = numerator | numerator , "/" , denominator ;
|
645
|
+
# numerator = integer part | fractional part | integer part , fractional part ;
|
646
|
+
# denominator = digits ;
|
647
|
+
# integer part = digits ;
|
648
|
+
# fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ;
|
649
|
+
# sign = "-" | "+" ;
|
650
|
+
# digits = digit , { digit | "_" , digit } ;
|
651
|
+
# digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
|
652
|
+
# extra spaces = ? \s* ? ;
|
653
|
+
#
|
654
|
+
# See also String#to_r.
|
655
|
+
#
|
656
|
+
def self?.Rational: (int | _ToR rational_like, ?exception: true) -> Rational
|
657
|
+
| (int | _ToR rational_like, exception: bool) -> Rational?
|
658
|
+
| (int | _ToR numer, ?int | _ToR denom, ?exception: true) -> Rational
|
659
|
+
| (int | _ToR numer, ?int | _ToR denom, exception: bool) -> Rational?
|
660
|
+
| [T] (Numeric & _RationalDiv[T] numer, Numeric denom, ?exception: bool) -> T
|
661
|
+
| [T < Numeric] (T value, 1, ?exception: bool) -> T
|
662
|
+
| (untyped, ?untyped, ?exception: bool) -> Rational?
|
663
|
+
|
664
|
+
interface _RationalDiv[T]
|
665
|
+
def /: (Numeric) -> T
|
666
|
+
end
|
667
|
+
|
668
|
+
# <!--
|
669
|
+
# rdoc-file=object.c
|
670
|
+
# - String(object) -> object or new_string
|
671
|
+
# -->
|
672
|
+
# Returns a string converted from `object`.
|
673
|
+
#
|
674
|
+
# Tries to convert `object` to a string using `to_str` first and `to_s` second:
|
675
|
+
#
|
676
|
+
# String([0, 1, 2]) # => "[0, 1, 2]"
|
677
|
+
# String(0..5) # => "0..5"
|
678
|
+
# String({foo: 0, bar: 1}) # => "{foo: 0, bar: 1}"
|
679
|
+
#
|
680
|
+
# Raises `TypeError` if `object` cannot be converted to a string.
|
681
|
+
#
|
682
|
+
def self?.String: (string | _ToS string_like) -> String
|
683
|
+
|
684
|
+
# <!--
|
685
|
+
# rdoc-file=eval.c
|
686
|
+
# - __callee__ -> symbol
|
687
|
+
# -->
|
688
|
+
# Returns the called name of the current method as a Symbol. If called outside
|
689
|
+
# of a method, it returns `nil`.
|
690
|
+
#
|
691
|
+
def self?.__callee__: () -> Symbol?
|
692
|
+
|
693
|
+
# <!--
|
694
|
+
# rdoc-file=eval.c
|
695
|
+
# - __dir__ -> string
|
696
|
+
# -->
|
697
|
+
# Returns the canonicalized absolute path of the directory of the file from
|
698
|
+
# which this method is called. It means symlinks in the path is resolved. If
|
699
|
+
# `__FILE__` is `nil`, it returns `nil`. The return value equals to
|
700
|
+
# `File.dirname(File.realpath(__FILE__))`.
|
701
|
+
#
|
702
|
+
def self?.__dir__: () -> String?
|
703
|
+
|
704
|
+
# <!--
|
705
|
+
# rdoc-file=eval.c
|
706
|
+
# - __method__ -> symbol
|
707
|
+
# -->
|
708
|
+
# Returns the name at the definition of the current method as a Symbol. If
|
709
|
+
# called outside of a method, it returns `nil`.
|
710
|
+
#
|
711
|
+
def self?.__method__: () -> Symbol?
|
712
|
+
|
713
|
+
# <!--
|
714
|
+
# rdoc-file=io.c
|
715
|
+
# - `command` -> string
|
716
|
+
# -->
|
717
|
+
# Returns the `$stdout` output from running `command` in a subshell; sets global
|
718
|
+
# variable `$?` to the process status.
|
719
|
+
#
|
720
|
+
# This method has potential security vulnerabilities if called with untrusted
|
721
|
+
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
722
|
+
#
|
723
|
+
# Examples:
|
724
|
+
#
|
725
|
+
# $ `date` # => "Wed Apr 9 08:56:30 CDT 2003\n"
|
726
|
+
# $ `echo oops && exit 99` # => "oops\n"
|
727
|
+
# $ $? # => #<Process::Status: pid 17088 exit 99>
|
728
|
+
# $ $?.status # => 99>
|
729
|
+
#
|
730
|
+
# The built-in syntax `%x{...}` uses this method.
|
731
|
+
#
|
732
|
+
def self?.`: (String arg0) -> String
|
733
|
+
|
734
|
+
# <!--
|
735
|
+
# rdoc-file=process.c
|
736
|
+
# - abort
|
737
|
+
# - Process.abort(msg = nil)
|
738
|
+
# -->
|
739
|
+
# Terminates execution immediately, effectively by calling `Kernel.exit(false)`.
|
740
|
+
#
|
741
|
+
# If string argument `msg` is given, it is written to STDERR prior to
|
742
|
+
# termination; otherwise, if an exception was raised, prints its message and
|
743
|
+
# backtrace.
|
744
|
+
#
|
745
|
+
def self?.abort: (?string msg) -> bot
|
746
|
+
|
747
|
+
# <!--
|
748
|
+
# rdoc-file=eval_jump.c
|
749
|
+
# - at_exit { block } -> proc
|
750
|
+
# -->
|
751
|
+
# Converts *block* to a `Proc` object (and therefore binds it at the point of
|
752
|
+
# call) and registers it for execution when the program exits. If multiple
|
753
|
+
# handlers are registered, they are executed in reverse order of registration.
|
754
|
+
#
|
755
|
+
# def do_at_exit(str1)
|
756
|
+
# at_exit { print str1 }
|
757
|
+
# end
|
758
|
+
# at_exit { puts "cruel world" }
|
759
|
+
# do_at_exit("goodbye ")
|
760
|
+
# exit
|
761
|
+
#
|
762
|
+
# *produces:*
|
763
|
+
#
|
764
|
+
# goodbye cruel world
|
765
|
+
#
|
766
|
+
def self?.at_exit: () { () -> void } -> Proc
|
767
|
+
|
768
|
+
# <!--
|
769
|
+
# rdoc-file=load.c
|
770
|
+
# - autoload(const, filename) -> nil
|
771
|
+
# -->
|
772
|
+
# Registers *filename* to be loaded (using Kernel::require) the first time that
|
773
|
+
# *const* (which may be a String or a symbol) is accessed.
|
774
|
+
#
|
775
|
+
# autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
|
776
|
+
#
|
777
|
+
# If *const* is defined as autoload, the file name to be loaded is replaced with
|
778
|
+
# *filename*. If *const* is defined but not as autoload, does nothing.
|
779
|
+
#
|
780
|
+
def self?.autoload: (interned _module, String filename) -> NilClass
|
781
|
+
|
782
|
+
# <!--
|
783
|
+
# rdoc-file=load.c
|
784
|
+
# - autoload?(name, inherit=true) -> String or nil
|
785
|
+
# -->
|
786
|
+
# Returns *filename* to be loaded if *name* is registered as `autoload` in the
|
787
|
+
# current namespace or one of its ancestors.
|
788
|
+
#
|
789
|
+
# autoload(:B, "b")
|
790
|
+
# autoload?(:B) #=> "b"
|
791
|
+
#
|
792
|
+
# module C
|
793
|
+
# autoload(:D, "d")
|
794
|
+
# autoload?(:D) #=> "d"
|
795
|
+
# autoload?(:B) #=> nil
|
796
|
+
# end
|
797
|
+
#
|
798
|
+
# class E
|
799
|
+
# autoload(:F, "f")
|
800
|
+
# autoload?(:F) #=> "f"
|
801
|
+
# autoload?(:B) #=> "b"
|
802
|
+
# end
|
803
|
+
#
|
804
|
+
def self?.autoload?: (interned name) -> String?
|
805
|
+
|
806
|
+
# <!--
|
807
|
+
# rdoc-file=proc.c
|
808
|
+
# - binding -> a_binding
|
809
|
+
# -->
|
810
|
+
# Returns a Binding object, describing the variable and method bindings at the
|
811
|
+
# point of call. This object can be used when calling Binding#eval to execute
|
812
|
+
# the evaluated command in this environment, or extracting its local variables.
|
813
|
+
#
|
814
|
+
# class User
|
815
|
+
# def initialize(name, position)
|
816
|
+
# @name = name
|
817
|
+
# @position = position
|
818
|
+
# end
|
819
|
+
#
|
820
|
+
# def get_binding
|
821
|
+
# binding
|
822
|
+
# end
|
823
|
+
# end
|
824
|
+
#
|
825
|
+
# user = User.new('Joan', 'manager')
|
826
|
+
# template = '{name: @name, position: @position}'
|
827
|
+
#
|
828
|
+
# # evaluate template in context of the object
|
829
|
+
# eval(template, user.get_binding)
|
830
|
+
# #=> {:name=>"Joan", :position=>"manager"}
|
831
|
+
#
|
832
|
+
# Binding#local_variable_get can be used to access the variables whose names are
|
833
|
+
# reserved Ruby keywords:
|
834
|
+
#
|
835
|
+
# # This is valid parameter declaration, but `if` parameter can't
|
836
|
+
# # be accessed by name, because it is a reserved word.
|
837
|
+
# def validate(field, validation, if: nil)
|
838
|
+
# condition = binding.local_variable_get('if')
|
839
|
+
# return unless condition
|
840
|
+
#
|
841
|
+
# # ...Some implementation ...
|
842
|
+
# end
|
843
|
+
#
|
844
|
+
# validate(:name, :empty?, if: false) # skips validation
|
845
|
+
# validate(:name, :empty?, if: true) # performs validation
|
846
|
+
#
|
847
|
+
def self?.binding: () -> Binding
|
848
|
+
|
849
|
+
# <!--
|
850
|
+
# rdoc-file=process.c
|
851
|
+
# - exit(status = true)
|
852
|
+
# - Process.exit(status = true)
|
853
|
+
# -->
|
854
|
+
# Initiates termination of the Ruby script by raising SystemExit; the exception
|
855
|
+
# may be caught. Returns exit status `status` to the underlying operating
|
856
|
+
# system.
|
857
|
+
#
|
858
|
+
# Values `true` and `false` for argument `status` indicate, respectively,
|
859
|
+
# success and failure; The meanings of integer values are system-dependent.
|
860
|
+
#
|
861
|
+
# Example:
|
862
|
+
#
|
863
|
+
# begin
|
864
|
+
# exit
|
865
|
+
# puts 'Never get here.'
|
866
|
+
# rescue SystemExit
|
867
|
+
# puts 'Rescued a SystemExit exception.'
|
868
|
+
# end
|
869
|
+
# puts 'After begin block.'
|
870
|
+
#
|
871
|
+
# Output:
|
872
|
+
#
|
873
|
+
# Rescued a SystemExit exception.
|
874
|
+
# After begin block.
|
875
|
+
#
|
876
|
+
# Just prior to final termination, Ruby executes any at-exit procedures (see
|
877
|
+
# Kernel::at_exit) and any object finalizers (see
|
878
|
+
# ObjectSpace::define_finalizer).
|
879
|
+
#
|
880
|
+
# Example:
|
881
|
+
#
|
882
|
+
# at_exit { puts 'In at_exit function.' }
|
883
|
+
# ObjectSpace.define_finalizer('string', proc { puts 'In finalizer.' })
|
884
|
+
# exit
|
885
|
+
#
|
886
|
+
# Output:
|
887
|
+
#
|
888
|
+
# In at_exit function.
|
889
|
+
# In finalizer.
|
890
|
+
#
|
891
|
+
def self?.exit: (?int | bool status) -> bot
|
892
|
+
|
893
|
+
# <!--
|
894
|
+
# rdoc-file=process.c
|
895
|
+
# - exit!(status = false)
|
896
|
+
# - Process.exit!(status = false)
|
897
|
+
# -->
|
898
|
+
# Exits the process immediately; no exit handlers are called. Returns exit
|
899
|
+
# status `status` to the underlying operating system.
|
900
|
+
#
|
901
|
+
# Process.exit!(true)
|
902
|
+
#
|
903
|
+
# Values `true` and `false` for argument `status` indicate, respectively,
|
904
|
+
# success and failure; The meanings of integer values are system-dependent.
|
905
|
+
#
|
906
|
+
def self?.exit!: (?int | bool status) -> bot
|
907
|
+
|
908
|
+
# <!-- rdoc-file=eval.c -->
|
909
|
+
# Raises an exception; see [Exceptions](rdoc-ref:exceptions.md).
|
910
|
+
#
|
911
|
+
# Argument `exception` sets the class of the new exception; it should be class
|
912
|
+
# Exception or one of its subclasses (most commonly, RuntimeError or
|
913
|
+
# StandardError), or an instance of one of those classes:
|
914
|
+
#
|
915
|
+
# begin
|
916
|
+
# raise(StandardError)
|
917
|
+
# rescue => x
|
918
|
+
# p x.class
|
919
|
+
# end
|
920
|
+
# # => StandardError
|
921
|
+
#
|
922
|
+
# Argument `message` sets the stored message in the new exception, which may be
|
923
|
+
# retrieved by method Exception#message; the message must be a
|
924
|
+
# [string-convertible
|
925
|
+
# object](rdoc-ref:implicit_conversion.rdoc@String-Convertible+Objects) or
|
926
|
+
# `nil`:
|
927
|
+
#
|
928
|
+
# begin
|
929
|
+
# raise(StandardError, 'Boom')
|
930
|
+
# rescue => x
|
931
|
+
# p x.message
|
932
|
+
# end
|
933
|
+
# # => "Boom"
|
934
|
+
#
|
935
|
+
# If argument `message` is not given, the message is the exception class name.
|
936
|
+
#
|
937
|
+
# See [Messages](rdoc-ref:exceptions.md@Messages).
|
938
|
+
#
|
939
|
+
# Argument `backtrace` might be used to modify the backtrace of the new
|
940
|
+
# exception, as reported by Exception#backtrace and
|
941
|
+
# Exception#backtrace_locations; the backtrace must be an array of
|
942
|
+
# Thread::Backtrace::Location, an array of strings, a single string, or `nil`.
|
943
|
+
#
|
944
|
+
# Using the array of Thread::Backtrace::Location instances is the most
|
945
|
+
# consistent option and should be preferred when possible. The necessary value
|
946
|
+
# might be obtained from #caller_locations, or copied from
|
947
|
+
# Exception#backtrace_locations of another error:
|
948
|
+
#
|
949
|
+
# begin
|
950
|
+
# do_some_work()
|
951
|
+
# rescue ZeroDivisionError => ex
|
952
|
+
# raise(LogicalError, "You have an error in your math", ex.backtrace_locations)
|
953
|
+
# end
|
954
|
+
#
|
955
|
+
# The ways, both Exception#backtrace and Exception#backtrace_locations of the
|
956
|
+
# raised error are set to the same backtrace.
|
957
|
+
#
|
958
|
+
# When the desired stack of locations is not available and should be constructed
|
959
|
+
# from scratch, an array of strings or a singular string can be used. In this
|
960
|
+
# case, only Exception#backtrace is set:
|
961
|
+
#
|
962
|
+
# begin
|
963
|
+
# raise(StandardError, 'Boom', %w[dsl.rb:3 framework.rb:1])
|
964
|
+
# rescue => ex
|
965
|
+
# p ex.backtrace
|
966
|
+
# # => ["dsl.rb:3", "framework.rb:1"]
|
967
|
+
# p ex.backtrace_locations
|
968
|
+
# # => nil
|
969
|
+
# end
|
970
|
+
#
|
971
|
+
# If argument `backtrace` is not given, the backtrace is set according to an
|
972
|
+
# array of Thread::Backtrace::Location objects, as derived from the call stack.
|
973
|
+
#
|
974
|
+
# See [Backtraces](rdoc-ref:exceptions.md@Backtraces).
|
975
|
+
#
|
976
|
+
# Keyword argument `cause` sets the stored cause in the new exception, which may
|
977
|
+
# be retrieved by method Exception#cause; the cause must be an exception object
|
978
|
+
# (Exception or one of its subclasses), or `nil`:
|
979
|
+
#
|
980
|
+
# begin
|
981
|
+
# raise(StandardError, cause: RuntimeError.new)
|
982
|
+
# rescue => x
|
983
|
+
# p x.cause
|
984
|
+
# end
|
985
|
+
# # => #<RuntimeError: RuntimeError>
|
986
|
+
#
|
987
|
+
# If keyword argument `cause` is not given, the cause is the value of `$!`.
|
988
|
+
#
|
989
|
+
# See [Cause](rdoc-ref:exceptions.md@Cause).
|
990
|
+
#
|
991
|
+
# In the alternate calling sequence, where argument `exception` *not* given,
|
992
|
+
# raises a new exception of the class given by `$!`, or of class RuntimeError if
|
993
|
+
# `$!` is `nil`:
|
994
|
+
#
|
995
|
+
# begin
|
996
|
+
# raise
|
997
|
+
# rescue => x
|
998
|
+
# p x
|
999
|
+
# end
|
1000
|
+
# # => RuntimeError
|
1001
|
+
#
|
1002
|
+
# With argument `exception` not given, argument `message` and keyword argument
|
1003
|
+
# `cause` may be given, but argument `backtrace` may not be given.
|
1004
|
+
#
|
1005
|
+
def self?.fail: () -> bot
|
1006
|
+
| (string message, ?cause: Exception?) -> bot
|
1007
|
+
| (_Exception exception, ?_ToS? message, ?String | Array[String] | Array[Thread::Backtrace::Location] | nil backtrace, ?cause: Exception?) -> bot
|
1008
|
+
| (_Exception exception, ?cause: Exception?, **untyped) -> bot
|
1009
|
+
|
1010
|
+
# <!--
|
1011
|
+
# rdoc-file=eval.c
|
1012
|
+
# - raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
|
1013
|
+
# - raise(message = nil, cause: $!)
|
1014
|
+
# -->
|
1015
|
+
# Raises an exception; see [Exceptions](rdoc-ref:exceptions.md).
|
1016
|
+
#
|
1017
|
+
# Argument `exception` sets the class of the new exception; it should be class
|
1018
|
+
# Exception or one of its subclasses (most commonly, RuntimeError or
|
1019
|
+
# StandardError), or an instance of one of those classes:
|
1020
|
+
#
|
1021
|
+
# begin
|
1022
|
+
# raise(StandardError)
|
1023
|
+
# rescue => x
|
1024
|
+
# p x.class
|
1025
|
+
# end
|
1026
|
+
# # => StandardError
|
1027
|
+
#
|
1028
|
+
# Argument `message` sets the stored message in the new exception, which may be
|
1029
|
+
# retrieved by method Exception#message; the message must be a
|
1030
|
+
# [string-convertible
|
1031
|
+
# object](rdoc-ref:implicit_conversion.rdoc@String-Convertible+Objects) or
|
1032
|
+
# `nil`:
|
1033
|
+
#
|
1034
|
+
# begin
|
1035
|
+
# raise(StandardError, 'Boom')
|
1036
|
+
# rescue => x
|
1037
|
+
# p x.message
|
1038
|
+
# end
|
1039
|
+
# # => "Boom"
|
1040
|
+
#
|
1041
|
+
# If argument `message` is not given, the message is the exception class name.
|
1042
|
+
#
|
1043
|
+
# See [Messages](rdoc-ref:exceptions.md@Messages).
|
1044
|
+
#
|
1045
|
+
# Argument `backtrace` might be used to modify the backtrace of the new
|
1046
|
+
# exception, as reported by Exception#backtrace and
|
1047
|
+
# Exception#backtrace_locations; the backtrace must be an array of
|
1048
|
+
# Thread::Backtrace::Location, an array of strings, a single string, or `nil`.
|
1049
|
+
#
|
1050
|
+
# Using the array of Thread::Backtrace::Location instances is the most
|
1051
|
+
# consistent option and should be preferred when possible. The necessary value
|
1052
|
+
# might be obtained from #caller_locations, or copied from
|
1053
|
+
# Exception#backtrace_locations of another error:
|
1054
|
+
#
|
1055
|
+
# begin
|
1056
|
+
# do_some_work()
|
1057
|
+
# rescue ZeroDivisionError => ex
|
1058
|
+
# raise(LogicalError, "You have an error in your math", ex.backtrace_locations)
|
1059
|
+
# end
|
1060
|
+
#
|
1061
|
+
# The ways, both Exception#backtrace and Exception#backtrace_locations of the
|
1062
|
+
# raised error are set to the same backtrace.
|
1063
|
+
#
|
1064
|
+
# When the desired stack of locations is not available and should be constructed
|
1065
|
+
# from scratch, an array of strings or a singular string can be used. In this
|
1066
|
+
# case, only Exception#backtrace is set:
|
1067
|
+
#
|
1068
|
+
# begin
|
1069
|
+
# raise(StandardError, 'Boom', %w[dsl.rb:3 framework.rb:1])
|
1070
|
+
# rescue => ex
|
1071
|
+
# p ex.backtrace
|
1072
|
+
# # => ["dsl.rb:3", "framework.rb:1"]
|
1073
|
+
# p ex.backtrace_locations
|
1074
|
+
# # => nil
|
1075
|
+
# end
|
1076
|
+
#
|
1077
|
+
# If argument `backtrace` is not given, the backtrace is set according to an
|
1078
|
+
# array of Thread::Backtrace::Location objects, as derived from the call stack.
|
1079
|
+
#
|
1080
|
+
# See [Backtraces](rdoc-ref:exceptions.md@Backtraces).
|
1081
|
+
#
|
1082
|
+
# Keyword argument `cause` sets the stored cause in the new exception, which may
|
1083
|
+
# be retrieved by method Exception#cause; the cause must be an exception object
|
1084
|
+
# (Exception or one of its subclasses), or `nil`:
|
1085
|
+
#
|
1086
|
+
# begin
|
1087
|
+
# raise(StandardError, cause: RuntimeError.new)
|
1088
|
+
# rescue => x
|
1089
|
+
# p x.cause
|
1090
|
+
# end
|
1091
|
+
# # => #<RuntimeError: RuntimeError>
|
1092
|
+
#
|
1093
|
+
# If keyword argument `cause` is not given, the cause is the value of `$!`.
|
1094
|
+
#
|
1095
|
+
# See [Cause](rdoc-ref:exceptions.md@Cause).
|
1096
|
+
#
|
1097
|
+
# In the alternate calling sequence, where argument `exception` *not* given,
|
1098
|
+
# raises a new exception of the class given by `$!`, or of class RuntimeError if
|
1099
|
+
# `$!` is `nil`:
|
1100
|
+
#
|
1101
|
+
# begin
|
1102
|
+
# raise
|
1103
|
+
# rescue => x
|
1104
|
+
# p x
|
1105
|
+
# end
|
1106
|
+
# # => RuntimeError
|
1107
|
+
#
|
1108
|
+
# With argument `exception` not given, argument `message` and keyword argument
|
1109
|
+
# `cause` may be given, but argument `backtrace` may not be given.
|
1110
|
+
#
|
1111
|
+
alias raise fail
|
1112
|
+
|
1113
|
+
alias self.raise self.fail
|
1114
|
+
|
1115
|
+
# <!-- rdoc-file=object.c -->
|
1116
|
+
# Returns the string resulting from formatting `objects` into `format_string`.
|
1117
|
+
#
|
1118
|
+
# For details on `format_string`, see [Format
|
1119
|
+
# Specifications](rdoc-ref:format_specifications.rdoc).
|
1120
|
+
#
|
1121
|
+
def self?.format: (String format, *untyped args) -> String
|
1122
|
+
|
1123
|
+
# <!--
|
1124
|
+
# rdoc-file=object.c
|
1125
|
+
# - sprintf(format_string *objects) -> string
|
1126
|
+
# -->
|
1127
|
+
# Returns the string resulting from formatting `objects` into `format_string`.
|
1128
|
+
#
|
1129
|
+
# For details on `format_string`, see [Format
|
1130
|
+
# Specifications](rdoc-ref:format_specifications.rdoc).
|
1131
|
+
#
|
1132
|
+
alias sprintf format
|
1133
|
+
|
1134
|
+
alias self.sprintf self.format
|
1135
|
+
|
1136
|
+
# <!--
|
1137
|
+
# rdoc-file=io.c
|
1138
|
+
# - gets(sep=$/ [, getline_args]) -> string or nil
|
1139
|
+
# - gets(limit [, getline_args]) -> string or nil
|
1140
|
+
# - gets(sep, limit [, getline_args]) -> string or nil
|
1141
|
+
# -->
|
1142
|
+
# Returns (and assigns to `$_`) the next line from the list of files in `ARGV`
|
1143
|
+
# (or `$*`), or from standard input if no files are present on the command line.
|
1144
|
+
# Returns `nil` at end of file. The optional argument specifies the record
|
1145
|
+
# separator. The separator is included with the contents of each record. A
|
1146
|
+
# separator of `nil` reads the entire contents, and a zero-length separator
|
1147
|
+
# reads the input one paragraph at a time, where paragraphs are divided by two
|
1148
|
+
# consecutive newlines. If the first argument is an integer, or optional second
|
1149
|
+
# argument is given, the returning string would not be longer than the given
|
1150
|
+
# value in bytes. If multiple filenames are present in `ARGV`, `gets(nil)` will
|
1151
|
+
# read the contents one file at a time.
|
1152
|
+
#
|
1153
|
+
# ARGV << "testfile"
|
1154
|
+
# print while gets
|
1155
|
+
#
|
1156
|
+
# *produces:*
|
1157
|
+
#
|
1158
|
+
# This is line one
|
1159
|
+
# This is line two
|
1160
|
+
# This is line three
|
1161
|
+
# And so on...
|
1162
|
+
#
|
1163
|
+
# The style of programming using `$_` as an implicit parameter is gradually
|
1164
|
+
# losing favor in the Ruby community.
|
1165
|
+
#
|
1166
|
+
def self?.gets: (?String arg0, ?Integer arg1) -> String?
|
1167
|
+
|
1168
|
+
# <!--
|
1169
|
+
# rdoc-file=eval.c
|
1170
|
+
# - global_variables -> array
|
1171
|
+
# -->
|
1172
|
+
# Returns an array of the names of global variables. This includes special
|
1173
|
+
# regexp global variables such as `$~` and `$+`, but does not include the
|
1174
|
+
# numbered regexp global variables (`$1`, `$2`, etc.).
|
1175
|
+
#
|
1176
|
+
# global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
|
1177
|
+
#
|
1178
|
+
def self?.global_variables: () -> ::Array[Symbol]
|
1179
|
+
|
1180
|
+
# <!--
|
1181
|
+
# rdoc-file=load.c
|
1182
|
+
# - load(filename, wrap=false) -> true
|
1183
|
+
# -->
|
1184
|
+
# Loads and executes the Ruby program in the file *filename*.
|
1185
|
+
#
|
1186
|
+
# If the filename is an absolute path (e.g. starts with '/'), the file will be
|
1187
|
+
# loaded directly using the absolute path.
|
1188
|
+
#
|
1189
|
+
# If the filename is an explicit relative path (e.g. starts with './' or '../'),
|
1190
|
+
# the file will be loaded using the relative path from the current directory.
|
1191
|
+
#
|
1192
|
+
# Otherwise, the file will be searched for in the library directories listed in
|
1193
|
+
# `$LOAD_PATH` (`$:`). If the file is found in a directory, it will attempt to
|
1194
|
+
# load the file relative to that directory. If the file is not found in any of
|
1195
|
+
# the directories in `$LOAD_PATH`, the file will be loaded using the relative
|
1196
|
+
# path from the current directory.
|
1197
|
+
#
|
1198
|
+
# If the file doesn't exist when there is an attempt to load it, a LoadError
|
1199
|
+
# will be raised.
|
1200
|
+
#
|
1201
|
+
# If the optional *wrap* parameter is `true`, the loaded script will be executed
|
1202
|
+
# under an anonymous module. If the optional *wrap* parameter is a module, the
|
1203
|
+
# loaded script will be executed under the given module. In no circumstance will
|
1204
|
+
# any local variables in the loaded file be propagated to the loading
|
1205
|
+
# environment.
|
1206
|
+
#
|
1207
|
+
def self?.load: (String filename, ?Module | bool) -> bool
|
1208
|
+
|
1209
|
+
# <!--
|
1210
|
+
# rdoc-file=kernel.rb
|
1211
|
+
# - loop { block }
|
1212
|
+
# - loop -> an_enumerator
|
1213
|
+
# -->
|
1214
|
+
# Repeatedly executes the block.
|
1215
|
+
#
|
1216
|
+
# If no block is given, an enumerator is returned instead.
|
1217
|
+
#
|
1218
|
+
# loop do
|
1219
|
+
# print "Input: "
|
1220
|
+
# line = gets
|
1221
|
+
# break if !line or line =~ /^q/i
|
1222
|
+
# # ...
|
1223
|
+
# end
|
1224
|
+
#
|
1225
|
+
# A StopIteration raised in the block breaks the loop. In this case, loop
|
1226
|
+
# returns the "result" value stored in the exception.
|
1227
|
+
#
|
1228
|
+
# enum = Enumerator.new { |y|
|
1229
|
+
# y << "one"
|
1230
|
+
# y << "two"
|
1231
|
+
# :ok
|
1232
|
+
# }
|
1233
|
+
#
|
1234
|
+
# result = loop {
|
1235
|
+
# puts enum.next
|
1236
|
+
# } #=> :ok
|
1237
|
+
#
|
1238
|
+
def self?.loop: () { () -> void } -> bot
|
1239
|
+
| () -> ::Enumerator[nil, bot]
|
1240
|
+
|
1241
|
+
# <!--
|
1242
|
+
# rdoc-file=io.c
|
1243
|
+
# - open(path, mode = 'r', perm = 0666, **opts) -> io or nil
|
1244
|
+
# - open(path, mode = 'r', perm = 0666, **opts) {|io| ... } -> obj
|
1245
|
+
# -->
|
1246
|
+
# Creates an IO object connected to the given file.
|
1247
|
+
#
|
1248
|
+
# This method has potential security vulnerabilities if called with untrusted
|
1249
|
+
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
1250
|
+
#
|
1251
|
+
# With no block given, file stream is returned:
|
1252
|
+
#
|
1253
|
+
# open('t.txt') # => #<File:t.txt>
|
1254
|
+
#
|
1255
|
+
# With a block given, calls the block with the open file stream, then closes the
|
1256
|
+
# stream:
|
1257
|
+
#
|
1258
|
+
# open('t.txt') {|f| p f } # => #<File:t.txt (closed)>
|
1259
|
+
#
|
1260
|
+
# Output:
|
1261
|
+
#
|
1262
|
+
# #<File:t.txt>
|
1263
|
+
#
|
1264
|
+
# See File.open for details.
|
1265
|
+
#
|
1266
|
+
def self?.open: (String name, ?String mode, ?Integer perm) -> IO?
|
1267
|
+
| [T] (String name, ?String mode, ?Integer perm) { (IO) -> T } -> T
|
1268
|
+
|
1269
|
+
# <!--
|
1270
|
+
# rdoc-file=io.c
|
1271
|
+
# - print(*objects) -> nil
|
1272
|
+
# -->
|
1273
|
+
# Equivalent to `$stdout.print(*objects)`, this method is the straightforward
|
1274
|
+
# way to write to `$stdout`.
|
1275
|
+
#
|
1276
|
+
# Writes the given objects to `$stdout`; returns `nil`. Appends the output
|
1277
|
+
# record separator `$OUTPUT_RECORD_SEPARATOR` `$\`), if it is not `nil`.
|
1278
|
+
#
|
1279
|
+
# With argument `objects` given, for each object:
|
1280
|
+
#
|
1281
|
+
# * Converts via its method `to_s` if not a string.
|
1282
|
+
# * Writes to `stdout`.
|
1283
|
+
# * If not the last object, writes the output field separator
|
1284
|
+
# `$OUTPUT_FIELD_SEPARATOR` (`$,` if it is not `nil`.
|
1285
|
+
#
|
1286
|
+
# With default separators:
|
1287
|
+
#
|
1288
|
+
# objects = [0, 0.0, Rational(0, 1), Complex(0, 0), :zero, 'zero']
|
1289
|
+
# $OUTPUT_RECORD_SEPARATOR
|
1290
|
+
# $OUTPUT_FIELD_SEPARATOR
|
1291
|
+
# print(*objects)
|
1292
|
+
#
|
1293
|
+
# Output:
|
1294
|
+
#
|
1295
|
+
# nil
|
1296
|
+
# nil
|
1297
|
+
# 00.00/10+0izerozero
|
1298
|
+
#
|
1299
|
+
# With specified separators:
|
1300
|
+
#
|
1301
|
+
# $OUTPUT_RECORD_SEPARATOR = "\n"
|
1302
|
+
# $OUTPUT_FIELD_SEPARATOR = ','
|
1303
|
+
# print(*objects)
|
1304
|
+
#
|
1305
|
+
# Output:
|
1306
|
+
#
|
1307
|
+
# 0,0.0,0/1,0+0i,zero,zero
|
1308
|
+
#
|
1309
|
+
# With no argument given, writes the content of `$_` (which is usually the most
|
1310
|
+
# recent user input):
|
1311
|
+
#
|
1312
|
+
# gets # Sets $_ to the most recent user input.
|
1313
|
+
# print # Prints $_.
|
1314
|
+
#
|
1315
|
+
def self?.print: (*_ToS args) -> nil
|
1316
|
+
|
1317
|
+
# <!--
|
1318
|
+
# rdoc-file=io.c
|
1319
|
+
# - printf(format_string, *objects) -> nil
|
1320
|
+
# - printf(io, format_string, *objects) -> nil
|
1321
|
+
# -->
|
1322
|
+
# Equivalent to:
|
1323
|
+
#
|
1324
|
+
# io.write(sprintf(format_string, *objects))
|
1325
|
+
#
|
1326
|
+
# For details on `format_string`, see [Format
|
1327
|
+
# Specifications](rdoc-ref:format_specifications.rdoc).
|
1328
|
+
#
|
1329
|
+
# With the single argument `format_string`, formats `objects` into the string,
|
1330
|
+
# then writes the formatted string to $stdout:
|
1331
|
+
#
|
1332
|
+
# printf('%4.4d %10s %2.2f', 24, 24, 24.0)
|
1333
|
+
#
|
1334
|
+
# Output (on $stdout):
|
1335
|
+
#
|
1336
|
+
# 0024 24 24.00#
|
1337
|
+
#
|
1338
|
+
# With arguments `io` and `format_string`, formats `objects` into the string,
|
1339
|
+
# then writes the formatted string to `io`:
|
1340
|
+
#
|
1341
|
+
# printf($stderr, '%4.4d %10s %2.2f', 24, 24, 24.0)
|
1342
|
+
#
|
1343
|
+
# Output (on $stderr):
|
1344
|
+
#
|
1345
|
+
# 0024 24 24.00# => nil
|
1346
|
+
#
|
1347
|
+
# With no arguments, does nothing.
|
1348
|
+
#
|
1349
|
+
def self?.printf: () -> nil
|
1350
|
+
| (String fmt, *untyped args) -> nil
|
1351
|
+
| (_Writer io, string fmt, *untyped args) -> nil
|
1352
|
+
|
1353
|
+
# <!--
|
1354
|
+
# rdoc-file=proc.c
|
1355
|
+
# - proc { |...| block } -> a_proc
|
1356
|
+
# -->
|
1357
|
+
# Equivalent to Proc.new.
|
1358
|
+
#
|
1359
|
+
def self?.proc: () { (?) -> untyped } -> Proc
|
1360
|
+
|
1361
|
+
# <!--
|
1362
|
+
# rdoc-file=proc.c
|
1363
|
+
# - lambda { |...| block } -> a_proc
|
1364
|
+
# -->
|
1365
|
+
# Equivalent to Proc.new, except the resulting Proc objects check the number of
|
1366
|
+
# parameters passed when called.
|
1367
|
+
#
|
1368
|
+
def self?.lambda: () { () -> untyped } -> Proc
|
1369
|
+
|
1370
|
+
# <!--
|
1371
|
+
# rdoc-file=io.c
|
1372
|
+
# - putc(int) -> int
|
1373
|
+
# -->
|
1374
|
+
# Equivalent to:
|
1375
|
+
#
|
1376
|
+
# $stdout.putc(int)
|
1377
|
+
#
|
1378
|
+
# See IO#putc for important information regarding multi-byte characters.
|
1379
|
+
#
|
1380
|
+
def self?.putc: [T < _ToInt] (T chr) -> T
|
1381
|
+
| (String chr) -> String
|
1382
|
+
|
1383
|
+
# <!--
|
1384
|
+
# rdoc-file=io.c
|
1385
|
+
# - puts(*objects) -> nil
|
1386
|
+
# -->
|
1387
|
+
# Equivalent to
|
1388
|
+
#
|
1389
|
+
# $stdout.puts(objects)
|
1390
|
+
#
|
1391
|
+
def self?.puts: (*_ToS objects) -> nil
|
1392
|
+
|
1393
|
+
# <!--
|
1394
|
+
# rdoc-file=io.c
|
1395
|
+
# - p(object) -> obj
|
1396
|
+
# - p(*objects) -> array of objects
|
1397
|
+
# - p -> nil
|
1398
|
+
# -->
|
1399
|
+
# For each object `obj`, executes:
|
1400
|
+
#
|
1401
|
+
# $stdout.write(obj.inspect, "\n")
|
1402
|
+
#
|
1403
|
+
# With one object given, returns the object; with multiple objects given,
|
1404
|
+
# returns an array containing the objects; with no object given, returns `nil`.
|
1405
|
+
#
|
1406
|
+
# Examples:
|
1407
|
+
#
|
1408
|
+
# r = Range.new(0, 4)
|
1409
|
+
# p r # => 0..4
|
1410
|
+
# p [r, r, r] # => [0..4, 0..4, 0..4]
|
1411
|
+
# p # => nil
|
1412
|
+
#
|
1413
|
+
# Output:
|
1414
|
+
#
|
1415
|
+
# 0..4
|
1416
|
+
# [0..4, 0..4, 0..4]
|
1417
|
+
#
|
1418
|
+
# Kernel#p is designed for debugging purposes. Ruby implementations may define
|
1419
|
+
# Kernel#p to be uninterruptible in whole or in part. On CRuby, Kernel#p's
|
1420
|
+
# writing of data is uninterruptible.
|
1421
|
+
#
|
1422
|
+
def self?.p: [T < _Inspect] (T arg0) -> T
|
1423
|
+
| (_Inspect arg0, _Inspect arg1, *_Inspect rest) -> Array[_Inspect]
|
1424
|
+
| () -> nil
|
1425
|
+
|
1426
|
+
# <!--
|
1427
|
+
# rdoc-file=lib/pp.rb
|
1428
|
+
# - pp(*objs)
|
1429
|
+
# -->
|
1430
|
+
# prints arguments in pretty form.
|
1431
|
+
#
|
1432
|
+
# `#pp` returns argument(s).
|
1433
|
+
#
|
1434
|
+
def self?.pp: [T] (T arg0) -> T
|
1435
|
+
| (untyped, untyped, *untyped) -> Array[untyped]
|
1436
|
+
| () -> nil
|
1437
|
+
|
1438
|
+
# <!--
|
1439
|
+
# rdoc-file=random.c
|
1440
|
+
# - rand(max=0) -> number
|
1441
|
+
# -->
|
1442
|
+
# If called without an argument, or if `max.to_i.abs == 0`, rand returns a
|
1443
|
+
# pseudo-random floating point number between 0.0 and 1.0, including 0.0 and
|
1444
|
+
# excluding 1.0.
|
1445
|
+
#
|
1446
|
+
# rand #=> 0.2725926052826416
|
1447
|
+
#
|
1448
|
+
# When `max.abs` is greater than or equal to 1, `rand` returns a pseudo-random
|
1449
|
+
# integer greater than or equal to 0 and less than `max.to_i.abs`.
|
1450
|
+
#
|
1451
|
+
# rand(100) #=> 12
|
1452
|
+
#
|
1453
|
+
# When `max` is a Range, `rand` returns a random number where
|
1454
|
+
# `range.member?(number) == true`.
|
1455
|
+
#
|
1456
|
+
# Negative or floating point values for `max` are allowed, but may give
|
1457
|
+
# surprising results.
|
1458
|
+
#
|
1459
|
+
# rand(-100) # => 87
|
1460
|
+
# rand(-0.5) # => 0.8130921818028143
|
1461
|
+
# rand(1.9) # equivalent to rand(1), which is always 0
|
1462
|
+
#
|
1463
|
+
# Kernel.srand may be used to ensure that sequences of random numbers are
|
1464
|
+
# reproducible between different runs of a program.
|
1465
|
+
#
|
1466
|
+
# See also Random.rand.
|
1467
|
+
#
|
1468
|
+
def self?.rand: (?0) -> Float
|
1469
|
+
| (int arg0) -> Integer
|
1470
|
+
| (::Range[Integer] arg0) -> Integer?
|
1471
|
+
| (::Range[Float] arg0) -> Float?
|
1472
|
+
|
1473
|
+
# <!--
|
1474
|
+
# rdoc-file=io.c
|
1475
|
+
# - readline(sep = $/, chomp: false) -> string
|
1476
|
+
# - readline(limit, chomp: false) -> string
|
1477
|
+
# - readline(sep, limit, chomp: false) -> string
|
1478
|
+
# -->
|
1479
|
+
# Equivalent to method Kernel#gets, except that it raises an exception if called
|
1480
|
+
# at end-of-stream:
|
1481
|
+
#
|
1482
|
+
# $ cat t.txt | ruby -e "p readlines; readline"
|
1483
|
+
# ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
1484
|
+
# in `readline': end of file reached (EOFError)
|
1485
|
+
#
|
1486
|
+
# Optional keyword argument `chomp` specifies whether line separators are to be
|
1487
|
+
# omitted.
|
1488
|
+
#
|
1489
|
+
def self?.readline: (?String arg0, ?Integer arg1) -> String
|
1490
|
+
|
1491
|
+
# <!--
|
1492
|
+
# rdoc-file=io.c
|
1493
|
+
# - readlines(sep = $/, chomp: false, **enc_opts) -> array
|
1494
|
+
# - readlines(limit, chomp: false, **enc_opts) -> array
|
1495
|
+
# - readlines(sep, limit, chomp: false, **enc_opts) -> array
|
1496
|
+
# -->
|
1497
|
+
# Returns an array containing the lines returned by calling Kernel#gets until
|
1498
|
+
# the end-of-stream is reached; (see [Line IO](rdoc-ref:IO@Line+IO)).
|
1499
|
+
#
|
1500
|
+
# With only string argument `sep` given, returns the remaining lines as
|
1501
|
+
# determined by line separator `sep`, or `nil` if none; see [Line
|
1502
|
+
# Separator](rdoc-ref:IO@Line+Separator):
|
1503
|
+
#
|
1504
|
+
# # Default separator.
|
1505
|
+
# $ cat t.txt | ruby -e "p readlines"
|
1506
|
+
# ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
1507
|
+
#
|
1508
|
+
# # Specified separator.
|
1509
|
+
# $ cat t.txt | ruby -e "p readlines 'li'"
|
1510
|
+
# ["First li", "ne\nSecond li", "ne\n\nFourth li", "ne\nFifth li", "ne\n"]
|
1511
|
+
#
|
1512
|
+
# # Get-all separator.
|
1513
|
+
# $ cat t.txt | ruby -e "p readlines nil"
|
1514
|
+
# ["First line\nSecond line\n\nFourth line\nFifth line\n"]
|
1515
|
+
#
|
1516
|
+
# # Get-paragraph separator.
|
1517
|
+
# $ cat t.txt | ruby -e "p readlines ''"
|
1518
|
+
# ["First line\nSecond line\n\n", "Fourth line\nFifth line\n"]
|
1519
|
+
#
|
1520
|
+
# With only integer argument `limit` given, limits the number of bytes in the
|
1521
|
+
# line; see [Line Limit](rdoc-ref:IO@Line+Limit):
|
1522
|
+
#
|
1523
|
+
# $cat t.txt | ruby -e "p readlines 10"
|
1524
|
+
# ["First line", "\n", "Second lin", "e\n", "\n", "Fourth lin", "e\n", "Fifth line", "\n"]
|
1525
|
+
#
|
1526
|
+
# $cat t.txt | ruby -e "p readlines 11"
|
1527
|
+
# ["First line\n", "Second line", "\n", "\n", "Fourth line", "\n", "Fifth line\n"]
|
1528
|
+
#
|
1529
|
+
# $cat t.txt | ruby -e "p readlines 12"
|
1530
|
+
# ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
1531
|
+
#
|
1532
|
+
# With arguments `sep` and `limit` given, combines the two behaviors (see [Line
|
1533
|
+
# Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
|
1534
|
+
#
|
1535
|
+
# Optional keyword argument `chomp` specifies whether line separators are to be
|
1536
|
+
# omitted:
|
1537
|
+
#
|
1538
|
+
# $ cat t.txt | ruby -e "p readlines(chomp: true)"
|
1539
|
+
# ["First line", "Second line", "", "Fourth line", "Fifth line"]
|
1540
|
+
#
|
1541
|
+
# Optional keyword arguments `enc_opts` specify encoding options; see [Encoding
|
1542
|
+
# options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
1543
|
+
#
|
1544
|
+
def self?.readlines: (?string sep, ?int limit, ?chomp: boolish) -> ::Array[String]
|
1545
|
+
|
1546
|
+
# <!--
|
1547
|
+
# rdoc-file=lib/rubygems/core_ext/kernel_require.rb
|
1548
|
+
# - require(path)
|
1549
|
+
# -->
|
1550
|
+
# When RubyGems is required, Kernel#require is replaced with our own which is
|
1551
|
+
# capable of loading gems on demand.
|
1552
|
+
#
|
1553
|
+
# When you call `require 'x'`, this is what happens:
|
1554
|
+
# * If the file can be loaded from the existing Ruby loadpath, it is.
|
1555
|
+
# * Otherwise, installed gems are searched for a file that matches. If it's
|
1556
|
+
# found in gem 'y', that gem is activated (added to the loadpath).
|
1557
|
+
#
|
1558
|
+
# The normal `require` functionality of returning false if that file has already
|
1559
|
+
# been loaded is preserved.
|
1560
|
+
#
|
1561
|
+
def self?.require: (String path) -> bool
|
1562
|
+
|
1563
|
+
# <!--
|
1564
|
+
# rdoc-file=load.c
|
1565
|
+
# - require_relative(string) -> true or false
|
1566
|
+
# -->
|
1567
|
+
# Ruby tries to load the library named *string* relative to the directory
|
1568
|
+
# containing the requiring file. If the file does not exist a LoadError is
|
1569
|
+
# raised. Returns `true` if the file was loaded and `false` if the file was
|
1570
|
+
# already loaded before.
|
1571
|
+
#
|
1572
|
+
def self?.require_relative: (String feature) -> bool
|
1573
|
+
|
1574
|
+
# <!--
|
1575
|
+
# rdoc-file=io.c
|
1576
|
+
# - IO.select(read_ios, write_ios = [], error_ios = [], timeout = nil) -> array or nil
|
1577
|
+
# -->
|
1578
|
+
# Invokes system call [select(2)](https://linux.die.net/man/2/select), which
|
1579
|
+
# monitors multiple file descriptors, waiting until one or more of the file
|
1580
|
+
# descriptors becomes ready for some class of I/O operation.
|
1581
|
+
#
|
1582
|
+
# Not implemented on all platforms.
|
1583
|
+
#
|
1584
|
+
# Each of the arguments `read_ios`, `write_ios`, and `error_ios` is an array of
|
1585
|
+
# IO objects.
|
1586
|
+
#
|
1587
|
+
# Argument `timeout` is a numeric value (such as integer or float) timeout
|
1588
|
+
# interval in seconds.
|
1589
|
+
#
|
1590
|
+
# The method monitors the IO objects given in all three arrays, waiting for some
|
1591
|
+
# to be ready; returns a 3-element array whose elements are:
|
1592
|
+
#
|
1593
|
+
# * An array of the objects in `read_ios` that are ready for reading.
|
1594
|
+
# * An array of the objects in `write_ios` that are ready for writing.
|
1595
|
+
# * An array of the objects in `error_ios` have pending exceptions.
|
1596
|
+
#
|
1597
|
+
# If no object becomes ready within the given `timeout`, `nil` is returned.
|
1598
|
+
#
|
1599
|
+
# IO.select peeks the buffer of IO objects for testing readability. If the IO
|
1600
|
+
# buffer is not empty, IO.select immediately notifies readability. This "peek"
|
1601
|
+
# only happens for IO objects. It does not happen for IO-like objects such as
|
1602
|
+
# OpenSSL::SSL::SSLSocket.
|
1603
|
+
#
|
1604
|
+
# The best way to use IO.select is invoking it after non-blocking methods such
|
1605
|
+
# as #read_nonblock, #write_nonblock, etc. The methods raise an exception which
|
1606
|
+
# is extended by IO::WaitReadable or IO::WaitWritable. The modules notify how
|
1607
|
+
# the caller should wait with IO.select. If IO::WaitReadable is raised, the
|
1608
|
+
# caller should wait for reading. If IO::WaitWritable is raised, the caller
|
1609
|
+
# should wait for writing.
|
1610
|
+
#
|
1611
|
+
# So, blocking read (#readpartial) can be emulated using #read_nonblock and
|
1612
|
+
# IO.select as follows:
|
1613
|
+
#
|
1614
|
+
# begin
|
1615
|
+
# result = io_like.read_nonblock(maxlen)
|
1616
|
+
# rescue IO::WaitReadable
|
1617
|
+
# IO.select([io_like])
|
1618
|
+
# retry
|
1619
|
+
# rescue IO::WaitWritable
|
1620
|
+
# IO.select(nil, [io_like])
|
1621
|
+
# retry
|
1622
|
+
# end
|
1623
|
+
#
|
1624
|
+
# Especially, the combination of non-blocking methods and IO.select is preferred
|
1625
|
+
# for IO like objects such as OpenSSL::SSL::SSLSocket. It has #to_io method to
|
1626
|
+
# return underlying IO object. IO.select calls #to_io to obtain the file
|
1627
|
+
# descriptor to wait.
|
1628
|
+
#
|
1629
|
+
# This means that readability notified by IO.select doesn't mean readability
|
1630
|
+
# from OpenSSL::SSL::SSLSocket object.
|
1631
|
+
#
|
1632
|
+
# The most likely situation is that OpenSSL::SSL::SSLSocket buffers some data.
|
1633
|
+
# IO.select doesn't see the buffer. So IO.select can block when
|
1634
|
+
# OpenSSL::SSL::SSLSocket#readpartial doesn't block.
|
1635
|
+
#
|
1636
|
+
# However, several more complicated situations exist.
|
1637
|
+
#
|
1638
|
+
# SSL is a protocol which is sequence of records. The record consists of
|
1639
|
+
# multiple bytes. So, the remote side of SSL sends a partial record, IO.select
|
1640
|
+
# notifies readability but OpenSSL::SSL::SSLSocket cannot decrypt a byte and
|
1641
|
+
# OpenSSL::SSL::SSLSocket#readpartial will block.
|
1642
|
+
#
|
1643
|
+
# Also, the remote side can request SSL renegotiation which forces the local SSL
|
1644
|
+
# engine to write some data. This means OpenSSL::SSL::SSLSocket#readpartial may
|
1645
|
+
# invoke #write system call and it can block. In such a situation,
|
1646
|
+
# OpenSSL::SSL::SSLSocket#read_nonblock raises IO::WaitWritable instead of
|
1647
|
+
# blocking. So, the caller should wait for ready for writability as above
|
1648
|
+
# example.
|
1649
|
+
#
|
1650
|
+
# The combination of non-blocking methods and IO.select is also useful for
|
1651
|
+
# streams such as tty, pipe socket socket when multiple processes read from a
|
1652
|
+
# stream.
|
1653
|
+
#
|
1654
|
+
# Finally, Linux kernel developers don't guarantee that readability of select(2)
|
1655
|
+
# means readability of following read(2) even for a single process; see
|
1656
|
+
# [select(2)](https://linux.die.net/man/2/select)
|
1657
|
+
#
|
1658
|
+
# Invoking IO.select before IO#readpartial works well as usual. However it is
|
1659
|
+
# not the best way to use IO.select.
|
1660
|
+
#
|
1661
|
+
# The writability notified by select(2) doesn't show how many bytes are
|
1662
|
+
# writable. IO#write method blocks until given whole string is written. So,
|
1663
|
+
# `IO#write(two or more bytes)` can block after writability is notified by
|
1664
|
+
# IO.select. IO#write_nonblock is required to avoid the blocking.
|
1665
|
+
#
|
1666
|
+
# Blocking write (#write) can be emulated using #write_nonblock and IO.select as
|
1667
|
+
# follows: IO::WaitReadable should also be rescued for SSL renegotiation in
|
1668
|
+
# OpenSSL::SSL::SSLSocket.
|
1669
|
+
#
|
1670
|
+
# while 0 < string.bytesize
|
1671
|
+
# begin
|
1672
|
+
# written = io_like.write_nonblock(string)
|
1673
|
+
# rescue IO::WaitReadable
|
1674
|
+
# IO.select([io_like])
|
1675
|
+
# retry
|
1676
|
+
# rescue IO::WaitWritable
|
1677
|
+
# IO.select(nil, [io_like])
|
1678
|
+
# retry
|
1679
|
+
# end
|
1680
|
+
# string = string.byteslice(written..-1)
|
1681
|
+
# end
|
1682
|
+
#
|
1683
|
+
# Example:
|
1684
|
+
#
|
1685
|
+
# rp, wp = IO.pipe
|
1686
|
+
# mesg = "ping "
|
1687
|
+
# 100.times {
|
1688
|
+
# # IO.select follows IO#read. Not the best way to use IO.select.
|
1689
|
+
# rs, ws, = IO.select([rp], [wp])
|
1690
|
+
# if r = rs[0]
|
1691
|
+
# ret = r.read(5)
|
1692
|
+
# print ret
|
1693
|
+
# case ret
|
1694
|
+
# when /ping/
|
1695
|
+
# mesg = "pong\n"
|
1696
|
+
# when /pong/
|
1697
|
+
# mesg = "ping "
|
1698
|
+
# end
|
1699
|
+
# end
|
1700
|
+
# if w = ws[0]
|
1701
|
+
# w.write(mesg)
|
1702
|
+
# end
|
1703
|
+
# }
|
1704
|
+
#
|
1705
|
+
# Output:
|
1706
|
+
#
|
1707
|
+
# ping pong
|
1708
|
+
# ping pong
|
1709
|
+
# ping pong
|
1710
|
+
# (snipped)
|
1711
|
+
# ping
|
1712
|
+
#
|
1713
|
+
def self?.select: (::Array[IO] read, ?::Array[IO] write, ?::Array[IO] error, ?Time::_Timeout timeout) -> ::Array[String]
|
1714
|
+
|
1715
|
+
# <!--
|
1716
|
+
# rdoc-file=process.c
|
1717
|
+
# - sleep(secs = nil) -> slept_secs
|
1718
|
+
# -->
|
1719
|
+
# Suspends execution of the current thread for the number of seconds specified
|
1720
|
+
# by numeric argument `secs`, or forever if `secs` is `nil`; returns the integer
|
1721
|
+
# number of seconds suspended (rounded).
|
1722
|
+
#
|
1723
|
+
# Time.new # => 2008-03-08 19:56:19 +0900
|
1724
|
+
# sleep 1.2 # => 1
|
1725
|
+
# Time.new # => 2008-03-08 19:56:20 +0900
|
1726
|
+
# sleep 1.9 # => 2
|
1727
|
+
# Time.new # => 2008-03-08 19:56:22 +0900
|
1728
|
+
#
|
1729
|
+
def self?.sleep: (?nil) -> bot
|
1730
|
+
| (Time::_Timeout duration) -> Integer
|
1731
|
+
|
1732
|
+
%a{steep:deprecated}
|
1733
|
+
interface _Divmod
|
1734
|
+
def divmod: (Numeric) -> [ Numeric, Numeric ]
|
1735
|
+
end
|
1736
|
+
|
1737
|
+
# <!--
|
1738
|
+
# rdoc-file=io.c
|
1739
|
+
# - syscall(integer_callno, *arguments) -> integer
|
1740
|
+
# -->
|
1741
|
+
# Invokes Posix system call [syscall(2)](https://linux.die.net/man/2/syscall),
|
1742
|
+
# which calls a specified function.
|
1743
|
+
#
|
1744
|
+
# Calls the operating system function identified by `integer_callno`; returns
|
1745
|
+
# the result of the function or raises SystemCallError if it failed. The effect
|
1746
|
+
# of the call is platform-dependent. The arguments and returned value are
|
1747
|
+
# platform-dependent.
|
1748
|
+
#
|
1749
|
+
# For each of `arguments`: if it is an integer, it is passed directly; if it is
|
1750
|
+
# a string, it is interpreted as a binary sequence of bytes. There may be as
|
1751
|
+
# many as nine such arguments.
|
1752
|
+
#
|
1753
|
+
# Arguments `integer_callno` and `argument`, as well as the returned value, are
|
1754
|
+
# platform-dependent.
|
1755
|
+
#
|
1756
|
+
# Note: Method `syscall` is essentially unsafe and unportable. The DL (Fiddle)
|
1757
|
+
# library is preferred for safer and a bit more portable programming.
|
1758
|
+
#
|
1759
|
+
# Not implemented on all platforms.
|
1760
|
+
#
|
1761
|
+
def self?.syscall: (Integer num, *untyped args) -> untyped
|
1762
|
+
|
1763
|
+
# <!--
|
1764
|
+
# rdoc-file=file.c
|
1765
|
+
# - test(char, path0, path1 = nil) -> object
|
1766
|
+
# -->
|
1767
|
+
# Performs a test on one or both of the *filesystem entities* at the given paths
|
1768
|
+
# `path0` and `path1`:
|
1769
|
+
# * Each path `path0` or `path1` points to a file, directory, device, pipe,
|
1770
|
+
# etc.
|
1771
|
+
# * Character `char` selects a specific test.
|
1772
|
+
# The tests:
|
1773
|
+
# * Each of these tests operates only on the entity at `path0`,
|
1774
|
+
# and returns `true` or `false`;
|
1775
|
+
# for a non-existent entity, returns `false` (does not raise exception):
|
1776
|
+
# Character |Test
|
1777
|
+
# ------------|-------------------------------------------------------------------------
|
1778
|
+
# <tt>'b'</tt>|Whether the entity is a block device.
|
1779
|
+
# <tt>'c'</tt>|Whether the entity is a character device.
|
1780
|
+
# <tt>'d'</tt>|Whether the entity is a directory.
|
1781
|
+
# <tt>'e'</tt>|Whether the entity is an existing entity.
|
1782
|
+
# <tt>'f'</tt>|Whether the entity is an existing regular file.
|
1783
|
+
# <tt>'g'</tt>|Whether the entity's setgid bit is set.
|
1784
|
+
# <tt>'G'</tt>|Whether the entity's group ownership is equal to the caller's.
|
1785
|
+
# <tt>'k'</tt>|Whether the entity's sticky bit is set.
|
1786
|
+
# <tt>'l'</tt>|Whether the entity is a symbolic link.
|
1787
|
+
# <tt>'o'</tt>|Whether the entity is owned by the caller's effective uid.
|
1788
|
+
# <tt>'O'</tt>|Like <tt>'o'</tt>, but uses the real uid (not the effective uid).
|
1789
|
+
# <tt>'p'</tt>|Whether the entity is a FIFO device (named pipe).
|
1790
|
+
# <tt>'r'</tt>|Whether the entity is readable by the caller's effective uid/gid.
|
1791
|
+
# <tt>'R'</tt>|Like <tt>'r'</tt>, but uses the real uid/gid (not the effective uid/gid).
|
1792
|
+
# <tt>'S'</tt>|Whether the entity is a socket.
|
1793
|
+
# <tt>'u'</tt>|Whether the entity's setuid bit is set.
|
1794
|
+
# <tt>'w'</tt>|Whether the entity is writable by the caller's effective uid/gid.
|
1795
|
+
# <tt>'W'</tt>|Like <tt>'w'</tt>, but uses the real uid/gid (not the effective uid/gid).
|
1796
|
+
# <tt>'x'</tt>|Whether the entity is executable by the caller's effective uid/gid.
|
1797
|
+
# <tt>'X'</tt>|Like <tt>'x'</tt>, but uses the real uid/gid (not the effective uid/git).
|
1798
|
+
# <tt>'z'</tt>|Whether the entity exists and is of length zero.
|
1799
|
+
# * This test operates only on the entity at `path0`,
|
1800
|
+
# and returns an integer size or `nil`:
|
1801
|
+
# Character |Test
|
1802
|
+
# ------------|--------------------------------------------------------------------------------------------
|
1803
|
+
# <tt>'s'</tt>|Returns positive integer size if the entity exists and has non-zero length, +nil+ otherwise.
|
1804
|
+
# * Each of these tests operates only on the entity at `path0`,
|
1805
|
+
# and returns a Time object;
|
1806
|
+
# raises an exception if the entity does not exist:
|
1807
|
+
# Character |Test
|
1808
|
+
# ------------|--------------------------------------
|
1809
|
+
# <tt>'A'</tt>|Last access time for the entity.
|
1810
|
+
# <tt>'C'</tt>|Last change time for the entity.
|
1811
|
+
# <tt>'M'</tt>|Last modification time for the entity.
|
1812
|
+
# * Each of these tests operates on the modification time (`mtime`)
|
1813
|
+
# of each of the entities at `path0` and `path1`,
|
1814
|
+
# and returns a `true` or `false`;
|
1815
|
+
# returns `false` if either entity does not exist:
|
1816
|
+
# Character |Test
|
1817
|
+
# ------------|---------------------------------------------------------------
|
1818
|
+
# <tt>'<'</tt>|Whether the `mtime` at `path0` is less than that at `path1`.
|
1819
|
+
# <tt>'='</tt>|Whether the `mtime` at `path0` is equal to that at `path1`.
|
1820
|
+
# <tt>'>'</tt>|Whether the `mtime` at `path0` is greater than that at `path1`.
|
1821
|
+
# * This test operates on the content of each of the entities at `path0` and
|
1822
|
+
# `path1`,
|
1823
|
+
# and returns a `true` or `false`;
|
1824
|
+
# returns `false` if either entity does not exist:
|
1825
|
+
# Character |Test
|
1826
|
+
# ------------|---------------------------------------------
|
1827
|
+
# <tt>'-'</tt>|Whether the entities exist and are identical.
|
1828
|
+
#
|
1829
|
+
def self?.test: (String | Integer cmd, String | IO file1, ?String | IO file2) -> (TrueClass | FalseClass | Time | nil | Integer)
|
1830
|
+
|
1831
|
+
# <!--
|
1832
|
+
# rdoc-file=vm_eval.c
|
1833
|
+
# - throw(tag [, obj])
|
1834
|
+
# -->
|
1835
|
+
# Transfers control to the end of the active `catch` block waiting for *tag*.
|
1836
|
+
# Raises `UncaughtThrowError` if there is no `catch` block for the *tag*. The
|
1837
|
+
# optional second parameter supplies a return value for the `catch` block, which
|
1838
|
+
# otherwise defaults to `nil`. For examples, see Kernel::catch.
|
1839
|
+
#
|
1840
|
+
def self?.throw: (untyped tag, ?untyped obj) -> bot
|
1841
|
+
|
1842
|
+
# <!--
|
1843
|
+
# rdoc-file=warning.rb
|
1844
|
+
# - warn(*msgs, uplevel: nil, category: nil) -> nil
|
1845
|
+
# -->
|
1846
|
+
# If warnings have been disabled (for example with the `-W0` flag), does
|
1847
|
+
# nothing. Otherwise, converts each of the messages to strings, appends a
|
1848
|
+
# newline character to the string if the string does not end in a newline, and
|
1849
|
+
# calls Warning.warn with the string.
|
1850
|
+
#
|
1851
|
+
# warn("warning 1", "warning 2")
|
1852
|
+
#
|
1853
|
+
# *produces:*
|
1854
|
+
#
|
1855
|
+
# warning 1
|
1856
|
+
# warning 2
|
1857
|
+
#
|
1858
|
+
# If the `uplevel` keyword argument is given, the string will be prepended with
|
1859
|
+
# information for the given caller frame in the same format used by the
|
1860
|
+
# `rb_warn` C function.
|
1861
|
+
#
|
1862
|
+
# # In baz.rb
|
1863
|
+
# def foo
|
1864
|
+
# warn("invalid call to foo", uplevel: 1)
|
1865
|
+
# end
|
1866
|
+
#
|
1867
|
+
# def bar
|
1868
|
+
# foo
|
1869
|
+
# end
|
1870
|
+
#
|
1871
|
+
# bar
|
1872
|
+
#
|
1873
|
+
# *produces:*
|
1874
|
+
#
|
1875
|
+
# baz.rb:6: warning: invalid call to foo
|
1876
|
+
#
|
1877
|
+
# If `category` keyword argument is given, passes the category to
|
1878
|
+
# `Warning.warn`. The category given must be one of the following categories:
|
1879
|
+
#
|
1880
|
+
# :deprecated
|
1881
|
+
# : Used for warning for deprecated functionality that may be removed in the
|
1882
|
+
# future.
|
1883
|
+
#
|
1884
|
+
# :experimental
|
1885
|
+
# : Used for experimental features that may change in future releases.
|
1886
|
+
#
|
1887
|
+
# :performance
|
1888
|
+
# : Used for warning about APIs or pattern that have negative performance
|
1889
|
+
# impact
|
1890
|
+
#
|
1891
|
+
def self?.warn: (*_ToS msg, ?uplevel: int?, ?category: Warning::category?) -> nil
|
1892
|
+
|
1893
|
+
# <!--
|
1894
|
+
# rdoc-file=process.c
|
1895
|
+
# - exec([env, ] command_line, options = {})
|
1896
|
+
# - exec([env, ] exe_path, *args, options = {})
|
1897
|
+
# -->
|
1898
|
+
# Replaces the current process by doing one of the following:
|
1899
|
+
#
|
1900
|
+
# * Passing string `command_line` to the shell.
|
1901
|
+
# * Invoking the executable at `exe_path`.
|
1902
|
+
#
|
1903
|
+
# This method has potential security vulnerabilities if called with untrusted
|
1904
|
+
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
1905
|
+
#
|
1906
|
+
# The new process is created using the [exec system
|
1907
|
+
# call](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/e
|
1908
|
+
# xecve.html); it may inherit some of its environment from the calling program
|
1909
|
+
# (possibly including open file descriptors).
|
1910
|
+
#
|
1911
|
+
# Argument `env`, if given, is a hash that affects `ENV` for the new process;
|
1912
|
+
# see [Execution Environment](rdoc-ref:Process@Execution+Environment).
|
1913
|
+
#
|
1914
|
+
# Argument `options` is a hash of options for the new process; see [Execution
|
1915
|
+
# Options](rdoc-ref:Process@Execution+Options).
|
1916
|
+
#
|
1917
|
+
# The first required argument is one of the following:
|
1918
|
+
#
|
1919
|
+
# * `command_line` if it is a string, and if it begins with a shell reserved
|
1920
|
+
# word or special built-in, or if it contains one or more meta characters.
|
1921
|
+
# * `exe_path` otherwise.
|
1922
|
+
#
|
1923
|
+
# **Argument `command_line`**
|
1924
|
+
#
|
1925
|
+
# String argument `command_line` is a command line to be passed to a shell; it
|
1926
|
+
# must begin with a shell reserved word, begin with a special built-in, or
|
1927
|
+
# contain meta characters:
|
1928
|
+
#
|
1929
|
+
# exec('if true; then echo "Foo"; fi') # Shell reserved word.
|
1930
|
+
# exec('exit') # Built-in.
|
1931
|
+
# exec('date > date.tmp') # Contains meta character.
|
1932
|
+
#
|
1933
|
+
# The command line may also contain arguments and options for the command:
|
1934
|
+
#
|
1935
|
+
# exec('echo "Foo"')
|
1936
|
+
#
|
1937
|
+
# Output:
|
1938
|
+
#
|
1939
|
+
# Foo
|
1940
|
+
#
|
1941
|
+
# See [Execution Shell](rdoc-ref:Process@Execution+Shell) for details about the
|
1942
|
+
# shell.
|
1943
|
+
#
|
1944
|
+
# Raises an exception if the new process could not execute.
|
1945
|
+
#
|
1946
|
+
# **Argument `exe_path`**
|
1947
|
+
#
|
1948
|
+
# Argument `exe_path` is one of the following:
|
1949
|
+
#
|
1950
|
+
# * The string path to an executable to be called.
|
1951
|
+
# * A 2-element array containing the path to an executable and the string to
|
1952
|
+
# be used as the name of the executing process.
|
1953
|
+
#
|
1954
|
+
# Example:
|
1955
|
+
#
|
1956
|
+
# exec('/usr/bin/date')
|
1957
|
+
#
|
1958
|
+
# Output:
|
1959
|
+
#
|
1960
|
+
# Sat Aug 26 09:38:00 AM CDT 2023
|
1961
|
+
#
|
1962
|
+
# Ruby invokes the executable directly. This form does not use the shell; see
|
1963
|
+
# [Arguments args](rdoc-ref:Process@Arguments+args) for caveats.
|
1964
|
+
#
|
1965
|
+
# exec('doesnt_exist') # Raises Errno::ENOENT
|
1966
|
+
#
|
1967
|
+
# If one or more `args` is given, each is an argument or option to be passed to
|
1968
|
+
# the executable:
|
1969
|
+
#
|
1970
|
+
# exec('echo', 'C*')
|
1971
|
+
# exec('echo', 'hello', 'world')
|
1972
|
+
#
|
1973
|
+
# Output:
|
1974
|
+
#
|
1975
|
+
# C*
|
1976
|
+
# hello world
|
1977
|
+
#
|
1978
|
+
# Raises an exception if the new process could not execute.
|
1979
|
+
#
|
1980
|
+
def self?.exec: (String command, *String args, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> bot
|
1981
|
+
| (Hash[string, string?] env, String command, *String args, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> bot
|
1982
|
+
|
1983
|
+
type redirect_fd = Integer | :in | :out | :err | IO | String | [ String ] | [ String, string | int ] | [ String, string | int, int ] | [ :child, int ] | :close
|
1984
|
+
|
1985
|
+
# <!--
|
1986
|
+
# rdoc-file=process.c
|
1987
|
+
# - spawn([env, ] command_line, options = {}) -> pid
|
1988
|
+
# - spawn([env, ] exe_path, *args, options = {}) -> pid
|
1989
|
+
# -->
|
1990
|
+
# Creates a new child process by doing one of the following in that process:
|
1991
|
+
#
|
1992
|
+
# * Passing string `command_line` to the shell.
|
1993
|
+
# * Invoking the executable at `exe_path`.
|
1994
|
+
#
|
1995
|
+
# This method has potential security vulnerabilities if called with untrusted
|
1996
|
+
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
1997
|
+
#
|
1998
|
+
# Returns the process ID (pid) of the new process, without waiting for it to
|
1999
|
+
# complete.
|
2000
|
+
#
|
2001
|
+
# To avoid zombie processes, the parent process should call either:
|
2002
|
+
#
|
2003
|
+
# * Process.wait, to collect the termination statuses of its children.
|
2004
|
+
# * Process.detach, to register disinterest in their status.
|
2005
|
+
#
|
2006
|
+
# The new process is created using the [exec system
|
2007
|
+
# call](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/e
|
2008
|
+
# xecve.html); it may inherit some of its environment from the calling program
|
2009
|
+
# (possibly including open file descriptors).
|
2010
|
+
#
|
2011
|
+
# Argument `env`, if given, is a hash that affects `ENV` for the new process;
|
2012
|
+
# see [Execution Environment](rdoc-ref:Process@Execution+Environment).
|
2013
|
+
#
|
2014
|
+
# Argument `options` is a hash of options for the new process; see [Execution
|
2015
|
+
# Options](rdoc-ref:Process@Execution+Options).
|
2016
|
+
#
|
2017
|
+
# The first required argument is one of the following:
|
2018
|
+
#
|
2019
|
+
# * `command_line` if it is a string, and if it begins with a shell reserved
|
2020
|
+
# word or special built-in, or if it contains one or more meta characters.
|
2021
|
+
# * `exe_path` otherwise.
|
2022
|
+
#
|
2023
|
+
# **Argument `command_line`**
|
2024
|
+
#
|
2025
|
+
# String argument `command_line` is a command line to be passed to a shell; it
|
2026
|
+
# must begin with a shell reserved word, begin with a special built-in, or
|
2027
|
+
# contain meta characters:
|
2028
|
+
#
|
2029
|
+
# spawn('if true; then echo "Foo"; fi') # => 798847 # Shell reserved word.
|
2030
|
+
# Process.wait # => 798847
|
2031
|
+
# spawn('exit') # => 798848 # Built-in.
|
2032
|
+
# Process.wait # => 798848
|
2033
|
+
# spawn('date > /tmp/date.tmp') # => 798879 # Contains meta character.
|
2034
|
+
# Process.wait # => 798849
|
2035
|
+
# spawn('date > /nop/date.tmp') # => 798882 # Issues error message.
|
2036
|
+
# Process.wait # => 798882
|
2037
|
+
#
|
2038
|
+
# The command line may also contain arguments and options for the command:
|
2039
|
+
#
|
2040
|
+
# spawn('echo "Foo"') # => 799031
|
2041
|
+
# Process.wait # => 799031
|
2042
|
+
#
|
2043
|
+
# Output:
|
2044
|
+
#
|
2045
|
+
# Foo
|
2046
|
+
#
|
2047
|
+
# See [Execution Shell](rdoc-ref:Process@Execution+Shell) for details about the
|
2048
|
+
# shell.
|
2049
|
+
#
|
2050
|
+
# Raises an exception if the new process could not execute.
|
2051
|
+
#
|
2052
|
+
# **Argument `exe_path`**
|
2053
|
+
#
|
2054
|
+
# Argument `exe_path` is one of the following:
|
2055
|
+
#
|
2056
|
+
# * The string path to an executable to be called.
|
2057
|
+
# * A 2-element array containing the path to an executable to be called, and
|
2058
|
+
# the string to be used as the name of the executing process.
|
2059
|
+
#
|
2060
|
+
# spawn('/usr/bin/date') # Path to date on Unix-style system.
|
2061
|
+
# Process.wait
|
2062
|
+
#
|
2063
|
+
# Output:
|
2064
|
+
#
|
2065
|
+
# Mon Aug 28 11:43:10 AM CDT 2023
|
2066
|
+
#
|
2067
|
+
# Ruby invokes the executable directly. This form does not use the shell; see
|
2068
|
+
# [Arguments args](rdoc-ref:Process@Arguments+args) for caveats.
|
2069
|
+
#
|
2070
|
+
# If one or more `args` is given, each is an argument or option to be passed to
|
2071
|
+
# the executable:
|
2072
|
+
#
|
2073
|
+
# spawn('echo', 'C*') # => 799392
|
2074
|
+
# Process.wait # => 799392
|
2075
|
+
# spawn('echo', 'hello', 'world') # => 799393
|
2076
|
+
# Process.wait # => 799393
|
2077
|
+
#
|
2078
|
+
# Output:
|
2079
|
+
#
|
2080
|
+
# C*
|
2081
|
+
# hello world
|
2082
|
+
#
|
2083
|
+
# Raises an exception if the new process could not execute.
|
2084
|
+
#
|
2085
|
+
def self?.spawn: (String command, *String args, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> Integer
|
2086
|
+
| (Hash[string, string?] env, String command, *String args, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> Integer
|
2087
|
+
|
2088
|
+
# <!--
|
2089
|
+
# rdoc-file=process.c
|
2090
|
+
# - system([env, ] command_line, options = {}, exception: false) -> true, false, or nil
|
2091
|
+
# - system([env, ] exe_path, *args, options = {}, exception: false) -> true, false, or nil
|
2092
|
+
# -->
|
2093
|
+
# Creates a new child process by doing one of the following in that process:
|
2094
|
+
#
|
2095
|
+
# * Passing string `command_line` to the shell.
|
2096
|
+
# * Invoking the executable at `exe_path`.
|
2097
|
+
#
|
2098
|
+
# This method has potential security vulnerabilities if called with untrusted
|
2099
|
+
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
2100
|
+
#
|
2101
|
+
# Returns:
|
2102
|
+
#
|
2103
|
+
# * `true` if the command exits with status zero.
|
2104
|
+
# * `false` if the exit status is a non-zero integer.
|
2105
|
+
# * `nil` if the command could not execute.
|
2106
|
+
#
|
2107
|
+
# Raises an exception (instead of returning `false` or `nil`) if keyword
|
2108
|
+
# argument `exception` is set to `true`.
|
2109
|
+
#
|
2110
|
+
# Assigns the command's error status to `$?`.
|
2111
|
+
#
|
2112
|
+
# The new process is created using the [system system
|
2113
|
+
# call](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/s
|
2114
|
+
# ystem.html); it may inherit some of its environment from the calling program
|
2115
|
+
# (possibly including open file descriptors).
|
2116
|
+
#
|
2117
|
+
# Argument `env`, if given, is a hash that affects `ENV` for the new process;
|
2118
|
+
# see [Execution Environment](rdoc-ref:Process@Execution+Environment).
|
2119
|
+
#
|
2120
|
+
# Argument `options` is a hash of options for the new process; see [Execution
|
2121
|
+
# Options](rdoc-ref:Process@Execution+Options).
|
2122
|
+
#
|
2123
|
+
# The first required argument is one of the following:
|
2124
|
+
#
|
2125
|
+
# * `command_line` if it is a string, and if it begins with a shell reserved
|
2126
|
+
# word or special built-in, or if it contains one or more meta characters.
|
2127
|
+
# * `exe_path` otherwise.
|
2128
|
+
#
|
2129
|
+
# **Argument `command_line`**
|
2130
|
+
#
|
2131
|
+
# String argument `command_line` is a command line to be passed to a shell; it
|
2132
|
+
# must begin with a shell reserved word, begin with a special built-in, or
|
2133
|
+
# contain meta characters:
|
2134
|
+
#
|
2135
|
+
# system('if true; then echo "Foo"; fi') # => true # Shell reserved word.
|
2136
|
+
# system('exit') # => true # Built-in.
|
2137
|
+
# system('date > /tmp/date.tmp') # => true # Contains meta character.
|
2138
|
+
# system('date > /nop/date.tmp') # => false
|
2139
|
+
# system('date > /nop/date.tmp', exception: true) # Raises RuntimeError.
|
2140
|
+
#
|
2141
|
+
# Assigns the command's error status to `$?`:
|
2142
|
+
#
|
2143
|
+
# system('exit') # => true # Built-in.
|
2144
|
+
# $? # => #<Process::Status: pid 640610 exit 0>
|
2145
|
+
# system('date > /nop/date.tmp') # => false
|
2146
|
+
# $? # => #<Process::Status: pid 640742 exit 2>
|
2147
|
+
#
|
2148
|
+
# The command line may also contain arguments and options for the command:
|
2149
|
+
#
|
2150
|
+
# system('echo "Foo"') # => true
|
2151
|
+
#
|
2152
|
+
# Output:
|
2153
|
+
#
|
2154
|
+
# Foo
|
2155
|
+
#
|
2156
|
+
# See [Execution Shell](rdoc-ref:Process@Execution+Shell) for details about the
|
2157
|
+
# shell.
|
2158
|
+
#
|
2159
|
+
# Raises an exception if the new process could not execute.
|
2160
|
+
#
|
2161
|
+
# **Argument `exe_path`**
|
2162
|
+
#
|
2163
|
+
# Argument `exe_path` is one of the following:
|
2164
|
+
#
|
2165
|
+
# * The string path to an executable to be called.
|
2166
|
+
# * A 2-element array containing the path to an executable and the string to
|
2167
|
+
# be used as the name of the executing process.
|
2168
|
+
#
|
2169
|
+
# Example:
|
2170
|
+
#
|
2171
|
+
# system('/usr/bin/date') # => true # Path to date on Unix-style system.
|
2172
|
+
# system('foo') # => nil # Command failed.
|
2173
|
+
#
|
2174
|
+
# Output:
|
2175
|
+
#
|
2176
|
+
# Mon Aug 28 11:43:10 AM CDT 2023
|
2177
|
+
#
|
2178
|
+
# Assigns the command's error status to `$?`:
|
2179
|
+
#
|
2180
|
+
# system('/usr/bin/date') # => true
|
2181
|
+
# $? # => #<Process::Status: pid 645605 exit 0>
|
2182
|
+
# system('foo') # => nil
|
2183
|
+
# $? # => #<Process::Status: pid 645608 exit 127>
|
2184
|
+
#
|
2185
|
+
# Ruby invokes the executable directly. This form does not use the shell; see
|
2186
|
+
# [Arguments args](rdoc-ref:Process@Arguments+args) for caveats.
|
2187
|
+
#
|
2188
|
+
# system('doesnt_exist') # => nil
|
2189
|
+
#
|
2190
|
+
# If one or more `args` is given, each is an argument or option to be passed to
|
2191
|
+
# the executable:
|
2192
|
+
#
|
2193
|
+
# system('echo', 'C*') # => true
|
2194
|
+
# system('echo', 'hello', 'world') # => true
|
2195
|
+
#
|
2196
|
+
# Output:
|
2197
|
+
#
|
2198
|
+
# C*
|
2199
|
+
# hello world
|
2200
|
+
#
|
2201
|
+
# Raises an exception if the new process could not execute.
|
2202
|
+
#
|
2203
|
+
def self?.system: (String command, *String args, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String, ?exception: bool) -> (NilClass | FalseClass | TrueClass)
|
2204
|
+
| (Hash[string, string?] env, String command, *String args, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String, ?exception: bool) -> (NilClass | FalseClass | TrueClass)
|
2205
|
+
|
2206
|
+
# <!--
|
2207
|
+
# rdoc-file=object.c
|
2208
|
+
# - obj !~ other -> true or false
|
2209
|
+
# -->
|
2210
|
+
# Returns true if two objects do not match (using the *=~* method), otherwise
|
2211
|
+
# false.
|
2212
|
+
#
|
2213
|
+
def !~: (untyped other) -> bool
|
2214
|
+
|
2215
|
+
# <!--
|
2216
|
+
# rdoc-file=object.c
|
2217
|
+
# - obj <=> other -> 0 or nil
|
2218
|
+
# -->
|
2219
|
+
# Returns 0 if `obj` and `other` are the same object or `obj == other`,
|
2220
|
+
# otherwise nil.
|
2221
|
+
#
|
2222
|
+
# The #<=> is used by various methods to compare objects, for example
|
2223
|
+
# Enumerable#sort, Enumerable#max etc.
|
2224
|
+
#
|
2225
|
+
# Your implementation of #<=> should return one of the following values: -1, 0,
|
2226
|
+
# 1 or nil. -1 means self is smaller than other. 0 means self is equal to other.
|
2227
|
+
# 1 means self is bigger than other. Nil means the two values could not be
|
2228
|
+
# compared.
|
2229
|
+
#
|
2230
|
+
# When you define #<=>, you can include Comparable to gain the methods #<=, #<,
|
2231
|
+
# #==, #>=, #> and #between?.
|
2232
|
+
#
|
2233
|
+
def <=>: (untyped other) -> 0?
|
2234
|
+
|
2235
|
+
# <!--
|
2236
|
+
# rdoc-file=object.c
|
2237
|
+
# - obj === other -> true or false
|
2238
|
+
# -->
|
2239
|
+
# Case Equality -- For class Object, effectively the same as calling `#==`, but
|
2240
|
+
# typically overridden by descendants to provide meaningful semantics in `case`
|
2241
|
+
# statements.
|
2242
|
+
#
|
2243
|
+
alias === ==
|
2244
|
+
|
2245
|
+
# <!--
|
2246
|
+
# rdoc-file=kernel.rb
|
2247
|
+
# - obj.clone(freeze: nil) -> an_object
|
2248
|
+
# -->
|
2249
|
+
# Produces a shallow copy of *obj*---the instance variables of *obj* are copied,
|
2250
|
+
# but not the objects they reference. #clone copies the frozen value state of
|
2251
|
+
# *obj*, unless the `:freeze` keyword argument is given with a false or true
|
2252
|
+
# value. See also the discussion under Object#dup.
|
2253
|
+
#
|
2254
|
+
# class Klass
|
2255
|
+
# attr_accessor :str
|
2256
|
+
# end
|
2257
|
+
# s1 = Klass.new #=> #<Klass:0x401b3a38>
|
2258
|
+
# s1.str = "Hello" #=> "Hello"
|
2259
|
+
# s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello">
|
2260
|
+
# s2.str[1,4] = "i" #=> "i"
|
2261
|
+
# s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
|
2262
|
+
# s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
|
2263
|
+
#
|
2264
|
+
# This method may have class-specific behavior. If so, that behavior will be
|
2265
|
+
# documented under the #`initialize_copy` method of the class.
|
2266
|
+
#
|
2267
|
+
def clone: (?freeze: bool?) -> self
|
2268
|
+
|
2269
|
+
# <!--
|
2270
|
+
# rdoc-file=proc.c
|
2271
|
+
# - define_singleton_method(symbol, method) -> symbol
|
2272
|
+
# - define_singleton_method(symbol) { block } -> symbol
|
2273
|
+
# -->
|
2274
|
+
# Defines a public singleton method in the receiver. The *method* parameter can
|
2275
|
+
# be a `Proc`, a `Method` or an `UnboundMethod` object. If a block is specified,
|
2276
|
+
# it is used as the method body. If a block or a method has parameters, they're
|
2277
|
+
# used as method parameters.
|
2278
|
+
#
|
2279
|
+
# class A
|
2280
|
+
# class << self
|
2281
|
+
# def class_name
|
2282
|
+
# to_s
|
2283
|
+
# end
|
2284
|
+
# end
|
2285
|
+
# end
|
2286
|
+
# A.define_singleton_method(:who_am_i) do
|
2287
|
+
# "I am: #{class_name}"
|
2288
|
+
# end
|
2289
|
+
# A.who_am_i # ==> "I am: A"
|
2290
|
+
#
|
2291
|
+
# guy = "Bob"
|
2292
|
+
# guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
|
2293
|
+
# guy.hello #=> "Bob: Hello there!"
|
2294
|
+
#
|
2295
|
+
# chris = "Chris"
|
2296
|
+
# chris.define_singleton_method(:greet) {|greeting| "#{greeting}, I'm Chris!" }
|
2297
|
+
# chris.greet("Hi") #=> "Hi, I'm Chris!"
|
2298
|
+
#
|
2299
|
+
def define_singleton_method: (interned name, Method | UnboundMethod | Proc method) -> Symbol
|
2300
|
+
| (interned name) { (?) -> untyped } -> Symbol
|
2301
|
+
|
2302
|
+
# <!--
|
2303
|
+
# rdoc-file=io.c
|
2304
|
+
# - display(port = $>) -> nil
|
2305
|
+
# -->
|
2306
|
+
# Writes `self` on the given port:
|
2307
|
+
#
|
2308
|
+
# 1.display
|
2309
|
+
# "cat".display
|
2310
|
+
# [ 4, 5, 6 ].display
|
2311
|
+
# puts
|
2312
|
+
#
|
2313
|
+
# Output:
|
2314
|
+
#
|
2315
|
+
# 1cat[4, 5, 6]
|
2316
|
+
#
|
2317
|
+
def display: (?_Writer port) -> nil
|
2318
|
+
|
2319
|
+
# <!--
|
2320
|
+
# rdoc-file=object.c
|
2321
|
+
# - obj.dup -> an_object
|
2322
|
+
# -->
|
2323
|
+
# Produces a shallow copy of *obj*---the instance variables of *obj* are copied,
|
2324
|
+
# but not the objects they reference.
|
2325
|
+
#
|
2326
|
+
# This method may have class-specific behavior. If so, that behavior will be
|
2327
|
+
# documented under the #`initialize_copy` method of the class.
|
2328
|
+
#
|
2329
|
+
# ### on dup vs clone
|
2330
|
+
#
|
2331
|
+
# In general, #clone and #dup may have different semantics in descendant
|
2332
|
+
# classes. While #clone is used to duplicate an object, including its internal
|
2333
|
+
# state, #dup typically uses the class of the descendant object to create the
|
2334
|
+
# new instance.
|
2335
|
+
#
|
2336
|
+
# When using #dup, any modules that the object has been extended with will not
|
2337
|
+
# be copied.
|
2338
|
+
#
|
2339
|
+
# class Klass
|
2340
|
+
# attr_accessor :str
|
2341
|
+
# end
|
2342
|
+
#
|
2343
|
+
# module Foo
|
2344
|
+
# def foo; 'foo'; end
|
2345
|
+
# end
|
2346
|
+
#
|
2347
|
+
# s1 = Klass.new #=> #<Klass:0x401b3a38>
|
2348
|
+
# s1.extend(Foo) #=> #<Klass:0x401b3a38>
|
2349
|
+
# s1.foo #=> "foo"
|
2350
|
+
#
|
2351
|
+
# s2 = s1.clone #=> #<Klass:0x401be280>
|
2352
|
+
# s2.foo #=> "foo"
|
2353
|
+
#
|
2354
|
+
# s3 = s1.dup #=> #<Klass:0x401c1084>
|
2355
|
+
# s3.foo #=> NoMethodError: undefined method `foo' for #<Klass:0x401c1084>
|
2356
|
+
#
|
2357
|
+
def dup: () -> self
|
2358
|
+
|
2359
|
+
# <!-- rdoc-file=enumerator.c -->
|
2360
|
+
# Creates a new Enumerator which will enumerate by calling `method` on `obj`,
|
2361
|
+
# passing `args` if any. What was *yielded* by method becomes values of
|
2362
|
+
# enumerator.
|
2363
|
+
#
|
2364
|
+
# If a block is given, it will be used to calculate the size of the enumerator
|
2365
|
+
# without the need to iterate it (see Enumerator#size).
|
2366
|
+
#
|
2367
|
+
# ### Examples
|
2368
|
+
#
|
2369
|
+
# str = "xyz"
|
2370
|
+
#
|
2371
|
+
# enum = str.enum_for(:each_byte)
|
2372
|
+
# enum.each { |b| puts b }
|
2373
|
+
# # => 120
|
2374
|
+
# # => 121
|
2375
|
+
# # => 122
|
2376
|
+
#
|
2377
|
+
# # protect an array from being modified by some_method
|
2378
|
+
# a = [1, 2, 3]
|
2379
|
+
# some_method(a.to_enum)
|
2380
|
+
#
|
2381
|
+
# # String#split in block form is more memory-effective:
|
2382
|
+
# very_large_string.split("|") { |chunk| return chunk if chunk.include?('DATE') }
|
2383
|
+
# # This could be rewritten more idiomatically with to_enum:
|
2384
|
+
# very_large_string.to_enum(:split, "|").lazy.grep(/DATE/).first
|
2385
|
+
#
|
2386
|
+
# It is typical to call to_enum when defining methods for a generic Enumerable,
|
2387
|
+
# in case no block is passed.
|
2388
|
+
#
|
2389
|
+
# Here is such an example, with parameter passing and a sizing block:
|
2390
|
+
#
|
2391
|
+
# module Enumerable
|
2392
|
+
# # a generic method to repeat the values of any enumerable
|
2393
|
+
# def repeat(n)
|
2394
|
+
# raise ArgumentError, "#{n} is negative!" if n < 0
|
2395
|
+
# unless block_given?
|
2396
|
+
# return to_enum(__method__, n) do # __method__ is :repeat here
|
2397
|
+
# sz = size # Call size and multiply by n...
|
2398
|
+
# sz * n if sz # but return nil if size itself is nil
|
2399
|
+
# end
|
2400
|
+
# end
|
2401
|
+
# each do |*val|
|
2402
|
+
# n.times { yield *val }
|
2403
|
+
# end
|
2404
|
+
# end
|
2405
|
+
# end
|
2406
|
+
#
|
2407
|
+
# %i[hello world].repeat(2) { |w| puts w }
|
2408
|
+
# # => Prints 'hello', 'hello', 'world', 'world'
|
2409
|
+
# enum = (1..14).repeat(3)
|
2410
|
+
# # => returns an Enumerator when called without a block
|
2411
|
+
# enum.first(4) # => [1, 1, 1, 2]
|
2412
|
+
# enum.size # => 42
|
2413
|
+
#
|
2414
|
+
def enum_for: (?interned method, *untyped, **untyped) ?{ (*untyped, **untyped) -> Integer } -> Enumerator[untyped, untyped]
|
2415
|
+
|
2416
|
+
alias to_enum enum_for
|
2417
|
+
|
2418
|
+
# <!--
|
2419
|
+
# rdoc-file=object.c
|
2420
|
+
# - obj == other -> true or false
|
2421
|
+
# - obj.equal?(other) -> true or false
|
2422
|
+
# - obj.eql?(other) -> true or false
|
2423
|
+
# -->
|
2424
|
+
# Equality --- At the Object level, #== returns `true` only if `obj` and `other`
|
2425
|
+
# are the same object. Typically, this method is overridden in descendant
|
2426
|
+
# classes to provide class-specific meaning.
|
2427
|
+
#
|
2428
|
+
# Unlike #==, the #equal? method should never be overridden by subclasses as it
|
2429
|
+
# is used to determine object identity (that is, `a.equal?(b)` if and only if
|
2430
|
+
# `a` is the same object as `b`):
|
2431
|
+
#
|
2432
|
+
# obj = "a"
|
2433
|
+
# other = obj.dup
|
2434
|
+
#
|
2435
|
+
# obj == other #=> true
|
2436
|
+
# obj.equal? other #=> false
|
2437
|
+
# obj.equal? obj #=> true
|
2438
|
+
#
|
2439
|
+
# The #eql? method returns `true` if `obj` and `other` refer to the same hash
|
2440
|
+
# key. This is used by Hash to test members for equality. For any pair of
|
2441
|
+
# objects where #eql? returns `true`, the #hash value of both objects must be
|
2442
|
+
# equal. So any subclass that overrides #eql? should also override #hash
|
2443
|
+
# appropriately.
|
2444
|
+
#
|
2445
|
+
# For objects of class Object, #eql? is synonymous with #==. Subclasses
|
2446
|
+
# normally continue this tradition by aliasing #eql? to their overridden #==
|
2447
|
+
# method, but there are exceptions. Numeric types, for example, perform type
|
2448
|
+
# conversion across #==, but not across #eql?, so:
|
2449
|
+
#
|
2450
|
+
# 1 == 1.0 #=> true
|
2451
|
+
# 1.eql? 1.0 #=> false
|
2452
|
+
#
|
2453
|
+
def eql?: (untyped other) -> bool
|
2454
|
+
|
2455
|
+
# <!--
|
2456
|
+
# rdoc-file=eval.c
|
2457
|
+
# - obj.extend(module, ...) -> obj
|
2458
|
+
# -->
|
2459
|
+
# Adds to *obj* the instance methods from each module given as a parameter.
|
2460
|
+
#
|
2461
|
+
# module Mod
|
2462
|
+
# def hello
|
2463
|
+
# "Hello from Mod.\n"
|
2464
|
+
# end
|
2465
|
+
# end
|
2466
|
+
#
|
2467
|
+
# class Klass
|
2468
|
+
# def hello
|
2469
|
+
# "Hello from Klass.\n"
|
2470
|
+
# end
|
2471
|
+
# end
|
2472
|
+
#
|
2473
|
+
# k = Klass.new
|
2474
|
+
# k.hello #=> "Hello from Klass.\n"
|
2475
|
+
# k.extend(Mod) #=> #<Klass:0x401b3bc8>
|
2476
|
+
# k.hello #=> "Hello from Mod.\n"
|
2477
|
+
#
|
2478
|
+
def extend: (Module module, *Module other_modules) -> self
|
2479
|
+
|
2480
|
+
# <!--
|
2481
|
+
# rdoc-file=object.c
|
2482
|
+
# - obj.freeze -> obj
|
2483
|
+
# -->
|
2484
|
+
# Prevents further modifications to *obj*. A FrozenError will be raised if
|
2485
|
+
# modification is attempted. There is no way to unfreeze a frozen object. See
|
2486
|
+
# also Object#frozen?.
|
2487
|
+
#
|
2488
|
+
# This method returns self.
|
2489
|
+
#
|
2490
|
+
# a = [ "a", "b", "c" ]
|
2491
|
+
# a.freeze
|
2492
|
+
# a << "z"
|
2493
|
+
#
|
2494
|
+
# *produces:*
|
2495
|
+
#
|
2496
|
+
# prog.rb:3:in `<<': can't modify frozen Array (FrozenError)
|
2497
|
+
# from prog.rb:3
|
2498
|
+
#
|
2499
|
+
# Objects of the following classes are always frozen: Integer, Float, Symbol.
|
2500
|
+
#
|
2501
|
+
def freeze: () -> self
|
2502
|
+
|
2503
|
+
# <!--
|
2504
|
+
# rdoc-file=kernel.rb
|
2505
|
+
# - obj.frozen? -> true or false
|
2506
|
+
# -->
|
2507
|
+
# Returns the freeze status of *obj*.
|
2508
|
+
#
|
2509
|
+
# a = [ "a", "b", "c" ]
|
2510
|
+
# a.freeze #=> ["a", "b", "c"]
|
2511
|
+
# a.frozen? #=> true
|
2512
|
+
#
|
2513
|
+
def frozen?: () -> bool
|
2514
|
+
|
2515
|
+
# <!--
|
2516
|
+
# rdoc-file=object.c
|
2517
|
+
# - obj.hash -> integer
|
2518
|
+
# -->
|
2519
|
+
# Generates an Integer hash value for this object. This function must have the
|
2520
|
+
# property that `a.eql?(b)` implies `a.hash == b.hash`.
|
2521
|
+
#
|
2522
|
+
# The hash value is used along with #eql? by the Hash class to determine if two
|
2523
|
+
# objects reference the same hash key. Any hash value that exceeds the capacity
|
2524
|
+
# of an Integer will be truncated before being used.
|
2525
|
+
#
|
2526
|
+
# The hash value for an object may not be identical across invocations or
|
2527
|
+
# implementations of Ruby. If you need a stable identifier across Ruby
|
2528
|
+
# invocations and implementations you will need to generate one with a custom
|
2529
|
+
# method.
|
2530
|
+
#
|
2531
|
+
# Certain core classes such as Integer use built-in hash calculations and do not
|
2532
|
+
# call the #hash method when used as a hash key.
|
2533
|
+
#
|
2534
|
+
# When implementing your own #hash based on multiple values, the best practice
|
2535
|
+
# is to combine the class and any values using the hash code of an array:
|
2536
|
+
#
|
2537
|
+
# For example:
|
2538
|
+
#
|
2539
|
+
# def hash
|
2540
|
+
# [self.class, a, b, c].hash
|
2541
|
+
# end
|
2542
|
+
#
|
2543
|
+
# The reason for this is that the Array#hash method already has logic for safely
|
2544
|
+
# and efficiently combining multiple hash values.
|
2545
|
+
#
|
2546
|
+
def hash: () -> Integer
|
2547
|
+
|
2548
|
+
# <!--
|
2549
|
+
# rdoc-file=object.c
|
2550
|
+
# - obj.inspect -> string
|
2551
|
+
# -->
|
2552
|
+
# Returns a string containing a human-readable representation of *obj*. The
|
2553
|
+
# default #inspect shows the object's class name, an encoding of its memory
|
2554
|
+
# address, and a list of the instance variables and their values (by calling
|
2555
|
+
# #inspect on each of them). User defined classes should override this method
|
2556
|
+
# to provide a better representation of *obj*. When overriding this method, it
|
2557
|
+
# should return a string whose encoding is compatible with the default external
|
2558
|
+
# encoding.
|
2559
|
+
#
|
2560
|
+
# [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]"
|
2561
|
+
# Time.new.inspect #=> "2008-03-08 19:43:39 +0900"
|
2562
|
+
#
|
2563
|
+
# class Foo
|
2564
|
+
# end
|
2565
|
+
# Foo.new.inspect #=> "#<Foo:0x0300c868>"
|
2566
|
+
#
|
2567
|
+
# class Bar
|
2568
|
+
# def initialize
|
2569
|
+
# @bar = 1
|
2570
|
+
# end
|
2571
|
+
# end
|
2572
|
+
# Bar.new.inspect #=> "#<Bar:0x0300c868 @bar=1>"
|
2573
|
+
#
|
2574
|
+
def inspect: () -> String
|
2575
|
+
|
2576
|
+
# <!--
|
2577
|
+
# rdoc-file=object.c
|
2578
|
+
# - obj.instance_of?(class) -> true or false
|
2579
|
+
# -->
|
2580
|
+
# Returns `true` if *obj* is an instance of the given class. See also
|
2581
|
+
# Object#kind_of?.
|
2582
|
+
#
|
2583
|
+
# class A; end
|
2584
|
+
# class B < A; end
|
2585
|
+
# class C < B; end
|
2586
|
+
#
|
2587
|
+
# b = B.new
|
2588
|
+
# b.instance_of? A #=> false
|
2589
|
+
# b.instance_of? B #=> true
|
2590
|
+
# b.instance_of? C #=> false
|
2591
|
+
#
|
2592
|
+
def instance_of?: (Module | Class module_or_class) -> bool
|
2593
|
+
|
2594
|
+
# <!--
|
2595
|
+
# rdoc-file=object.c
|
2596
|
+
# - obj.instance_variable_defined?(symbol) -> true or false
|
2597
|
+
# - obj.instance_variable_defined?(string) -> true or false
|
2598
|
+
# -->
|
2599
|
+
# Returns `true` if the given instance variable is defined in *obj*. String
|
2600
|
+
# arguments are converted to symbols.
|
2601
|
+
#
|
2602
|
+
# class Fred
|
2603
|
+
# def initialize(p1, p2)
|
2604
|
+
# @a, @b = p1, p2
|
2605
|
+
# end
|
2606
|
+
# end
|
2607
|
+
# fred = Fred.new('cat', 99)
|
2608
|
+
# fred.instance_variable_defined?(:@a) #=> true
|
2609
|
+
# fred.instance_variable_defined?("@b") #=> true
|
2610
|
+
# fred.instance_variable_defined?("@c") #=> false
|
2611
|
+
#
|
2612
|
+
def instance_variable_defined?: (interned variable) -> bool
|
2613
|
+
|
2614
|
+
# <!--
|
2615
|
+
# rdoc-file=object.c
|
2616
|
+
# - obj.instance_variable_get(symbol) -> obj
|
2617
|
+
# - obj.instance_variable_get(string) -> obj
|
2618
|
+
# -->
|
2619
|
+
# Returns the value of the given instance variable, or nil if the instance
|
2620
|
+
# variable is not set. The `@` part of the variable name should be included for
|
2621
|
+
# regular instance variables. Throws a NameError exception if the supplied
|
2622
|
+
# symbol is not valid as an instance variable name. String arguments are
|
2623
|
+
# converted to symbols.
|
2624
|
+
#
|
2625
|
+
# class Fred
|
2626
|
+
# def initialize(p1, p2)
|
2627
|
+
# @a, @b = p1, p2
|
2628
|
+
# end
|
2629
|
+
# end
|
2630
|
+
# fred = Fred.new('cat', 99)
|
2631
|
+
# fred.instance_variable_get(:@a) #=> "cat"
|
2632
|
+
# fred.instance_variable_get("@b") #=> 99
|
2633
|
+
#
|
2634
|
+
def instance_variable_get: (interned variable) -> untyped
|
2635
|
+
|
2636
|
+
# <!--
|
2637
|
+
# rdoc-file=object.c
|
2638
|
+
# - obj.instance_variable_set(symbol, obj) -> obj
|
2639
|
+
# - obj.instance_variable_set(string, obj) -> obj
|
2640
|
+
# -->
|
2641
|
+
# Sets the instance variable named by *symbol* to the given object. This may
|
2642
|
+
# circumvent the encapsulation intended by the author of the class, so it should
|
2643
|
+
# be used with care. The variable does not have to exist prior to this call. If
|
2644
|
+
# the instance variable name is passed as a string, that string is converted to
|
2645
|
+
# a symbol.
|
2646
|
+
#
|
2647
|
+
# class Fred
|
2648
|
+
# def initialize(p1, p2)
|
2649
|
+
# @a, @b = p1, p2
|
2650
|
+
# end
|
2651
|
+
# end
|
2652
|
+
# fred = Fred.new('cat', 99)
|
2653
|
+
# fred.instance_variable_set(:@a, 'dog') #=> "dog"
|
2654
|
+
# fred.instance_variable_set(:@c, 'cat') #=> "cat"
|
2655
|
+
# fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
|
2656
|
+
#
|
2657
|
+
def instance_variable_set: [T] (interned variable, T value) -> T
|
2658
|
+
|
2659
|
+
# <!--
|
2660
|
+
# rdoc-file=object.c
|
2661
|
+
# - obj.instance_variables -> array
|
2662
|
+
# -->
|
2663
|
+
# Returns an array of instance variable names for the receiver. Note that simply
|
2664
|
+
# defining an accessor does not create the corresponding instance variable.
|
2665
|
+
#
|
2666
|
+
# class Fred
|
2667
|
+
# attr_accessor :a1
|
2668
|
+
# def initialize
|
2669
|
+
# @iv = 3
|
2670
|
+
# end
|
2671
|
+
# end
|
2672
|
+
# Fred.new.instance_variables #=> [:@iv]
|
2673
|
+
#
|
2674
|
+
def instance_variables: () -> Array[Symbol]
|
2675
|
+
|
2676
|
+
# <!-- rdoc-file=object.c -->
|
2677
|
+
# Returns `true` if *class* is the class of *obj*, or if *class* is one of the
|
2678
|
+
# superclasses of *obj* or modules included in *obj*.
|
2679
|
+
#
|
2680
|
+
# module M; end
|
2681
|
+
# class A
|
2682
|
+
# include M
|
2683
|
+
# end
|
2684
|
+
# class B < A; end
|
2685
|
+
# class C < B; end
|
2686
|
+
#
|
2687
|
+
# b = B.new
|
2688
|
+
# b.is_a? A #=> true
|
2689
|
+
# b.is_a? B #=> true
|
2690
|
+
# b.is_a? C #=> false
|
2691
|
+
# b.is_a? M #=> true
|
2692
|
+
#
|
2693
|
+
# b.kind_of? A #=> true
|
2694
|
+
# b.kind_of? B #=> true
|
2695
|
+
# b.kind_of? C #=> false
|
2696
|
+
# b.kind_of? M #=> true
|
2697
|
+
#
|
2698
|
+
def is_a?: (Module | Class module_or_class) -> bool
|
2699
|
+
|
2700
|
+
alias kind_of? is_a?
|
2701
|
+
|
2702
|
+
# <!--
|
2703
|
+
# rdoc-file=object.c
|
2704
|
+
# - obj.itself -> obj
|
2705
|
+
# -->
|
2706
|
+
# Returns the receiver.
|
2707
|
+
#
|
2708
|
+
# string = "my string"
|
2709
|
+
# string.itself.object_id == string.object_id #=> true
|
2710
|
+
#
|
2711
|
+
def itself: () -> self
|
2712
|
+
|
2713
|
+
# <!--
|
2714
|
+
# rdoc-file=proc.c
|
2715
|
+
# - obj.method(sym) -> method
|
2716
|
+
# -->
|
2717
|
+
# Looks up the named method as a receiver in *obj*, returning a Method object
|
2718
|
+
# (or raising NameError). The Method object acts as a closure in *obj*'s object
|
2719
|
+
# instance, so instance variables and the value of `self` remain available.
|
2720
|
+
#
|
2721
|
+
# class Demo
|
2722
|
+
# def initialize(n)
|
2723
|
+
# @iv = n
|
2724
|
+
# end
|
2725
|
+
# def hello()
|
2726
|
+
# "Hello, @iv = #{@iv}"
|
2727
|
+
# end
|
2728
|
+
# end
|
2729
|
+
#
|
2730
|
+
# k = Demo.new(99)
|
2731
|
+
# m = k.method(:hello)
|
2732
|
+
# m.call #=> "Hello, @iv = 99"
|
2733
|
+
#
|
2734
|
+
# l = Demo.new('Fred')
|
2735
|
+
# m = l.method("hello")
|
2736
|
+
# m.call #=> "Hello, @iv = Fred"
|
2737
|
+
#
|
2738
|
+
# Note that Method implements `to_proc` method, which means it can be used with
|
2739
|
+
# iterators.
|
2740
|
+
#
|
2741
|
+
# [ 1, 2, 3 ].each(&method(:puts)) # => prints 3 lines to stdout
|
2742
|
+
#
|
2743
|
+
# out = File.open('test.txt', 'w')
|
2744
|
+
# [ 1, 2, 3 ].each(&out.method(:puts)) # => prints 3 lines to file
|
2745
|
+
#
|
2746
|
+
# require 'date'
|
2747
|
+
# %w[2017-03-01 2017-03-02].collect(&Date.method(:parse))
|
2748
|
+
# #=> [#<Date: 2017-03-01 ((2457814j,0s,0n),+0s,2299161j)>, #<Date: 2017-03-02 ((2457815j,0s,0n),+0s,2299161j)>]
|
2749
|
+
#
|
2750
|
+
def method: (interned name) -> Method
|
2751
|
+
|
2752
|
+
# <!--
|
2753
|
+
# rdoc-file=object.c
|
2754
|
+
# - obj.methods(regular=true) -> array
|
2755
|
+
# -->
|
2756
|
+
# Returns a list of the names of public and protected methods of *obj*. This
|
2757
|
+
# will include all the methods accessible in *obj*'s ancestors. If the optional
|
2758
|
+
# parameter is `false`, it returns an array of *obj*'s public and protected
|
2759
|
+
# singleton methods, the array will not include methods in modules included in
|
2760
|
+
# *obj*.
|
2761
|
+
#
|
2762
|
+
# class Klass
|
2763
|
+
# def klass_method()
|
2764
|
+
# end
|
2765
|
+
# end
|
2766
|
+
# k = Klass.new
|
2767
|
+
# k.methods[0..9] #=> [:klass_method, :nil?, :===,
|
2768
|
+
# # :==~, :!, :eql?
|
2769
|
+
# # :hash, :<=>, :class, :singleton_class]
|
2770
|
+
# k.methods.length #=> 56
|
2771
|
+
#
|
2772
|
+
# k.methods(false) #=> []
|
2773
|
+
# def k.singleton_method; end
|
2774
|
+
# k.methods(false) #=> [:singleton_method]
|
2775
|
+
#
|
2776
|
+
# module M123; def m123; end end
|
2777
|
+
# k.extend M123
|
2778
|
+
# k.methods(false) #=> [:singleton_method]
|
2779
|
+
#
|
2780
|
+
def methods: (?boolish regular) -> Array[Symbol]
|
2781
|
+
|
2782
|
+
# <!--
|
2783
|
+
# rdoc-file=object.c
|
2784
|
+
# - obj.nil? -> true or false
|
2785
|
+
# -->
|
2786
|
+
# Only the object *nil* responds `true` to `nil?`.
|
2787
|
+
#
|
2788
|
+
# Object.new.nil? #=> false
|
2789
|
+
# nil.nil? #=> true
|
2790
|
+
#
|
2791
|
+
def nil?: () -> false
|
2792
|
+
|
2793
|
+
# <!--
|
2794
|
+
# rdoc-file=gc.c
|
2795
|
+
# - obj.__id__ -> integer
|
2796
|
+
# - obj.object_id -> integer
|
2797
|
+
# -->
|
2798
|
+
# Returns an integer identifier for `obj`.
|
2799
|
+
#
|
2800
|
+
# The same number will be returned on all calls to `object_id` for a given
|
2801
|
+
# object, and no two active objects will share an id.
|
2802
|
+
#
|
2803
|
+
# Note: that some objects of builtin classes are reused for optimization. This
|
2804
|
+
# is the case for immediate values and frozen string literals.
|
2805
|
+
#
|
2806
|
+
# BasicObject implements +__id__+, Kernel implements `object_id`.
|
2807
|
+
#
|
2808
|
+
# Immediate values are not passed by reference but are passed by value: `nil`,
|
2809
|
+
# `true`, `false`, Fixnums, Symbols, and some Floats.
|
2810
|
+
#
|
2811
|
+
# Object.new.object_id == Object.new.object_id # => false
|
2812
|
+
# (21 * 2).object_id == (21 * 2).object_id # => true
|
2813
|
+
# "hello".object_id == "hello".object_id # => false
|
2814
|
+
# "hi".freeze.object_id == "hi".freeze.object_id # => true
|
2815
|
+
#
|
2816
|
+
alias object_id __id__
|
2817
|
+
|
2818
|
+
# <!--
|
2819
|
+
# rdoc-file=object.c
|
2820
|
+
# - obj.private_methods(all=true) -> array
|
2821
|
+
# -->
|
2822
|
+
# Returns the list of private methods accessible to *obj*. If the *all*
|
2823
|
+
# parameter is set to `false`, only those methods in the receiver will be
|
2824
|
+
# listed.
|
2825
|
+
#
|
2826
|
+
def private_methods: (?boolish all) -> Array[Symbol]
|
2827
|
+
|
2828
|
+
# <!--
|
2829
|
+
# rdoc-file=object.c
|
2830
|
+
# - obj.protected_methods(all=true) -> array
|
2831
|
+
# -->
|
2832
|
+
# Returns the list of protected methods accessible to *obj*. If the *all*
|
2833
|
+
# parameter is set to `false`, only those methods in the receiver will be
|
2834
|
+
# listed.
|
2835
|
+
#
|
2836
|
+
def protected_methods: (?boolish all) -> Array[Symbol]
|
2837
|
+
|
2838
|
+
# <!--
|
2839
|
+
# rdoc-file=proc.c
|
2840
|
+
# - obj.public_method(sym) -> method
|
2841
|
+
# -->
|
2842
|
+
# Similar to *method*, searches public method only.
|
2843
|
+
#
|
2844
|
+
def public_method: (interned name) -> Method
|
2845
|
+
|
2846
|
+
# <!--
|
2847
|
+
# rdoc-file=object.c
|
2848
|
+
# - obj.public_methods(all=true) -> array
|
2849
|
+
# -->
|
2850
|
+
# Returns the list of public methods accessible to *obj*. If the *all* parameter
|
2851
|
+
# is set to `false`, only those methods in the receiver will be listed.
|
2852
|
+
#
|
2853
|
+
def public_methods: (?boolish all) -> Array[Symbol]
|
2854
|
+
|
2855
|
+
# <!--
|
2856
|
+
# rdoc-file=vm_eval.c
|
2857
|
+
# - obj.public_send(symbol [, args...]) -> obj
|
2858
|
+
# - obj.public_send(string [, args...]) -> obj
|
2859
|
+
# -->
|
2860
|
+
# Invokes the method identified by *symbol*, passing it any arguments specified.
|
2861
|
+
# Unlike send, public_send calls public methods only. When the method is
|
2862
|
+
# identified by a string, the string is converted to a symbol.
|
2863
|
+
#
|
2864
|
+
# 1.public_send(:puts, "hello") # causes NoMethodError
|
2865
|
+
#
|
2866
|
+
def public_send: (interned name, *untyped, **untyped) ?{ (?) -> untyped } -> untyped
|
2867
|
+
|
2868
|
+
# <!--
|
2869
|
+
# rdoc-file=object.c
|
2870
|
+
# - obj.remove_instance_variable(symbol) -> obj
|
2871
|
+
# - obj.remove_instance_variable(string) -> obj
|
2872
|
+
# -->
|
2873
|
+
# Removes the named instance variable from *obj*, returning that variable's
|
2874
|
+
# value. String arguments are converted to symbols.
|
2875
|
+
#
|
2876
|
+
# class Dummy
|
2877
|
+
# attr_reader :var
|
2878
|
+
# def initialize
|
2879
|
+
# @var = 99
|
2880
|
+
# end
|
2881
|
+
# def remove
|
2882
|
+
# remove_instance_variable(:@var)
|
2883
|
+
# end
|
2884
|
+
# end
|
2885
|
+
# d = Dummy.new
|
2886
|
+
# d.var #=> 99
|
2887
|
+
# d.remove #=> 99
|
2888
|
+
# d.var #=> nil
|
2889
|
+
#
|
2890
|
+
def remove_instance_variable: (interned variable) -> untyped
|
2891
|
+
|
2892
|
+
# <!--
|
2893
|
+
# rdoc-file=vm_method.c
|
2894
|
+
# - obj.respond_to?(symbol, include_all=false) -> true or false
|
2895
|
+
# - obj.respond_to?(string, include_all=false) -> true or false
|
2896
|
+
# -->
|
2897
|
+
# Returns `true` if *obj* responds to the given method. Private and protected
|
2898
|
+
# methods are included in the search only if the optional second parameter
|
2899
|
+
# evaluates to `true`.
|
2900
|
+
#
|
2901
|
+
# If the method is not implemented, as Process.fork on Windows, File.lchmod on
|
2902
|
+
# GNU/Linux, etc., false is returned.
|
2903
|
+
#
|
2904
|
+
# If the method is not defined, `respond_to_missing?` method is called and the
|
2905
|
+
# result is returned.
|
2906
|
+
#
|
2907
|
+
# When the method name parameter is given as a string, the string is converted
|
2908
|
+
# to a symbol.
|
2909
|
+
#
|
2910
|
+
def respond_to?: (interned name, ?boolish include_all) -> bool
|
2911
|
+
|
2912
|
+
# <!--
|
2913
|
+
# rdoc-file=vm_method.c
|
2914
|
+
# - obj.respond_to_missing?(symbol, include_all) -> true or false
|
2915
|
+
# - obj.respond_to_missing?(string, include_all) -> true or false
|
2916
|
+
# -->
|
2917
|
+
# DO NOT USE THIS DIRECTLY.
|
2918
|
+
#
|
2919
|
+
# Hook method to return whether the *obj* can respond to *id* method or not.
|
2920
|
+
#
|
2921
|
+
# When the method name parameter is given as a string, the string is converted
|
2922
|
+
# to a symbol.
|
2923
|
+
#
|
2924
|
+
# See #respond_to?, and the example of BasicObject.
|
2925
|
+
#
|
2926
|
+
private def respond_to_missing?: (Symbol | String name, bool include_all) -> bool
|
2927
|
+
|
2928
|
+
# <!--
|
2929
|
+
# rdoc-file=vm_eval.c
|
2930
|
+
# - foo.send(symbol [, args...]) -> obj
|
2931
|
+
# - foo.__send__(symbol [, args...]) -> obj
|
2932
|
+
# - foo.send(string [, args...]) -> obj
|
2933
|
+
# - foo.__send__(string [, args...]) -> obj
|
2934
|
+
# -->
|
2935
|
+
# Invokes the method identified by *symbol*, passing it any arguments specified.
|
2936
|
+
# When the method is identified by a string, the string is converted to a
|
2937
|
+
# symbol.
|
2938
|
+
#
|
2939
|
+
# BasicObject implements +__send__+, Kernel implements `send`. `__send__` is
|
2940
|
+
# safer than `send` when *obj* has the same method name like `Socket`. See also
|
2941
|
+
# `public_send`.
|
2942
|
+
#
|
2943
|
+
# class Klass
|
2944
|
+
# def hello(*args)
|
2945
|
+
# "Hello " + args.join(' ')
|
2946
|
+
# end
|
2947
|
+
# end
|
2948
|
+
# k = Klass.new
|
2949
|
+
# k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
|
2950
|
+
#
|
2951
|
+
alias send __send__
|
2952
|
+
|
2953
|
+
# <!--
|
2954
|
+
# rdoc-file=object.c
|
2955
|
+
# - obj.singleton_class -> class
|
2956
|
+
# -->
|
2957
|
+
# Returns the singleton class of *obj*. This method creates a new singleton
|
2958
|
+
# class if *obj* does not have one.
|
2959
|
+
#
|
2960
|
+
# If *obj* is `nil`, `true`, or `false`, it returns NilClass, TrueClass, or
|
2961
|
+
# FalseClass, respectively. If *obj* is an Integer, a Float or a Symbol, it
|
2962
|
+
# raises a TypeError.
|
2963
|
+
#
|
2964
|
+
# Object.new.singleton_class #=> #<Class:#<Object:0xb7ce1e24>>
|
2965
|
+
# String.singleton_class #=> #<Class:String>
|
2966
|
+
# nil.singleton_class #=> NilClass
|
2967
|
+
#
|
2968
|
+
def singleton_class: () -> Class
|
2969
|
+
|
2970
|
+
# <!--
|
2971
|
+
# rdoc-file=proc.c
|
2972
|
+
# - obj.singleton_method(sym) -> method
|
2973
|
+
# -->
|
2974
|
+
# Similar to *method*, searches singleton method only.
|
2975
|
+
#
|
2976
|
+
# class Demo
|
2977
|
+
# def initialize(n)
|
2978
|
+
# @iv = n
|
2979
|
+
# end
|
2980
|
+
# def hello()
|
2981
|
+
# "Hello, @iv = #{@iv}"
|
2982
|
+
# end
|
2983
|
+
# end
|
2984
|
+
#
|
2985
|
+
# k = Demo.new(99)
|
2986
|
+
# def k.hi
|
2987
|
+
# "Hi, @iv = #{@iv}"
|
2988
|
+
# end
|
2989
|
+
# m = k.singleton_method(:hi)
|
2990
|
+
# m.call #=> "Hi, @iv = 99"
|
2991
|
+
# m = k.singleton_method(:hello) #=> NameError
|
2992
|
+
#
|
2993
|
+
def singleton_method: (interned name) -> Method
|
2994
|
+
|
2995
|
+
# <!--
|
2996
|
+
# rdoc-file=object.c
|
2997
|
+
# - obj.singleton_methods(all=true) -> array
|
2998
|
+
# -->
|
2999
|
+
# Returns an array of the names of singleton methods for *obj*. If the optional
|
3000
|
+
# *all* parameter is true, the list will include methods in modules included in
|
3001
|
+
# *obj*. Only public and protected singleton methods are returned.
|
3002
|
+
#
|
3003
|
+
# module Other
|
3004
|
+
# def three() end
|
3005
|
+
# end
|
3006
|
+
#
|
3007
|
+
# class Single
|
3008
|
+
# def Single.four() end
|
3009
|
+
# end
|
3010
|
+
#
|
3011
|
+
# a = Single.new
|
3012
|
+
#
|
3013
|
+
# def a.one()
|
3014
|
+
# end
|
3015
|
+
#
|
3016
|
+
# class << a
|
3017
|
+
# include Other
|
3018
|
+
# def two()
|
3019
|
+
# end
|
3020
|
+
# end
|
3021
|
+
#
|
3022
|
+
# Single.singleton_methods #=> [:four]
|
3023
|
+
# a.singleton_methods(false) #=> [:two, :one]
|
3024
|
+
# a.singleton_methods #=> [:two, :one, :three]
|
3025
|
+
#
|
3026
|
+
def singleton_methods: (?boolish all) -> Array[Symbol]
|
3027
|
+
|
3028
|
+
# <!--
|
3029
|
+
# rdoc-file=kernel.rb
|
3030
|
+
# - obj.tap {|x| block } -> obj
|
3031
|
+
# -->
|
3032
|
+
# Yields self to the block and then returns self. The primary purpose of this
|
3033
|
+
# method is to "tap into" a method chain, in order to perform operations on
|
3034
|
+
# intermediate results within the chain.
|
3035
|
+
#
|
3036
|
+
# (1..10) .tap {|x| puts "original: #{x}" }
|
3037
|
+
# .to_a .tap {|x| puts "array: #{x}" }
|
3038
|
+
# .select {|x| x.even? } .tap {|x| puts "evens: #{x}" }
|
3039
|
+
# .map {|x| x*x } .tap {|x| puts "squares: #{x}" }
|
3040
|
+
#
|
3041
|
+
def tap: () { (self) -> void } -> self
|
3042
|
+
|
3043
|
+
# <!--
|
3044
|
+
# rdoc-file=object.c
|
3045
|
+
# - obj.to_s -> string
|
3046
|
+
# -->
|
3047
|
+
# Returns a string representing *obj*. The default #to_s prints the object's
|
3048
|
+
# class and an encoding of the object id. As a special case, the top-level
|
3049
|
+
# object that is the initial execution context of Ruby programs returns
|
3050
|
+
# ``main''.
|
3051
|
+
#
|
3052
|
+
def to_s: () -> String
|
3053
|
+
|
3054
|
+
# <!--
|
3055
|
+
# rdoc-file=kernel.rb
|
3056
|
+
# - yield_self()
|
3057
|
+
# -->
|
3058
|
+
#
|
3059
|
+
def yield_self: () -> Enumerator[self, untyped]
|
3060
|
+
| [T] () { (self) -> T } -> T
|
3061
|
+
|
3062
|
+
# <!--
|
3063
|
+
# rdoc-file=kernel.rb
|
3064
|
+
# - obj.then {|x| block } -> an_object
|
3065
|
+
# -->
|
3066
|
+
# Yields self to the block and returns the result of the block.
|
3067
|
+
#
|
3068
|
+
# 3.next.then {|x| x**x }.to_s #=> "256"
|
3069
|
+
#
|
3070
|
+
# A good use of `then` is value piping in method chains:
|
3071
|
+
#
|
3072
|
+
# require 'open-uri'
|
3073
|
+
# require 'json'
|
3074
|
+
#
|
3075
|
+
# construct_url(arguments)
|
3076
|
+
# .then {|url| URI(url).read }
|
3077
|
+
# .then {|response| JSON.parse(response) }
|
3078
|
+
#
|
3079
|
+
# When called without a block, the method returns an `Enumerator`, which can be
|
3080
|
+
# used, for example, for conditional circuit-breaking:
|
3081
|
+
#
|
3082
|
+
# # Meets condition, no-op
|
3083
|
+
# 1.then.detect(&:odd?) # => 1
|
3084
|
+
# # Does not meet condition, drop value
|
3085
|
+
# 2.then.detect(&:odd?) # => nil
|
3086
|
+
#
|
3087
|
+
alias then yield_self
|
3088
|
+
|
3089
|
+
private
|
3090
|
+
|
3091
|
+
def initialize_copy: (self object) -> self
|
3092
|
+
|
3093
|
+
def initialize_clone: (self object, ?freeze: bool?) -> self
|
3094
|
+
|
3095
|
+
def initialize_dup: (self object) -> self
|
3096
|
+
end
|