rbs 2.8.4 → 3.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +12 -4
- data/.github/workflows/comments.yml +11 -11
- data/.github/workflows/dependabot.yml +30 -0
- data/.github/workflows/ruby.yml +40 -49
- data/.github/workflows/typecheck.yml +36 -0
- data/.github/workflows/windows.yml +28 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +42 -2
- data/CHANGELOG.md +845 -1
- data/README.md +64 -4
- data/Rakefile +198 -18
- data/Steepfile +11 -11
- data/config.yml +311 -0
- data/core/array.rbs +2189 -1914
- data/core/basic_object.rbs +59 -84
- data/core/binding.rbs +7 -69
- data/core/builtin.rbs +210 -11
- data/core/class.rbs +37 -0
- data/core/comparable.rbs +23 -25
- data/core/complex.rbs +449 -227
- data/core/constants.rbs +29 -21
- data/core/data.rbs +415 -0
- data/core/dir.rbs +698 -415
- data/core/encoding.rbs +468 -843
- data/core/enumerable.rbs +495 -455
- data/core/enumerator/product.rbs +92 -0
- data/core/enumerator.rbs +106 -9
- data/core/env.rbs +1 -1
- data/core/errno.rbs +506 -605
- data/core/errors.rbs +15 -17
- data/core/exception.rbs +361 -145
- data/core/false_class.rbs +39 -26
- data/core/fiber.rbs +121 -14
- data/core/file.rbs +1262 -320
- data/core/file_test.rbs +62 -45
- data/core/float.rbs +187 -208
- data/core/gc.rbs +446 -196
- data/core/global_variables.rbs +29 -29
- data/core/hash.rbs +242 -349
- data/core/integer.rbs +246 -308
- data/core/io/buffer.rbs +373 -122
- data/core/io/wait.rbs +29 -17
- data/core/io.rbs +1881 -1518
- data/core/kernel.rbs +2116 -1538
- data/core/marshal.rbs +24 -14
- data/core/match_data.rbs +413 -166
- data/core/math.rbs +531 -291
- data/core/method.rbs +101 -32
- data/core/module.rbs +228 -64
- data/core/nil_class.rbs +106 -47
- data/core/numeric.rbs +206 -292
- data/core/object.rbs +73 -1168
- data/core/object_space/weak_key_map.rbs +166 -0
- data/core/object_space.rbs +5 -3
- data/core/proc.rbs +280 -39
- data/core/process.rbs +1318 -658
- data/core/ractor.rbs +200 -134
- data/core/random.rbs +21 -4
- data/core/range.rbs +309 -153
- data/core/rational.rbs +4 -12
- data/core/rb_config.rbs +64 -43
- data/core/rbs/unnamed/argf.rbs +411 -147
- data/core/rbs/unnamed/env_class.rbs +137 -253
- data/core/rbs/unnamed/random.rbs +49 -26
- data/core/refinement.rbs +16 -1
- data/core/regexp.rbs +1568 -862
- data/core/ruby_vm.rbs +719 -7
- data/core/rubygems/config_file.rbs +3 -0
- data/core/rubygems/errors.rbs +69 -6
- data/core/rubygems/rubygems.rbs +71 -17
- data/core/rubygems/version.rbs +11 -7
- data/{stdlib/set/0 → core}/set.rbs +80 -91
- data/core/signal.rbs +14 -8
- data/core/string.rbs +1732 -1607
- data/core/struct.rbs +467 -95
- data/core/symbol.rbs +215 -245
- data/core/thread.rbs +133 -89
- data/core/thread_group.rbs +9 -9
- data/core/time.rbs +1141 -841
- data/core/trace_point.rbs +181 -121
- data/core/true_class.rbs +58 -32
- data/core/unbound_method.rbs +103 -30
- data/core/warning.rbs +50 -5
- data/docs/CONTRIBUTING.md +1 -1
- data/docs/architecture.md +110 -0
- data/docs/collection.md +59 -5
- data/docs/data_and_struct.md +86 -0
- data/docs/gem.md +57 -0
- data/docs/rbs_by_example.md +16 -35
- data/docs/repo.md +1 -1
- data/docs/sigs.md +7 -7
- data/docs/stdlib.md +63 -5
- data/docs/syntax.md +255 -61
- data/docs/tools.md +1 -0
- data/ext/rbs_extension/extconf.rb +10 -0
- data/ext/rbs_extension/lexer.c +1741 -1548
- data/ext/rbs_extension/lexer.h +11 -1
- data/ext/rbs_extension/lexer.re +12 -6
- data/ext/rbs_extension/lexstate.c +26 -3
- data/ext/rbs_extension/location.c +119 -111
- data/ext/rbs_extension/location.h +32 -7
- data/ext/rbs_extension/main.c +3 -0
- data/ext/rbs_extension/parser.c +883 -481
- data/ext/rbs_extension/parserstate.c +65 -25
- data/ext/rbs_extension/parserstate.h +13 -3
- data/ext/rbs_extension/rbs_extension.h +1 -10
- data/ext/rbs_extension/unescape.c +7 -47
- data/goodcheck.yml +2 -2
- data/{ext/rbs_extension → include/rbs}/constants.h +26 -15
- data/include/rbs/ruby_objs.h +72 -0
- data/include/rbs.h +7 -0
- data/lib/rbs/annotate/annotations.rb +3 -3
- data/lib/rbs/annotate/formatter.rb +13 -3
- data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
- data/lib/rbs/annotate/rdoc_source.rb +12 -3
- data/lib/rbs/ast/declarations.rb +85 -2
- data/lib/rbs/ast/directives.rb +39 -0
- data/lib/rbs/ast/members.rb +49 -15
- data/lib/rbs/ast/type_param.rb +104 -15
- data/lib/rbs/ast/visitor.rb +137 -0
- data/lib/rbs/buffer.rb +5 -0
- data/lib/rbs/cli/colored_io.rb +48 -0
- data/lib/rbs/cli/diff.rb +83 -0
- data/lib/rbs/cli/validate.rb +356 -0
- data/lib/rbs/cli.rb +253 -143
- data/lib/rbs/collection/cleaner.rb +8 -1
- data/lib/rbs/collection/config/lockfile.rb +92 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +154 -65
- data/lib/rbs/collection/config.rb +19 -46
- data/lib/rbs/collection/installer.rb +12 -13
- data/lib/rbs/collection/sources/base.rb +2 -2
- data/lib/rbs/collection/sources/git.rb +146 -69
- data/lib/rbs/collection/sources/local.rb +81 -0
- data/lib/rbs/collection/sources/rubygems.rb +10 -12
- data/lib/rbs/collection/sources/stdlib.rb +14 -13
- data/lib/rbs/collection/sources.rb +15 -2
- data/lib/rbs/collection.rb +2 -1
- data/lib/rbs/definition.rb +13 -16
- data/lib/rbs/definition_builder/ancestor_builder.rb +100 -24
- data/lib/rbs/definition_builder/method_builder.rb +4 -4
- data/lib/rbs/definition_builder.rb +489 -584
- data/lib/rbs/diff.rb +125 -0
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +406 -105
- data/lib/rbs/environment_loader.rb +48 -44
- data/lib/rbs/environment_walker.rb +1 -1
- data/lib/rbs/errors.rb +175 -56
- data/lib/rbs/file_finder.rb +28 -0
- data/lib/rbs/location_aux.rb +8 -7
- data/lib/rbs/locator.rb +37 -15
- data/lib/rbs/method_type.rb +23 -0
- data/lib/rbs/namespace.rb +1 -0
- data/lib/rbs/parser/lex_result.rb +15 -0
- data/lib/rbs/parser/token.rb +23 -0
- data/lib/rbs/parser_aux.rb +22 -13
- data/lib/rbs/prototype/helpers.rb +48 -22
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +125 -31
- data/lib/rbs/prototype/rbi.rb +49 -36
- 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 +273 -159
- data/lib/rbs/resolver/constant_resolver.rb +24 -8
- data/lib/rbs/resolver/type_name_resolver.rb +41 -7
- data/lib/rbs/sorter.rb +153 -123
- data/lib/rbs/substitution.rb +19 -0
- data/lib/rbs/subtractor.rb +201 -0
- data/lib/rbs/test/errors.rb +24 -11
- data/lib/rbs/test/guaranteed.rb +30 -0
- data/lib/rbs/test/hook.rb +45 -40
- data/lib/rbs/test/setup.rb +1 -1
- data/lib/rbs/test/tester.rb +1 -1
- data/lib/rbs/test/type_check.rb +120 -23
- data/lib/rbs/test.rb +6 -3
- data/lib/rbs/type_alias_dependency.rb +13 -3
- data/lib/rbs/type_alias_regularity.rb +21 -14
- data/lib/rbs/type_name.rb +18 -13
- data/lib/rbs/types.rb +352 -18
- data/lib/rbs/unit_test/convertibles.rb +176 -0
- data/lib/rbs/unit_test/spy.rb +136 -0
- data/lib/rbs/unit_test/type_assertions.rb +341 -0
- data/lib/rbs/unit_test/with_aliases.rb +143 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/validator.rb +55 -30
- data/lib/rbs/variance_calculator.rb +26 -23
- data/lib/rbs/vendorer.rb +3 -3
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +69 -22
- data/lib/rbs.rb +7 -2
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +5 -5
- data/rbs.gemspec +12 -2
- data/schema/decls.json +1 -1
- data/schema/members.json +15 -10
- data/sig/ancestor_builder.rbs +4 -0
- data/sig/ancestor_graph.rbs +22 -2
- data/sig/annotate/formatter.rbs +2 -2
- data/sig/annotate/rdoc_annotater.rbs +1 -1
- 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 +4 -0
- data/sig/collection/config/lockfile.rbs +74 -0
- data/sig/collection/config/lockfile_generator.rbs +66 -0
- data/sig/collection/config.rbs +5 -48
- data/sig/collection/installer.rbs +1 -1
- data/sig/collection/sources.rbs +105 -33
- data/sig/constant.rbs +1 -1
- data/sig/declarations.rbs +42 -3
- data/sig/definition.rbs +26 -10
- data/sig/definition_builder.rbs +103 -81
- data/sig/diff.rbs +28 -0
- data/sig/directives.rbs +61 -0
- data/sig/environment.rbs +175 -29
- data/sig/environment_loader.rbs +20 -18
- data/sig/errors.rbs +123 -2
- data/sig/file_finder.rbs +28 -0
- data/sig/location.rbs +0 -3
- data/sig/locator.rbs +14 -2
- data/sig/manifest.yaml +0 -1
- data/sig/members.rbs +32 -9
- data/sig/method_types.rbs +10 -4
- data/sig/namespace.rbs +2 -3
- data/sig/parser.rbs +55 -16
- data/sig/prototype/helpers.rbs +4 -0
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/prototype/rb.rbs +10 -2
- data/sig/prototype/rbi.rbs +2 -0
- data/sig/prototype/runtime.rbs +182 -0
- data/sig/rbs.rbs +1 -1
- data/sig/rdoc/rbs.rbs +4 -0
- data/sig/repository.rbs +7 -5
- data/sig/resolver/constant_resolver.rbs +3 -4
- data/sig/resolver/context.rbs +1 -1
- data/sig/resolver/type_name_resolver.rbs +5 -1
- data/sig/shims/bundler.rbs +38 -0
- data/sig/shims/rubygems.rbs +19 -0
- data/sig/sorter.rbs +23 -5
- data/sig/substitution.rbs +6 -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 +31 -0
- data/sig/type_alias_regularity.rbs +12 -6
- data/sig/type_param.rbs +45 -9
- data/sig/typename.rbs +8 -5
- data/sig/types.rbs +119 -12
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +28 -0
- data/sig/unit_test/type_assertions.rbs +194 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/sig/use_map.rbs +35 -0
- data/sig/validator.rbs +12 -5
- data/sig/variance_calculator.rbs +3 -1
- data/sig/vendorer.rbs +1 -1
- data/sig/visitor.rbs +47 -0
- data/sig/writer.rbs +6 -2
- data/src/constants.c +153 -0
- data/src/ruby_objs.c +793 -0
- data/stdlib/base64/0/base64.rbs +298 -45
- data/stdlib/benchmark/0/benchmark.rbs +12 -3
- data/stdlib/bigdecimal/0/big_decimal.rbs +62 -198
- data/stdlib/cgi/0/core.rbs +68 -15
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/coverage/0/coverage.rbs +50 -11
- data/stdlib/csv/0/csv.rbs +90 -119
- data/stdlib/csv/0/manifest.yaml +1 -0
- data/stdlib/date/0/date.rbs +806 -735
- data/stdlib/date/0/date_time.rbs +70 -211
- data/stdlib/dbm/0/dbm.rbs +0 -2
- 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 +3 -8
- data/stdlib/digest/0/digest.rbs +48 -35
- data/stdlib/erb/0/erb.rbs +15 -39
- data/stdlib/etc/0/etc.rbs +174 -54
- data/stdlib/fileutils/0/fileutils.rbs +1234 -385
- data/stdlib/forwardable/0/forwardable.rbs +4 -4
- data/stdlib/io-console/0/io-console.rbs +82 -17
- data/stdlib/ipaddr/0/ipaddr.rbs +11 -6
- data/stdlib/json/0/json.rbs +434 -151
- data/stdlib/kconv/0/kconv.rbs +166 -0
- data/stdlib/logger/0/formatter.rbs +0 -2
- data/stdlib/logger/0/log_device.rbs +1 -3
- data/stdlib/logger/0/logger.rbs +465 -328
- data/stdlib/minitest/0/kernel.rbs +2 -2
- data/stdlib/minitest/0/minitest/abstract_reporter.rbs +4 -1
- data/stdlib/minitest/0/minitest/assertion.rbs +1 -0
- data/stdlib/minitest/0/minitest/assertions.rbs +58 -13
- data/stdlib/minitest/0/minitest/backtrace_filter.rbs +7 -0
- data/stdlib/minitest/0/minitest/bench_spec.rbs +8 -8
- data/stdlib/minitest/0/minitest/benchmark.rbs +17 -16
- 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/mock.rbs +9 -5
- data/stdlib/minitest/0/minitest/parallel/executor.rbs +4 -0
- data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +0 -1
- data/stdlib/minitest/0/minitest/pride_io.rbs +8 -0
- data/stdlib/minitest/0/minitest/pride_lol.rbs +2 -0
- data/stdlib/minitest/0/minitest/progress_reporter.rbs +1 -1
- data/stdlib/minitest/0/minitest/reportable.rbs +2 -0
- data/stdlib/minitest/0/minitest/runnable.rbs +33 -1
- data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +1 -1
- data/stdlib/minitest/0/minitest/spec/dsl.rbs +10 -6
- data/stdlib/minitest/0/minitest/spec.rbs +1 -1
- data/stdlib/minitest/0/minitest/statistics_reporter.rbs +5 -0
- data/stdlib/minitest/0/minitest/summary_reporter.rbs +0 -7
- data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +7 -7
- data/stdlib/minitest/0/minitest/test.rbs +7 -14
- data/stdlib/minitest/0/minitest/unexpected_error.rbs +2 -0
- data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
- data/stdlib/minitest/0/minitest/unit.rbs +1 -2
- data/stdlib/minitest/0/minitest.rbs +41 -892
- data/stdlib/monitor/0/monitor.rbs +91 -10
- data/stdlib/mutex_m/0/mutex_m.rbs +0 -2
- data/stdlib/net-http/0/manifest.yaml +1 -1
- data/stdlib/net-http/0/net-http.rbs +3858 -964
- 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 +35 -5
- data/stdlib/objspace/0/objspace.rbs +40 -18
- 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 +1 -0
- data/stdlib/openssl/0/openssl.rbs +681 -316
- data/stdlib/optparse/0/optparse.rbs +100 -65
- data/stdlib/pathname/0/pathname.rbs +24 -15
- data/stdlib/pp/0/manifest.yaml +2 -0
- data/stdlib/pp/0/pp.rbs +300 -0
- data/stdlib/prettyprint/0/prettyprint.rbs +2 -6
- data/stdlib/pstore/0/pstore.rbs +370 -156
- data/stdlib/psych/0/core_ext.rbs +12 -0
- data/stdlib/{yaml → psych}/0/dbm.rbs +3 -3
- data/stdlib/psych/0/manifest.yaml +3 -0
- data/stdlib/psych/0/psych.rbs +402 -0
- data/stdlib/{yaml → psych}/0/store.rbs +2 -2
- data/stdlib/pty/0/pty.rbs +63 -11
- 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 +13 -380
- 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/resolv.rbs +16 -79
- data/stdlib/ripper/0/ripper.rbs +1648 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -2
- data/stdlib/shellwords/0/shellwords.rbs +11 -12
- data/stdlib/singleton/0/singleton.rbs +0 -3
- data/stdlib/socket/0/addrinfo.rbs +13 -18
- data/stdlib/socket/0/basic_socket.rbs +5 -10
- data/stdlib/socket/0/ip_socket.rbs +0 -2
- data/stdlib/socket/0/socket.rbs +77 -46
- data/stdlib/socket/0/tcp_server.rbs +0 -5
- data/stdlib/socket/0/tcp_socket.rbs +36 -3
- data/stdlib/socket/0/udp_socket.rbs +4 -5
- data/stdlib/socket/0/unix_server.rbs +0 -5
- data/stdlib/socket/0/unix_socket.rbs +2 -4
- data/{core/string_io.rbs → stdlib/stringio/0/stringio.rbs} +188 -107
- data/stdlib/strscan/0/string_scanner.rbs +1269 -425
- data/stdlib/tempfile/0/tempfile.rbs +224 -61
- data/stdlib/time/0/time.rbs +48 -35
- data/stdlib/timeout/0/timeout.rbs +17 -8
- data/stdlib/tmpdir/0/tmpdir.rbs +10 -3
- data/stdlib/tsort/0/tsort.rbs +0 -4
- data/stdlib/uri/0/common.rbs +271 -144
- data/stdlib/uri/0/file.rbs +5 -0
- data/stdlib/uri/0/ftp.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +26 -22
- data/stdlib/uri/0/http.rbs +4 -4
- data/stdlib/uri/0/ldap.rbs +1 -1
- data/stdlib/uri/0/mailto.rbs +84 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
- data/stdlib/yaml/0/manifest.yaml +1 -2
- data/stdlib/yaml/0/yaml.rbs +1 -199
- 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 +1 -3
- data/stdlib/zlib/0/zstream.rbs +200 -0
- data/templates/include/rbs/constants.h.erb +20 -0
- data/templates/include/rbs/ruby_objs.h.erb +10 -0
- data/templates/src/constants.c.erb +36 -0
- data/templates/src/ruby_objs.c.erb +27 -0
- data/templates/template.rb +122 -0
- metadata +136 -36
- data/Gemfile +0 -33
- data/Gemfile.lock +0 -118
- data/core/deprecated.rbs +0 -9
- data/ext/rbs_extension/constants.c +0 -135
- data/ext/rbs_extension/ruby_objs.c +0 -525
- data/ext/rbs_extension/ruby_objs.h +0 -43
- data/lib/rbs/constant_table.rb +0 -167
- data/lib/rbs/parser_compat/lexer_error.rb +0 -6
- data/lib/rbs/parser_compat/located_value.rb +0 -7
- data/lib/rbs/parser_compat/semantics_error.rb +0 -6
- data/lib/rbs/parser_compat/syntax_error.rb +0 -6
- data/lib/rbs/test/spy.rb +0 -6
- data/lib/rbs/type_name_resolver.rb +0 -67
- data/sig/constant_table.rbs +0 -30
- data/sig/shims/abstract_syntax_tree.rbs +0 -25
- data/sig/shims/pp.rbs +0 -3
- data/sig/shims/ripper.rbs +0 -8
- data/sig/shims.rbs +0 -69
- data/sig/type_name_resolver.rbs +0 -26
- data/stdlib/minitest/0/manifest.yaml +0 -2
- data/stdlib/prime/0/integer-extension.rbs +0 -41
- data/stdlib/prime/0/manifest.yaml +0 -2
- data/stdlib/prime/0/prime.rbs +0 -372
data/core/kernel.rbs
CHANGED
@@ -12,266 +12,135 @@
|
|
12
12
|
#
|
13
13
|
# Module Kernel provides methods that are useful for:
|
14
14
|
#
|
15
|
-
# * [Converting](
|
16
|
-
# * [Querying](
|
17
|
-
# * [Exiting](
|
18
|
-
# * [Exceptions](
|
19
|
-
# * [IO](
|
20
|
-
# * [Procs](
|
21
|
-
# * [Tracing](
|
22
|
-
# * [Subprocesses](
|
23
|
-
# * [Loading](
|
24
|
-
# * [Yielding](
|
25
|
-
# * [Random Values](
|
26
|
-
# * [Other](
|
27
|
-
#
|
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)
|
28
27
|
#
|
29
28
|
# ### Converting
|
30
29
|
#
|
31
|
-
#
|
32
|
-
# :
|
33
|
-
#
|
34
|
-
#
|
35
|
-
# :
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# : Returns a Float based on the given arguments.
|
39
|
-
#
|
40
|
-
# [#Hash](#method-i-Hash)
|
41
|
-
# : Returns a Hash based on the given argument.
|
42
|
-
#
|
43
|
-
# [#Integer](#method-i-Integer)
|
44
|
-
# : Returns an Integer based on the given arguments.
|
45
|
-
#
|
46
|
-
# [#Rational](#method-i-Rational)
|
47
|
-
# : Returns a Rational based on the given arguments.
|
48
|
-
#
|
49
|
-
# [#String](#method-i-String)
|
50
|
-
# : Returns a String based on the given argument.
|
51
|
-
#
|
52
|
-
#
|
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.
|
53
37
|
#
|
54
38
|
# ### Querying
|
55
39
|
#
|
56
|
-
#
|
57
|
-
# :
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
# :
|
65
|
-
#
|
66
|
-
#
|
67
|
-
# :
|
68
|
-
#
|
69
|
-
#
|
70
|
-
# :
|
71
|
-
#
|
72
|
-
# #block_given?
|
73
|
-
# : Returns `true` if a block was passed to the calling method.
|
74
|
-
#
|
75
|
-
# #caller
|
76
|
-
# : Returns the current execution stack as an array of strings.
|
77
|
-
#
|
78
|
-
# #caller_locations
|
79
|
-
# : Returns the current execution stack as an array of
|
80
|
-
# Thread::Backtrace::Location objects.
|
81
|
-
#
|
82
|
-
# #class
|
83
|
-
# : Returns the class of `self`.
|
84
|
-
#
|
85
|
-
# #frozen?
|
86
|
-
# : Returns whether `self` is frozen.
|
87
|
-
#
|
88
|
-
# #global_variables
|
89
|
-
# : Returns an array of global variables as symbols.
|
90
|
-
#
|
91
|
-
# #local_variables
|
92
|
-
# : Returns an array of local variables as symbols.
|
93
|
-
#
|
94
|
-
# #test
|
95
|
-
# : Performs specified tests on the given single file or pair of files.
|
96
|
-
#
|
97
|
-
#
|
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.
|
98
56
|
#
|
99
57
|
# ### Exiting
|
100
58
|
#
|
101
|
-
#
|
102
|
-
# :
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
# #exit
|
108
|
-
# : Exits the current process after calling any registered `at_exit`
|
109
|
-
# handlers.
|
110
|
-
#
|
111
|
-
# #exit!
|
112
|
-
# : Exits the current process without calling any registered `at_exit`
|
113
|
-
# handlers.
|
114
|
-
#
|
115
|
-
#
|
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.
|
116
65
|
#
|
117
66
|
# ### Exceptions
|
118
67
|
#
|
119
|
-
#
|
120
|
-
# :
|
121
|
-
#
|
122
|
-
#
|
123
|
-
# : Raises an exception based on the given arguments.
|
124
|
-
#
|
125
|
-
# #throw
|
126
|
-
# : Returns from the active catch block waiting for the given tag.
|
127
|
-
#
|
128
|
-
#
|
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.
|
129
72
|
#
|
130
73
|
# ### IO
|
131
74
|
#
|
132
|
-
#
|
133
|
-
# :
|
134
|
-
#
|
135
|
-
#
|
136
|
-
# :
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
# :
|
141
|
-
#
|
142
|
-
#
|
143
|
-
# :
|
144
|
-
#
|
145
|
-
#
|
146
|
-
# : Prints the given objects to standard output without a newline.
|
147
|
-
#
|
148
|
-
# #printf
|
149
|
-
# : Prints the string resulting from applying the given format string to
|
150
|
-
# any additional arguments.
|
151
|
-
#
|
152
|
-
# #putc
|
153
|
-
# : Equivalent to <tt.$stdout.putc(object)</tt> for the given object.
|
154
|
-
#
|
155
|
-
# #puts
|
156
|
-
# : Equivalent to `$stdout.puts(*objects)` for the given objects.
|
157
|
-
#
|
158
|
-
# #readline
|
159
|
-
# : Similar to #gets, but raises an exception at the end of file.
|
160
|
-
#
|
161
|
-
# #readlines
|
162
|
-
# : Returns an array of the remaining lines from the current input.
|
163
|
-
#
|
164
|
-
# #select
|
165
|
-
# : Same as IO.select.
|
166
|
-
#
|
167
|
-
#
|
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.
|
168
89
|
#
|
169
90
|
# ### Procs
|
170
91
|
#
|
171
|
-
#
|
172
|
-
# :
|
173
|
-
#
|
174
|
-
# #proc
|
175
|
-
# : Returns a new Proc; equivalent to Proc.new.
|
176
|
-
#
|
177
|
-
#
|
92
|
+
# * #lambda: Returns a lambda proc for the given block.
|
93
|
+
# * #proc: Returns a new Proc; equivalent to Proc.new.
|
178
94
|
#
|
179
95
|
# ### Tracing
|
180
96
|
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
# : Starts tracing assignments to the given global variable.
|
187
|
-
#
|
188
|
-
# #untrace_var
|
189
|
-
# : Disables tracing of assignments to the given global variable.
|
190
|
-
#
|
191
|
-
#
|
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.
|
192
102
|
#
|
193
103
|
# ### Subprocesses
|
194
104
|
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
# :
|
200
|
-
#
|
201
|
-
#
|
202
|
-
# : Forks the current process into two processes.
|
203
|
-
#
|
204
|
-
# #spawn
|
205
|
-
# : Executes the given command and returns its pid without waiting for
|
206
|
-
# completion.
|
207
|
-
#
|
208
|
-
# #system
|
209
|
-
# : Executes the given command in a subshell.
|
210
|
-
#
|
211
|
-
#
|
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.
|
212
112
|
#
|
213
113
|
# ### Loading
|
214
114
|
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
#
|
219
|
-
#
|
220
|
-
#
|
221
|
-
#
|
222
|
-
# #require
|
223
|
-
# : Loads the given Ruby file unless it has already been loaded.
|
224
|
-
#
|
225
|
-
# #require_relative
|
226
|
-
# : Loads the Ruby file path relative to the calling file, unless it has
|
227
|
-
# already been loaded.
|
228
|
-
#
|
229
|
-
#
|
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.
|
230
121
|
#
|
231
122
|
# ### Yielding
|
232
123
|
#
|
233
|
-
#
|
234
|
-
# :
|
235
|
-
#
|
236
|
-
# #then (aliased as #yield_self)
|
237
|
-
# : Yields `self` to the block and returns the result of the block.
|
238
|
-
#
|
239
|
-
#
|
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.
|
240
127
|
#
|
241
128
|
# ### Random Values
|
242
129
|
#
|
243
|
-
#
|
244
|
-
#
|
245
|
-
#
|
246
|
-
#
|
247
|
-
# #srand
|
248
|
-
# : Seeds the pseudo-random number generator with the given number.
|
249
|
-
#
|
250
|
-
#
|
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.
|
251
133
|
#
|
252
134
|
# ### Other
|
253
135
|
#
|
254
|
-
#
|
255
|
-
# :
|
256
|
-
#
|
257
|
-
#
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
261
|
-
# :
|
262
|
-
#
|
263
|
-
# #sprintf (aliased as #format)
|
264
|
-
# : Returns the string resulting from applying the given format string to
|
265
|
-
# any additional arguments.
|
266
|
-
#
|
267
|
-
# #syscall
|
268
|
-
# : Runs an operating system call.
|
269
|
-
#
|
270
|
-
# #trap
|
271
|
-
# : Specifies the handling of system signals.
|
272
|
-
#
|
273
|
-
# #warn
|
274
|
-
# : Issue a warning based on the given messages and options.
|
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.
|
275
144
|
#
|
276
145
|
%a{annotate:rdoc:source:from=object.c}
|
277
146
|
module Kernel : BasicObject
|
@@ -401,7 +270,7 @@ module Kernel : BasicObject
|
|
401
270
|
# 1.class #=> Integer
|
402
271
|
# self.class #=> Object
|
403
272
|
#
|
404
|
-
def class: () ->
|
273
|
+
def class: () -> Class
|
405
274
|
|
406
275
|
# <!--
|
407
276
|
# rdoc-file=vm_eval.c
|
@@ -419,7 +288,7 @@ module Kernel : BasicObject
|
|
419
288
|
# eval "str + ' Fred'" #=> "hello Fred"
|
420
289
|
# eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
|
421
290
|
#
|
422
|
-
def self?.eval: (
|
291
|
+
def self?.eval: (string src, ?Binding? scope, ?string filename, ?int lineno) -> untyped
|
423
292
|
|
424
293
|
# <!--
|
425
294
|
# rdoc-file=vm_eval.c
|
@@ -477,106 +346,152 @@ module Kernel : BasicObject
|
|
477
346
|
# srand 1234 # => 1234
|
478
347
|
# [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
|
479
348
|
#
|
480
|
-
def self?.srand: (?
|
349
|
+
def self?.srand: (?int number) -> Integer
|
481
350
|
|
482
351
|
# <!--
|
483
352
|
# rdoc-file=process.c
|
484
|
-
# -
|
485
|
-
# - Process.fork
|
353
|
+
# - Process.fork { ... } -> integer or nil
|
354
|
+
# - Process.fork -> integer or nil
|
486
355
|
# -->
|
487
|
-
# Creates a
|
488
|
-
#
|
489
|
-
#
|
490
|
-
#
|
491
|
-
#
|
492
|
-
#
|
493
|
-
#
|
494
|
-
#
|
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`.
|
495
377
|
#
|
496
|
-
#
|
497
|
-
# doesn't copy other threads.
|
378
|
+
# Example:
|
498
379
|
#
|
499
|
-
#
|
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})"
|
500
383
|
#
|
501
|
-
#
|
502
|
-
#
|
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`.
|
503
408
|
#
|
504
409
|
def self?.fork: () -> Integer?
|
505
|
-
| () { () ->
|
506
|
-
|
507
|
-
def initialize_copy: (self object) -> self
|
410
|
+
| () { () -> void } -> Integer
|
508
411
|
|
509
412
|
# <!--
|
510
413
|
# rdoc-file=object.c
|
511
|
-
# - Array(
|
414
|
+
# - Array(object) -> object or new_array
|
512
415
|
# -->
|
513
|
-
# Returns
|
416
|
+
# Returns an array converted from `object`.
|
417
|
+
#
|
418
|
+
# Tries to convert `object` to an array using `to_ary` first and `to_a` second:
|
514
419
|
#
|
515
|
-
#
|
516
|
-
#
|
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]
|
517
423
|
#
|
518
|
-
#
|
519
|
-
# TypeError.
|
424
|
+
# Returns `object` in an array, `[object]`, if `object` cannot be converted:
|
520
425
|
#
|
521
|
-
# Array(
|
522
|
-
# Array(1..5) #=> [1, 2, 3, 4, 5]
|
523
|
-
# Array(key: :value) #=> [[:key, :value]]
|
524
|
-
# Array(nil) #=> []
|
525
|
-
# Array(1) #=> [1]
|
426
|
+
# Array(:foo) # => [:foo]
|
526
427
|
#
|
527
|
-
def self?.Array: (
|
528
|
-
| [T] (
|
529
|
-
| [T] (
|
530
|
-
| [T] (_Each[T] x) -> ::Array[T]
|
531
|
-
| [K, V] (::Hash[K, V] x) -> ::Array[[ K, V ]]
|
532
|
-
| [T] (T x) -> ::Array[T]
|
428
|
+
def self?.Array: (nil) -> []
|
429
|
+
| [T] (array[T] | _ToA[T] array_like) -> Array[T]
|
430
|
+
| [T] (T ele) -> [T]
|
533
431
|
|
534
432
|
# <!--
|
535
433
|
# rdoc-file=complex.c
|
536
|
-
# - Complex(
|
434
|
+
# - Complex(real, imag = 0, exception: true) -> complex or nil
|
435
|
+
# - Complex(s, exception: true) -> complex or nil
|
537
436
|
# -->
|
538
|
-
# Returns
|
437
|
+
# Returns a new Complex object if the arguments are valid; otherwise raises an
|
438
|
+
# exception if `exception` is `true`; otherwise returns `nil`.
|
539
439
|
#
|
540
|
-
#
|
541
|
-
#
|
542
|
-
# Complex(nil) #=> TypeError
|
543
|
-
# Complex(1, nil) #=> TypeError
|
440
|
+
# With Numeric arguments `real` and `imag`, returns `Complex.rect(real, imag)`
|
441
|
+
# if the arguments are valid.
|
544
442
|
#
|
545
|
-
#
|
546
|
-
#
|
443
|
+
# With string argument `s`, returns a new Complex object if the argument is
|
444
|
+
# valid; the string may have:
|
547
445
|
#
|
548
|
-
#
|
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):
|
549
449
|
#
|
550
|
-
#
|
551
|
-
#
|
552
|
-
#
|
553
|
-
#
|
554
|
-
#
|
555
|
-
#
|
556
|
-
#
|
557
|
-
#
|
558
|
-
#
|
559
|
-
#
|
560
|
-
#
|
561
|
-
#
|
562
|
-
#
|
563
|
-
#
|
564
|
-
# digits = digit , { digit | "_" , digit };
|
565
|
-
# digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
|
566
|
-
# extra spaces = ? \s* ? ;
|
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)
|
567
464
|
#
|
568
|
-
#
|
465
|
+
# * Imaginary-only numeric string (with trailing character `'i'`):
|
569
466
|
#
|
570
|
-
|
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?
|
571
486
|
|
572
487
|
# <!--
|
573
488
|
# rdoc-file=kernel.rb
|
574
489
|
# - Float(arg, exception: true) -> float or nil
|
575
490
|
# -->
|
576
491
|
# Returns *arg* converted to a float. Numeric types are converted directly, and
|
577
|
-
# with exception to String and `nil
|
578
|
-
# Converting a String with invalid characters will result in
|
579
|
-
# Converting `nil` generates a TypeError.
|
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
|
580
495
|
# passing `exception: false`.
|
581
496
|
#
|
582
497
|
# Float(1) #=> 1.0
|
@@ -585,53 +500,121 @@ module Kernel : BasicObject
|
|
585
500
|
# Float(nil) #=> TypeError: can't convert nil into Float
|
586
501
|
# Float("123.0_badstring", exception: false) #=> nil
|
587
502
|
#
|
588
|
-
def self?.Float: (
|
503
|
+
def self?.Float: (_ToF float_like, ?exception: true) -> Float
|
504
|
+
| (_ToF float_like, exception: bool) -> Float?
|
505
|
+
| (untyped, ?exception: bool) -> Float?
|
589
506
|
|
590
507
|
# <!--
|
591
508
|
# rdoc-file=object.c
|
592
|
-
# - Hash(
|
509
|
+
# - Hash(object) -> object or new_hash
|
593
510
|
# -->
|
594
|
-
#
|
595
|
-
#
|
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:
|
596
522
|
#
|
597
|
-
# Hash(
|
598
|
-
# Hash(nil)
|
599
|
-
# Hash(
|
600
|
-
# Hash([1, 2, 3]) #=> TypeError
|
523
|
+
# Hash({foo: 0, bar: 1}) # => {:foo=>0, :bar=>1}
|
524
|
+
# Hash(nil) # => {}
|
525
|
+
# Hash([]) # => {}
|
601
526
|
#
|
602
|
-
def self?.Hash: [K, V] (
|
527
|
+
def self?.Hash: [K, V] (nil | [] _empty) -> Hash[K, V]
|
528
|
+
| [K, V] (hash[K, V] hash_like) -> Hash[K, V]
|
603
529
|
|
604
530
|
# <!--
|
605
|
-
# rdoc-file=
|
606
|
-
# - Integer(
|
531
|
+
# rdoc-file=kernel.rb
|
532
|
+
# - Integer(object, base = 0, exception: true) -> integer or nil
|
607
533
|
# -->
|
608
|
-
#
|
609
|
-
#
|
610
|
-
#
|
611
|
-
#
|
612
|
-
#
|
613
|
-
#
|
614
|
-
#
|
615
|
-
#
|
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
|
616
575
|
#
|
617
|
-
#
|
618
|
-
#
|
619
|
-
# altered by passing `exception: false`, in this case a not convertible value
|
620
|
-
# will return `nil`.
|
576
|
+
# With a negative `base` (in range -36..-2) given, returns `object` converted to
|
577
|
+
# the radix indicator if it exists or `base`:
|
621
578
|
#
|
622
|
-
# Integer(
|
623
|
-
# Integer(
|
624
|
-
# Integer(
|
625
|
-
# Integer(
|
626
|
-
# Integer(
|
627
|
-
# Integer(
|
628
|
-
# Integer(nil) #=> TypeError: can't convert nil into Integer
|
629
|
-
# Integer("x") #=> ArgumentError: invalid value for Integer(): "x"
|
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
|
630
585
|
#
|
631
|
-
#
|
586
|
+
# `base` -1 is equivalent to the -10 case.
|
632
587
|
#
|
633
|
-
|
634
|
-
|
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?
|
635
618
|
|
636
619
|
# <!--
|
637
620
|
# rdoc-file=rational.c
|
@@ -670,21 +653,33 @@ module Kernel : BasicObject
|
|
670
653
|
#
|
671
654
|
# See also String#to_r.
|
672
655
|
#
|
673
|
-
def self?.Rational: (
|
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
|
674
667
|
|
675
668
|
# <!--
|
676
669
|
# rdoc-file=object.c
|
677
|
-
# - String(
|
670
|
+
# - String(object) -> object or new_string
|
678
671
|
# -->
|
679
|
-
# Returns
|
672
|
+
# Returns a string converted from `object`.
|
673
|
+
#
|
674
|
+
# Tries to convert `object` to a string using `to_str` first and `to_s` second:
|
680
675
|
#
|
681
|
-
#
|
676
|
+
# String([0, 1, 2]) # => "[0, 1, 2]"
|
677
|
+
# String(0..5) # => "0..5"
|
678
|
+
# String({foo: 0, bar: 1}) # => "{foo: 0, bar: 1}"
|
682
679
|
#
|
683
|
-
#
|
684
|
-
# String(self.class) #=> "Object"
|
685
|
-
# String(123456) #=> "123456"
|
680
|
+
# Raises `TypeError` if `object` cannot be converted to a string.
|
686
681
|
#
|
687
|
-
def self?.String: (
|
682
|
+
def self?.String: (string | _ToS string_like) -> String
|
688
683
|
|
689
684
|
# <!--
|
690
685
|
# rdoc-file=eval.c
|
@@ -717,28 +712,37 @@ module Kernel : BasicObject
|
|
717
712
|
|
718
713
|
# <!--
|
719
714
|
# rdoc-file=io.c
|
720
|
-
# - `
|
715
|
+
# - `command` -> string
|
721
716
|
# -->
|
722
|
-
# Returns the
|
723
|
-
#
|
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>
|
724
729
|
#
|
725
|
-
#
|
726
|
-
# `ls testdir`.split[1] #=> "main.rb"
|
727
|
-
# `echo oops && exit 99` #=> "oops\n"
|
728
|
-
# $?.exitstatus #=> 99
|
730
|
+
# The built-in syntax `%x{...}` uses this method.
|
729
731
|
#
|
730
732
|
def self?.`: (String arg0) -> String
|
731
733
|
|
732
734
|
# <!--
|
733
735
|
# rdoc-file=process.c
|
734
736
|
# - abort
|
735
|
-
# -
|
736
|
-
# - Process.abort([msg])
|
737
|
+
# - Process.abort(msg = nil)
|
737
738
|
# -->
|
738
|
-
#
|
739
|
-
# If *msg* is given, it is written to STDERR prior to terminating.
|
739
|
+
# Terminates execution immediately, effectively by calling `Kernel.exit(false)`.
|
740
740
|
#
|
741
|
-
|
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
|
742
746
|
|
743
747
|
# <!--
|
744
748
|
# rdoc-file=eval_jump.c
|
@@ -759,658 +763,371 @@ module Kernel : BasicObject
|
|
759
763
|
#
|
760
764
|
# goodbye cruel world
|
761
765
|
#
|
762
|
-
def self?.at_exit: () { () ->
|
766
|
+
def self?.at_exit: () { () -> void } -> Proc
|
763
767
|
|
764
768
|
# <!--
|
765
769
|
# rdoc-file=load.c
|
766
|
-
# - autoload(
|
770
|
+
# - autoload(const, filename) -> nil
|
767
771
|
# -->
|
768
772
|
# Registers *filename* to be loaded (using Kernel::require) the first time that
|
769
|
-
# *
|
773
|
+
# *const* (which may be a String or a symbol) is accessed.
|
770
774
|
#
|
771
775
|
# autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
|
772
776
|
#
|
773
|
-
|
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
|
774
781
|
|
775
782
|
# <!--
|
776
783
|
# rdoc-file=load.c
|
777
784
|
# - autoload?(name, inherit=true) -> String or nil
|
778
785
|
# -->
|
779
|
-
# Returns *filename* to be loaded if *name* is registered as `autoload
|
786
|
+
# Returns *filename* to be loaded if *name* is registered as `autoload` in the
|
787
|
+
# current namespace or one of its ancestors.
|
780
788
|
#
|
781
789
|
# autoload(:B, "b")
|
782
790
|
# autoload?(:B) #=> "b"
|
783
791
|
#
|
784
|
-
|
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?
|
785
805
|
|
786
806
|
# <!--
|
787
807
|
# rdoc-file=proc.c
|
788
808
|
# - binding -> a_binding
|
789
809
|
# -->
|
790
|
-
# Returns a
|
791
|
-
# point of call. This object can be used when calling
|
792
|
-
# evaluated command in this environment
|
793
|
-
#
|
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"}
|
794
831
|
#
|
795
|
-
#
|
796
|
-
#
|
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 ...
|
797
842
|
# end
|
798
|
-
#
|
799
|
-
#
|
843
|
+
#
|
844
|
+
# validate(:name, :empty?, if: false) # skips validation
|
845
|
+
# validate(:name, :empty?, if: true) # performs validation
|
800
846
|
#
|
801
847
|
def self?.binding: () -> Binding
|
802
848
|
|
803
849
|
# <!--
|
804
850
|
# rdoc-file=process.c
|
805
|
-
# - exit(status=true)
|
806
|
-
# -
|
807
|
-
# - Process::exit(status=true)
|
851
|
+
# - exit(status = true)
|
852
|
+
# - Process.exit(status = true)
|
808
853
|
# -->
|
809
|
-
# Initiates
|
810
|
-
#
|
811
|
-
#
|
812
|
-
#
|
813
|
-
#
|
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:
|
814
862
|
#
|
815
863
|
# begin
|
816
864
|
# exit
|
817
|
-
# puts
|
865
|
+
# puts 'Never get here.'
|
818
866
|
# rescue SystemExit
|
819
|
-
# puts
|
867
|
+
# puts 'Rescued a SystemExit exception.'
|
820
868
|
# end
|
821
|
-
# puts
|
869
|
+
# puts 'After begin block.'
|
822
870
|
#
|
823
|
-
#
|
871
|
+
# Output:
|
824
872
|
#
|
825
|
-
#
|
826
|
-
#
|
873
|
+
# Rescued a SystemExit exception.
|
874
|
+
# After begin block.
|
827
875
|
#
|
828
|
-
# Just prior to termination, Ruby executes any
|
829
|
-
# Kernel::at_exit) and
|
876
|
+
# Just prior to final termination, Ruby executes any at-exit procedures (see
|
877
|
+
# Kernel::at_exit) and any object finalizers (see
|
830
878
|
# ObjectSpace::define_finalizer).
|
831
879
|
#
|
832
|
-
#
|
833
|
-
#
|
880
|
+
# Example:
|
881
|
+
#
|
882
|
+
# at_exit { puts 'In at_exit function.' }
|
883
|
+
# ObjectSpace.define_finalizer('string', proc { puts 'In finalizer.' })
|
834
884
|
# exit
|
835
885
|
#
|
836
|
-
#
|
886
|
+
# Output:
|
837
887
|
#
|
838
|
-
# at_exit function
|
839
|
-
#
|
888
|
+
# In at_exit function.
|
889
|
+
# In finalizer.
|
840
890
|
#
|
841
|
-
def self?.exit: () -> bot
|
842
|
-
| (?Integer | TrueClass | FalseClass status) -> bot
|
891
|
+
def self?.exit: (?int | bool status) -> bot
|
843
892
|
|
844
893
|
# <!--
|
845
894
|
# rdoc-file=process.c
|
846
|
-
# -
|
895
|
+
# - exit!(status = false)
|
896
|
+
# - Process.exit!(status = false)
|
847
897
|
# -->
|
848
|
-
# Exits the process immediately
|
849
|
-
# to the underlying system
|
898
|
+
# Exits the process immediately; no exit handlers are called. Returns exit
|
899
|
+
# status `status` to the underlying operating system.
|
850
900
|
#
|
851
901
|
# Process.exit!(true)
|
852
902
|
#
|
853
|
-
|
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
|
854
907
|
|
855
908
|
# <!-- rdoc-file=eval.c -->
|
856
|
-
#
|
857
|
-
#
|
858
|
-
#
|
859
|
-
#
|
860
|
-
#
|
861
|
-
#
|
862
|
-
#
|
863
|
-
#
|
864
|
-
#
|
865
|
-
#
|
866
|
-
#
|
867
|
-
#
|
868
|
-
#
|
869
|
-
#
|
870
|
-
#
|
871
|
-
#
|
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.
|
872
1004
|
#
|
873
1005
|
def self?.fail: () -> bot
|
874
|
-
| (
|
875
|
-
| (_Exception exception, ?
|
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
|
876
1009
|
|
877
1010
|
# <!--
|
878
1011
|
# rdoc-file=eval.c
|
879
|
-
# - raise
|
880
|
-
# - raise(
|
881
|
-
#
|
882
|
-
#
|
883
|
-
#
|
884
|
-
#
|
885
|
-
#
|
886
|
-
#
|
887
|
-
#
|
888
|
-
#
|
889
|
-
#
|
890
|
-
#
|
891
|
-
#
|
892
|
-
#
|
893
|
-
#
|
894
|
-
#
|
895
|
-
#
|
896
|
-
#
|
897
|
-
#
|
898
|
-
#
|
899
|
-
#
|
900
|
-
#
|
901
|
-
#
|
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.
|
902
1110
|
#
|
903
1111
|
alias raise fail
|
904
1112
|
|
905
1113
|
alias self.raise self.fail
|
906
1114
|
|
907
1115
|
# <!-- rdoc-file=object.c -->
|
908
|
-
# Returns the string resulting from
|
909
|
-
# arguments. Within the format string, any characters other than format
|
910
|
-
# sequences are copied to the result.
|
911
|
-
#
|
912
|
-
# The syntax of a format sequence is as follows.
|
913
|
-
#
|
914
|
-
# %[flags][width][.precision]type
|
915
|
-
#
|
916
|
-
# A format sequence consists of a percent sign, followed by optional flags,
|
917
|
-
# width, and precision indicators, then terminated with a field type character.
|
918
|
-
# The field type controls how the corresponding `sprintf` argument is to be
|
919
|
-
# interpreted, while the flags modify that interpretation.
|
920
|
-
#
|
921
|
-
# The field type characters are:
|
922
|
-
#
|
923
|
-
# Field | Integer Format
|
924
|
-
# ------+--------------------------------------------------------------
|
925
|
-
# b | Convert argument as a binary number.
|
926
|
-
# | Negative numbers will be displayed as a two's complement
|
927
|
-
# | prefixed with `..1'.
|
928
|
-
# B | Equivalent to `b', but uses an uppercase 0B for prefix
|
929
|
-
# | in the alternative format by #.
|
930
|
-
# d | Convert argument as a decimal number.
|
931
|
-
# i | Identical to `d'.
|
932
|
-
# o | Convert argument as an octal number.
|
933
|
-
# | Negative numbers will be displayed as a two's complement
|
934
|
-
# | prefixed with `..7'.
|
935
|
-
# u | Identical to `d'.
|
936
|
-
# x | Convert argument as a hexadecimal number.
|
937
|
-
# | Negative numbers will be displayed as a two's complement
|
938
|
-
# | prefixed with `..f' (representing an infinite string of
|
939
|
-
# | leading 'ff's).
|
940
|
-
# X | Equivalent to `x', but uses uppercase letters.
|
941
|
-
#
|
942
|
-
# Field | Float Format
|
943
|
-
# ------+--------------------------------------------------------------
|
944
|
-
# e | Convert floating point argument into exponential notation
|
945
|
-
# | with one digit before the decimal point as [-]d.dddddde[+-]dd.
|
946
|
-
# | The precision specifies the number of digits after the decimal
|
947
|
-
# | point (defaulting to six).
|
948
|
-
# E | Equivalent to `e', but uses an uppercase E to indicate
|
949
|
-
# | the exponent.
|
950
|
-
# f | Convert floating point argument as [-]ddd.dddddd,
|
951
|
-
# | where the precision specifies the number of digits after
|
952
|
-
# | the decimal point.
|
953
|
-
# g | Convert a floating point number using exponential form
|
954
|
-
# | if the exponent is less than -4 or greater than or
|
955
|
-
# | equal to the precision, or in dd.dddd form otherwise.
|
956
|
-
# | The precision specifies the number of significant digits.
|
957
|
-
# G | Equivalent to `g', but use an uppercase `E' in exponent form.
|
958
|
-
# a | Convert floating point argument as [-]0xh.hhhhp[+-]dd,
|
959
|
-
# | which is consisted from optional sign, "0x", fraction part
|
960
|
-
# | as hexadecimal, "p", and exponential part as decimal.
|
961
|
-
# A | Equivalent to `a', but use uppercase `X' and `P'.
|
962
|
-
#
|
963
|
-
# Field | Other Format
|
964
|
-
# ------+--------------------------------------------------------------
|
965
|
-
# c | Argument is the numeric code for a single character or
|
966
|
-
# | a single character string itself.
|
967
|
-
# p | The valuing of argument.inspect.
|
968
|
-
# s | Argument is a string to be substituted. If the format
|
969
|
-
# | sequence contains a precision, at most that many characters
|
970
|
-
# | will be copied.
|
971
|
-
# % | A percent sign itself will be displayed. No argument taken.
|
972
|
-
#
|
973
|
-
# The flags modifies the behavior of the formats. The flag characters are:
|
974
|
-
#
|
975
|
-
# Flag | Applies to | Meaning
|
976
|
-
# ---------+---------------+-----------------------------------------
|
977
|
-
# space | bBdiouxX | Leave a space at the start of
|
978
|
-
# | aAeEfgG | non-negative numbers.
|
979
|
-
# | (numeric fmt) | For `o', `x', `X', `b' and `B', use
|
980
|
-
# | | a minus sign with absolute value for
|
981
|
-
# | | negative values.
|
982
|
-
# ---------+---------------+-----------------------------------------
|
983
|
-
# (digit)$ | all | Specifies the absolute argument number
|
984
|
-
# | | for this field. Absolute and relative
|
985
|
-
# | | argument numbers cannot be mixed in a
|
986
|
-
# | | sprintf string.
|
987
|
-
# ---------+---------------+-----------------------------------------
|
988
|
-
# # | bBoxX | Use an alternative format.
|
989
|
-
# | aAeEfgG | For the conversions `o', increase the precision
|
990
|
-
# | | until the first digit will be `0' if
|
991
|
-
# | | it is not formatted as complements.
|
992
|
-
# | | For the conversions `x', `X', `b' and `B'
|
993
|
-
# | | on non-zero, prefix the result with ``0x'',
|
994
|
-
# | | ``0X'', ``0b'' and ``0B'', respectively.
|
995
|
-
# | | For `a', `A', `e', `E', `f', `g', and 'G',
|
996
|
-
# | | force a decimal point to be added,
|
997
|
-
# | | even if no digits follow.
|
998
|
-
# | | For `g' and 'G', do not remove trailing zeros.
|
999
|
-
# ---------+---------------+-----------------------------------------
|
1000
|
-
# + | bBdiouxX | Add a leading plus sign to non-negative
|
1001
|
-
# | aAeEfgG | numbers.
|
1002
|
-
# | (numeric fmt) | For `o', `x', `X', `b' and `B', use
|
1003
|
-
# | | a minus sign with absolute value for
|
1004
|
-
# | | negative values.
|
1005
|
-
# ---------+---------------+-----------------------------------------
|
1006
|
-
# - | all | Left-justify the result of this conversion.
|
1007
|
-
# ---------+---------------+-----------------------------------------
|
1008
|
-
# 0 (zero) | bBdiouxX | Pad with zeros, not spaces.
|
1009
|
-
# | aAeEfgG | For `o', `x', `X', `b' and `B', radix-1
|
1010
|
-
# | (numeric fmt) | is used for negative numbers formatted as
|
1011
|
-
# | | complements.
|
1012
|
-
# ---------+---------------+-----------------------------------------
|
1013
|
-
# * | all | Use the next argument as the field width.
|
1014
|
-
# | | If negative, left-justify the result. If the
|
1015
|
-
# | | asterisk is followed by a number and a dollar
|
1016
|
-
# | | sign, use the indicated argument as the width.
|
1017
|
-
#
|
1018
|
-
# Examples of flags:
|
1019
|
-
#
|
1020
|
-
# # `+' and space flag specifies the sign of non-negative numbers.
|
1021
|
-
# sprintf("%d", 123) #=> "123"
|
1022
|
-
# sprintf("%+d", 123) #=> "+123"
|
1023
|
-
# sprintf("% d", 123) #=> " 123"
|
1024
|
-
#
|
1025
|
-
# # `#' flag for `o' increases number of digits to show `0'.
|
1026
|
-
# # `+' and space flag changes format of negative numbers.
|
1027
|
-
# sprintf("%o", 123) #=> "173"
|
1028
|
-
# sprintf("%#o", 123) #=> "0173"
|
1029
|
-
# sprintf("%+o", -123) #=> "-173"
|
1030
|
-
# sprintf("%o", -123) #=> "..7605"
|
1031
|
-
# sprintf("%#o", -123) #=> "..7605"
|
1032
|
-
#
|
1033
|
-
# # `#' flag for `x' add a prefix `0x' for non-zero numbers.
|
1034
|
-
# # `+' and space flag disables complements for negative numbers.
|
1035
|
-
# sprintf("%x", 123) #=> "7b"
|
1036
|
-
# sprintf("%#x", 123) #=> "0x7b"
|
1037
|
-
# sprintf("%+x", -123) #=> "-7b"
|
1038
|
-
# sprintf("%x", -123) #=> "..f85"
|
1039
|
-
# sprintf("%#x", -123) #=> "0x..f85"
|
1040
|
-
# sprintf("%#x", 0) #=> "0"
|
1041
|
-
#
|
1042
|
-
# # `#' for `X' uses the prefix `0X'.
|
1043
|
-
# sprintf("%X", 123) #=> "7B"
|
1044
|
-
# sprintf("%#X", 123) #=> "0X7B"
|
1045
|
-
#
|
1046
|
-
# # `#' flag for `b' add a prefix `0b' for non-zero numbers.
|
1047
|
-
# # `+' and space flag disables complements for negative numbers.
|
1048
|
-
# sprintf("%b", 123) #=> "1111011"
|
1049
|
-
# sprintf("%#b", 123) #=> "0b1111011"
|
1050
|
-
# sprintf("%+b", -123) #=> "-1111011"
|
1051
|
-
# sprintf("%b", -123) #=> "..10000101"
|
1052
|
-
# sprintf("%#b", -123) #=> "0b..10000101"
|
1053
|
-
# sprintf("%#b", 0) #=> "0"
|
1054
|
-
#
|
1055
|
-
# # `#' for `B' uses the prefix `0B'.
|
1056
|
-
# sprintf("%B", 123) #=> "1111011"
|
1057
|
-
# sprintf("%#B", 123) #=> "0B1111011"
|
1058
|
-
#
|
1059
|
-
# # `#' for `e' forces to show the decimal point.
|
1060
|
-
# sprintf("%.0e", 1) #=> "1e+00"
|
1061
|
-
# sprintf("%#.0e", 1) #=> "1.e+00"
|
1062
|
-
#
|
1063
|
-
# # `#' for `f' forces to show the decimal point.
|
1064
|
-
# sprintf("%.0f", 1234) #=> "1234"
|
1065
|
-
# sprintf("%#.0f", 1234) #=> "1234."
|
1066
|
-
#
|
1067
|
-
# # `#' for `g' forces to show the decimal point.
|
1068
|
-
# # It also disables stripping lowest zeros.
|
1069
|
-
# sprintf("%g", 123.4) #=> "123.4"
|
1070
|
-
# sprintf("%#g", 123.4) #=> "123.400"
|
1071
|
-
# sprintf("%g", 123456) #=> "123456"
|
1072
|
-
# sprintf("%#g", 123456) #=> "123456."
|
1073
|
-
#
|
1074
|
-
# The field width is an optional integer, followed optionally by a period and a
|
1075
|
-
# precision. The width specifies the minimum number of characters that will be
|
1076
|
-
# written to the result for this field.
|
1077
|
-
#
|
1078
|
-
# Examples of width:
|
1079
|
-
#
|
1080
|
-
# # padding is done by spaces, width=20
|
1081
|
-
# # 0 or radix-1. <------------------>
|
1082
|
-
# sprintf("%20d", 123) #=> " 123"
|
1083
|
-
# sprintf("%+20d", 123) #=> " +123"
|
1084
|
-
# sprintf("%020d", 123) #=> "00000000000000000123"
|
1085
|
-
# sprintf("%+020d", 123) #=> "+0000000000000000123"
|
1086
|
-
# sprintf("% 020d", 123) #=> " 0000000000000000123"
|
1087
|
-
# sprintf("%-20d", 123) #=> "123 "
|
1088
|
-
# sprintf("%-+20d", 123) #=> "+123 "
|
1089
|
-
# sprintf("%- 20d", 123) #=> " 123 "
|
1090
|
-
# sprintf("%020x", -123) #=> "..ffffffffffffffff85"
|
1091
|
-
#
|
1092
|
-
# For numeric fields, the precision controls the number of decimal places
|
1093
|
-
# displayed. For string fields, the precision determines the maximum number of
|
1094
|
-
# characters to be copied from the string. (Thus, the format sequence `%10.10s`
|
1095
|
-
# will always contribute exactly ten characters to the result.)
|
1096
|
-
#
|
1097
|
-
# Examples of precisions:
|
1098
|
-
#
|
1099
|
-
# # precision for `d', 'o', 'x' and 'b' is
|
1100
|
-
# # minimum number of digits <------>
|
1101
|
-
# sprintf("%20.8d", 123) #=> " 00000123"
|
1102
|
-
# sprintf("%20.8o", 123) #=> " 00000173"
|
1103
|
-
# sprintf("%20.8x", 123) #=> " 0000007b"
|
1104
|
-
# sprintf("%20.8b", 123) #=> " 01111011"
|
1105
|
-
# sprintf("%20.8d", -123) #=> " -00000123"
|
1106
|
-
# sprintf("%20.8o", -123) #=> " ..777605"
|
1107
|
-
# sprintf("%20.8x", -123) #=> " ..ffff85"
|
1108
|
-
# sprintf("%20.8b", -11) #=> " ..110101"
|
1109
|
-
#
|
1110
|
-
# # "0x" and "0b" for `#x' and `#b' is not counted for
|
1111
|
-
# # precision but "0" for `#o' is counted. <------>
|
1112
|
-
# sprintf("%#20.8d", 123) #=> " 00000123"
|
1113
|
-
# sprintf("%#20.8o", 123) #=> " 00000173"
|
1114
|
-
# sprintf("%#20.8x", 123) #=> " 0x0000007b"
|
1115
|
-
# sprintf("%#20.8b", 123) #=> " 0b01111011"
|
1116
|
-
# sprintf("%#20.8d", -123) #=> " -00000123"
|
1117
|
-
# sprintf("%#20.8o", -123) #=> " ..777605"
|
1118
|
-
# sprintf("%#20.8x", -123) #=> " 0x..ffff85"
|
1119
|
-
# sprintf("%#20.8b", -11) #=> " 0b..110101"
|
1120
|
-
#
|
1121
|
-
# # precision for `e' is number of
|
1122
|
-
# # digits after the decimal point <------>
|
1123
|
-
# sprintf("%20.8e", 1234.56789) #=> " 1.23456789e+03"
|
1124
|
-
#
|
1125
|
-
# # precision for `f' is number of
|
1126
|
-
# # digits after the decimal point <------>
|
1127
|
-
# sprintf("%20.8f", 1234.56789) #=> " 1234.56789000"
|
1128
|
-
#
|
1129
|
-
# # precision for `g' is number of
|
1130
|
-
# # significant digits <------->
|
1131
|
-
# sprintf("%20.8g", 1234.56789) #=> " 1234.5679"
|
1132
|
-
#
|
1133
|
-
# # <------->
|
1134
|
-
# sprintf("%20.8g", 123456789) #=> " 1.2345679e+08"
|
1135
|
-
#
|
1136
|
-
# # precision for `s' is
|
1137
|
-
# # maximum number of characters <------>
|
1138
|
-
# sprintf("%20.8s", "string test") #=> " string t"
|
1116
|
+
# Returns the string resulting from formatting `objects` into `format_string`.
|
1139
1117
|
#
|
1140
|
-
#
|
1141
|
-
#
|
1142
|
-
# sprintf("%d %04x", 123, 123) #=> "123 007b"
|
1143
|
-
# sprintf("%08b '%4s'", 123, 123) #=> "01111011 ' 123'"
|
1144
|
-
# sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 hello"
|
1145
|
-
# sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"
|
1146
|
-
# sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 1.23:1.23"
|
1147
|
-
# sprintf("%u", -123) #=> "-123"
|
1148
|
-
#
|
1149
|
-
# For more complex formatting, Ruby supports a reference by name. %<name>s style
|
1150
|
-
# uses format style, but %{name} style doesn't.
|
1151
|
-
#
|
1152
|
-
# Examples:
|
1153
|
-
# sprintf("%<foo>d : %<bar>f", { :foo => 1, :bar => 2 })
|
1154
|
-
# #=> 1 : 2.000000
|
1155
|
-
# sprintf("%{foo}f", { :foo => 1 })
|
1156
|
-
# # => "1f"
|
1118
|
+
# For details on `format_string`, see [Format
|
1119
|
+
# Specifications](rdoc-ref:format_specifications.rdoc).
|
1157
1120
|
#
|
1158
1121
|
def self?.format: (String format, *untyped args) -> String
|
1159
1122
|
|
1160
1123
|
# <!--
|
1161
1124
|
# rdoc-file=object.c
|
1162
|
-
# -
|
1163
|
-
#
|
1164
|
-
#
|
1165
|
-
# Returns the string resulting from applying *format_string* to any additional
|
1166
|
-
# arguments. Within the format string, any characters other than format
|
1167
|
-
# sequences are copied to the result.
|
1168
|
-
#
|
1169
|
-
# The syntax of a format sequence is as follows.
|
1170
|
-
#
|
1171
|
-
# %[flags][width][.precision]type
|
1172
|
-
#
|
1173
|
-
# A format sequence consists of a percent sign, followed by optional flags,
|
1174
|
-
# width, and precision indicators, then terminated with a field type character.
|
1175
|
-
# The field type controls how the corresponding `sprintf` argument is to be
|
1176
|
-
# interpreted, while the flags modify that interpretation.
|
1177
|
-
#
|
1178
|
-
# The field type characters are:
|
1179
|
-
#
|
1180
|
-
# Field | Integer Format
|
1181
|
-
# ------+--------------------------------------------------------------
|
1182
|
-
# b | Convert argument as a binary number.
|
1183
|
-
# | Negative numbers will be displayed as a two's complement
|
1184
|
-
# | prefixed with `..1'.
|
1185
|
-
# B | Equivalent to `b', but uses an uppercase 0B for prefix
|
1186
|
-
# | in the alternative format by #.
|
1187
|
-
# d | Convert argument as a decimal number.
|
1188
|
-
# i | Identical to `d'.
|
1189
|
-
# o | Convert argument as an octal number.
|
1190
|
-
# | Negative numbers will be displayed as a two's complement
|
1191
|
-
# | prefixed with `..7'.
|
1192
|
-
# u | Identical to `d'.
|
1193
|
-
# x | Convert argument as a hexadecimal number.
|
1194
|
-
# | Negative numbers will be displayed as a two's complement
|
1195
|
-
# | prefixed with `..f' (representing an infinite string of
|
1196
|
-
# | leading 'ff's).
|
1197
|
-
# X | Equivalent to `x', but uses uppercase letters.
|
1198
|
-
#
|
1199
|
-
# Field | Float Format
|
1200
|
-
# ------+--------------------------------------------------------------
|
1201
|
-
# e | Convert floating point argument into exponential notation
|
1202
|
-
# | with one digit before the decimal point as [-]d.dddddde[+-]dd.
|
1203
|
-
# | The precision specifies the number of digits after the decimal
|
1204
|
-
# | point (defaulting to six).
|
1205
|
-
# E | Equivalent to `e', but uses an uppercase E to indicate
|
1206
|
-
# | the exponent.
|
1207
|
-
# f | Convert floating point argument as [-]ddd.dddddd,
|
1208
|
-
# | where the precision specifies the number of digits after
|
1209
|
-
# | the decimal point.
|
1210
|
-
# g | Convert a floating point number using exponential form
|
1211
|
-
# | if the exponent is less than -4 or greater than or
|
1212
|
-
# | equal to the precision, or in dd.dddd form otherwise.
|
1213
|
-
# | The precision specifies the number of significant digits.
|
1214
|
-
# G | Equivalent to `g', but use an uppercase `E' in exponent form.
|
1215
|
-
# a | Convert floating point argument as [-]0xh.hhhhp[+-]dd,
|
1216
|
-
# | which is consisted from optional sign, "0x", fraction part
|
1217
|
-
# | as hexadecimal, "p", and exponential part as decimal.
|
1218
|
-
# A | Equivalent to `a', but use uppercase `X' and `P'.
|
1219
|
-
#
|
1220
|
-
# Field | Other Format
|
1221
|
-
# ------+--------------------------------------------------------------
|
1222
|
-
# c | Argument is the numeric code for a single character or
|
1223
|
-
# | a single character string itself.
|
1224
|
-
# p | The valuing of argument.inspect.
|
1225
|
-
# s | Argument is a string to be substituted. If the format
|
1226
|
-
# | sequence contains a precision, at most that many characters
|
1227
|
-
# | will be copied.
|
1228
|
-
# % | A percent sign itself will be displayed. No argument taken.
|
1229
|
-
#
|
1230
|
-
# The flags modifies the behavior of the formats. The flag characters are:
|
1231
|
-
#
|
1232
|
-
# Flag | Applies to | Meaning
|
1233
|
-
# ---------+---------------+-----------------------------------------
|
1234
|
-
# space | bBdiouxX | Leave a space at the start of
|
1235
|
-
# | aAeEfgG | non-negative numbers.
|
1236
|
-
# | (numeric fmt) | For `o', `x', `X', `b' and `B', use
|
1237
|
-
# | | a minus sign with absolute value for
|
1238
|
-
# | | negative values.
|
1239
|
-
# ---------+---------------+-----------------------------------------
|
1240
|
-
# (digit)$ | all | Specifies the absolute argument number
|
1241
|
-
# | | for this field. Absolute and relative
|
1242
|
-
# | | argument numbers cannot be mixed in a
|
1243
|
-
# | | sprintf string.
|
1244
|
-
# ---------+---------------+-----------------------------------------
|
1245
|
-
# # | bBoxX | Use an alternative format.
|
1246
|
-
# | aAeEfgG | For the conversions `o', increase the precision
|
1247
|
-
# | | until the first digit will be `0' if
|
1248
|
-
# | | it is not formatted as complements.
|
1249
|
-
# | | For the conversions `x', `X', `b' and `B'
|
1250
|
-
# | | on non-zero, prefix the result with ``0x'',
|
1251
|
-
# | | ``0X'', ``0b'' and ``0B'', respectively.
|
1252
|
-
# | | For `a', `A', `e', `E', `f', `g', and 'G',
|
1253
|
-
# | | force a decimal point to be added,
|
1254
|
-
# | | even if no digits follow.
|
1255
|
-
# | | For `g' and 'G', do not remove trailing zeros.
|
1256
|
-
# ---------+---------------+-----------------------------------------
|
1257
|
-
# + | bBdiouxX | Add a leading plus sign to non-negative
|
1258
|
-
# | aAeEfgG | numbers.
|
1259
|
-
# | (numeric fmt) | For `o', `x', `X', `b' and `B', use
|
1260
|
-
# | | a minus sign with absolute value for
|
1261
|
-
# | | negative values.
|
1262
|
-
# ---------+---------------+-----------------------------------------
|
1263
|
-
# - | all | Left-justify the result of this conversion.
|
1264
|
-
# ---------+---------------+-----------------------------------------
|
1265
|
-
# 0 (zero) | bBdiouxX | Pad with zeros, not spaces.
|
1266
|
-
# | aAeEfgG | For `o', `x', `X', `b' and `B', radix-1
|
1267
|
-
# | (numeric fmt) | is used for negative numbers formatted as
|
1268
|
-
# | | complements.
|
1269
|
-
# ---------+---------------+-----------------------------------------
|
1270
|
-
# * | all | Use the next argument as the field width.
|
1271
|
-
# | | If negative, left-justify the result. If the
|
1272
|
-
# | | asterisk is followed by a number and a dollar
|
1273
|
-
# | | sign, use the indicated argument as the width.
|
1274
|
-
#
|
1275
|
-
# Examples of flags:
|
1276
|
-
#
|
1277
|
-
# # `+' and space flag specifies the sign of non-negative numbers.
|
1278
|
-
# sprintf("%d", 123) #=> "123"
|
1279
|
-
# sprintf("%+d", 123) #=> "+123"
|
1280
|
-
# sprintf("% d", 123) #=> " 123"
|
1281
|
-
#
|
1282
|
-
# # `#' flag for `o' increases number of digits to show `0'.
|
1283
|
-
# # `+' and space flag changes format of negative numbers.
|
1284
|
-
# sprintf("%o", 123) #=> "173"
|
1285
|
-
# sprintf("%#o", 123) #=> "0173"
|
1286
|
-
# sprintf("%+o", -123) #=> "-173"
|
1287
|
-
# sprintf("%o", -123) #=> "..7605"
|
1288
|
-
# sprintf("%#o", -123) #=> "..7605"
|
1289
|
-
#
|
1290
|
-
# # `#' flag for `x' add a prefix `0x' for non-zero numbers.
|
1291
|
-
# # `+' and space flag disables complements for negative numbers.
|
1292
|
-
# sprintf("%x", 123) #=> "7b"
|
1293
|
-
# sprintf("%#x", 123) #=> "0x7b"
|
1294
|
-
# sprintf("%+x", -123) #=> "-7b"
|
1295
|
-
# sprintf("%x", -123) #=> "..f85"
|
1296
|
-
# sprintf("%#x", -123) #=> "0x..f85"
|
1297
|
-
# sprintf("%#x", 0) #=> "0"
|
1298
|
-
#
|
1299
|
-
# # `#' for `X' uses the prefix `0X'.
|
1300
|
-
# sprintf("%X", 123) #=> "7B"
|
1301
|
-
# sprintf("%#X", 123) #=> "0X7B"
|
1302
|
-
#
|
1303
|
-
# # `#' flag for `b' add a prefix `0b' for non-zero numbers.
|
1304
|
-
# # `+' and space flag disables complements for negative numbers.
|
1305
|
-
# sprintf("%b", 123) #=> "1111011"
|
1306
|
-
# sprintf("%#b", 123) #=> "0b1111011"
|
1307
|
-
# sprintf("%+b", -123) #=> "-1111011"
|
1308
|
-
# sprintf("%b", -123) #=> "..10000101"
|
1309
|
-
# sprintf("%#b", -123) #=> "0b..10000101"
|
1310
|
-
# sprintf("%#b", 0) #=> "0"
|
1311
|
-
#
|
1312
|
-
# # `#' for `B' uses the prefix `0B'.
|
1313
|
-
# sprintf("%B", 123) #=> "1111011"
|
1314
|
-
# sprintf("%#B", 123) #=> "0B1111011"
|
1315
|
-
#
|
1316
|
-
# # `#' for `e' forces to show the decimal point.
|
1317
|
-
# sprintf("%.0e", 1) #=> "1e+00"
|
1318
|
-
# sprintf("%#.0e", 1) #=> "1.e+00"
|
1319
|
-
#
|
1320
|
-
# # `#' for `f' forces to show the decimal point.
|
1321
|
-
# sprintf("%.0f", 1234) #=> "1234"
|
1322
|
-
# sprintf("%#.0f", 1234) #=> "1234."
|
1323
|
-
#
|
1324
|
-
# # `#' for `g' forces to show the decimal point.
|
1325
|
-
# # It also disables stripping lowest zeros.
|
1326
|
-
# sprintf("%g", 123.4) #=> "123.4"
|
1327
|
-
# sprintf("%#g", 123.4) #=> "123.400"
|
1328
|
-
# sprintf("%g", 123456) #=> "123456"
|
1329
|
-
# sprintf("%#g", 123456) #=> "123456."
|
1330
|
-
#
|
1331
|
-
# The field width is an optional integer, followed optionally by a period and a
|
1332
|
-
# precision. The width specifies the minimum number of characters that will be
|
1333
|
-
# written to the result for this field.
|
1334
|
-
#
|
1335
|
-
# Examples of width:
|
1336
|
-
#
|
1337
|
-
# # padding is done by spaces, width=20
|
1338
|
-
# # 0 or radix-1. <------------------>
|
1339
|
-
# sprintf("%20d", 123) #=> " 123"
|
1340
|
-
# sprintf("%+20d", 123) #=> " +123"
|
1341
|
-
# sprintf("%020d", 123) #=> "00000000000000000123"
|
1342
|
-
# sprintf("%+020d", 123) #=> "+0000000000000000123"
|
1343
|
-
# sprintf("% 020d", 123) #=> " 0000000000000000123"
|
1344
|
-
# sprintf("%-20d", 123) #=> "123 "
|
1345
|
-
# sprintf("%-+20d", 123) #=> "+123 "
|
1346
|
-
# sprintf("%- 20d", 123) #=> " 123 "
|
1347
|
-
# sprintf("%020x", -123) #=> "..ffffffffffffffff85"
|
1348
|
-
#
|
1349
|
-
# For numeric fields, the precision controls the number of decimal places
|
1350
|
-
# displayed. For string fields, the precision determines the maximum number of
|
1351
|
-
# characters to be copied from the string. (Thus, the format sequence `%10.10s`
|
1352
|
-
# will always contribute exactly ten characters to the result.)
|
1353
|
-
#
|
1354
|
-
# Examples of precisions:
|
1355
|
-
#
|
1356
|
-
# # precision for `d', 'o', 'x' and 'b' is
|
1357
|
-
# # minimum number of digits <------>
|
1358
|
-
# sprintf("%20.8d", 123) #=> " 00000123"
|
1359
|
-
# sprintf("%20.8o", 123) #=> " 00000173"
|
1360
|
-
# sprintf("%20.8x", 123) #=> " 0000007b"
|
1361
|
-
# sprintf("%20.8b", 123) #=> " 01111011"
|
1362
|
-
# sprintf("%20.8d", -123) #=> " -00000123"
|
1363
|
-
# sprintf("%20.8o", -123) #=> " ..777605"
|
1364
|
-
# sprintf("%20.8x", -123) #=> " ..ffff85"
|
1365
|
-
# sprintf("%20.8b", -11) #=> " ..110101"
|
1366
|
-
#
|
1367
|
-
# # "0x" and "0b" for `#x' and `#b' is not counted for
|
1368
|
-
# # precision but "0" for `#o' is counted. <------>
|
1369
|
-
# sprintf("%#20.8d", 123) #=> " 00000123"
|
1370
|
-
# sprintf("%#20.8o", 123) #=> " 00000173"
|
1371
|
-
# sprintf("%#20.8x", 123) #=> " 0x0000007b"
|
1372
|
-
# sprintf("%#20.8b", 123) #=> " 0b01111011"
|
1373
|
-
# sprintf("%#20.8d", -123) #=> " -00000123"
|
1374
|
-
# sprintf("%#20.8o", -123) #=> " ..777605"
|
1375
|
-
# sprintf("%#20.8x", -123) #=> " 0x..ffff85"
|
1376
|
-
# sprintf("%#20.8b", -11) #=> " 0b..110101"
|
1377
|
-
#
|
1378
|
-
# # precision for `e' is number of
|
1379
|
-
# # digits after the decimal point <------>
|
1380
|
-
# sprintf("%20.8e", 1234.56789) #=> " 1.23456789e+03"
|
1381
|
-
#
|
1382
|
-
# # precision for `f' is number of
|
1383
|
-
# # digits after the decimal point <------>
|
1384
|
-
# sprintf("%20.8f", 1234.56789) #=> " 1234.56789000"
|
1385
|
-
#
|
1386
|
-
# # precision for `g' is number of
|
1387
|
-
# # significant digits <------->
|
1388
|
-
# sprintf("%20.8g", 1234.56789) #=> " 1234.5679"
|
1389
|
-
#
|
1390
|
-
# # <------->
|
1391
|
-
# sprintf("%20.8g", 123456789) #=> " 1.2345679e+08"
|
1392
|
-
#
|
1393
|
-
# # precision for `s' is
|
1394
|
-
# # maximum number of characters <------>
|
1395
|
-
# sprintf("%20.8s", "string test") #=> " string t"
|
1396
|
-
#
|
1397
|
-
# Examples:
|
1398
|
-
#
|
1399
|
-
# sprintf("%d %04x", 123, 123) #=> "123 007b"
|
1400
|
-
# sprintf("%08b '%4s'", 123, 123) #=> "01111011 ' 123'"
|
1401
|
-
# sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 hello"
|
1402
|
-
# sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"
|
1403
|
-
# sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 1.23:1.23"
|
1404
|
-
# sprintf("%u", -123) #=> "-123"
|
1405
|
-
#
|
1406
|
-
# For more complex formatting, Ruby supports a reference by name. %<name>s style
|
1407
|
-
# uses format style, but %{name} style doesn't.
|
1125
|
+
# - sprintf(format_string *objects) -> string
|
1126
|
+
# -->
|
1127
|
+
# Returns the string resulting from formatting `objects` into `format_string`.
|
1408
1128
|
#
|
1409
|
-
#
|
1410
|
-
#
|
1411
|
-
# #=> 1 : 2.000000
|
1412
|
-
# sprintf("%{foo}f", { :foo => 1 })
|
1413
|
-
# # => "1f"
|
1129
|
+
# For details on `format_string`, see [Format
|
1130
|
+
# Specifications](rdoc-ref:format_specifications.rdoc).
|
1414
1131
|
#
|
1415
1132
|
alias sprintf format
|
1416
1133
|
|
@@ -1482,15 +1199,15 @@ module Kernel : BasicObject
|
|
1482
1199
|
# will be raised.
|
1483
1200
|
#
|
1484
1201
|
# If the optional *wrap* parameter is `true`, the loaded script will be executed
|
1485
|
-
# under an anonymous module
|
1486
|
-
#
|
1487
|
-
#
|
1488
|
-
#
|
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.
|
1489
1206
|
#
|
1490
1207
|
def self?.load: (String filename, ?Module | bool) -> bool
|
1491
1208
|
|
1492
1209
|
# <!--
|
1493
|
-
# rdoc-file=
|
1210
|
+
# rdoc-file=kernel.rb
|
1494
1211
|
# - loop { block }
|
1495
1212
|
# - loop -> an_enumerator
|
1496
1213
|
# -->
|
@@ -1501,12 +1218,12 @@ module Kernel : BasicObject
|
|
1501
1218
|
# loop do
|
1502
1219
|
# print "Input: "
|
1503
1220
|
# line = gets
|
1504
|
-
# break if !line or line =~ /^
|
1221
|
+
# break if !line or line =~ /^q/i
|
1505
1222
|
# # ...
|
1506
1223
|
# end
|
1507
1224
|
#
|
1508
|
-
# StopIteration raised in the block breaks the loop.
|
1509
|
-
# the "result" value stored in the exception.
|
1225
|
+
# A StopIteration raised in the block breaks the loop. In this case, loop
|
1226
|
+
# returns the "result" value stored in the exception.
|
1510
1227
|
#
|
1511
1228
|
# enum = Enumerator.new { |y|
|
1512
1229
|
# y << "one"
|
@@ -1518,143 +1235,120 @@ module Kernel : BasicObject
|
|
1518
1235
|
# puts enum.next
|
1519
1236
|
# } #=> :ok
|
1520
1237
|
#
|
1521
|
-
def self?.loop: () { (
|
1238
|
+
def self?.loop: () { () -> void } -> bot
|
1522
1239
|
| () -> ::Enumerator[nil, bot]
|
1523
1240
|
|
1524
1241
|
# <!--
|
1525
1242
|
# rdoc-file=io.c
|
1526
|
-
# - open(path
|
1527
|
-
# - open(path
|
1243
|
+
# - open(path, mode = 'r', perm = 0666, **opts) -> io or nil
|
1244
|
+
# - open(path, mode = 'r', perm = 0666, **opts) {|io| ... } -> obj
|
1528
1245
|
# -->
|
1529
|
-
# Creates an IO object connected to the given
|
1246
|
+
# Creates an IO object connected to the given file.
|
1530
1247
|
#
|
1531
|
-
#
|
1532
|
-
#
|
1248
|
+
# This method has potential security vulnerabilities if called with untrusted
|
1249
|
+
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
1533
1250
|
#
|
1534
|
-
#
|
1535
|
-
# bitwise-or of open(2) flags, such as File::RDWR or File::EXCL. If it is a
|
1536
|
-
# string, it is either "fmode", "fmode:ext_enc", or "fmode:ext_enc:int_enc".
|
1251
|
+
# With no block given, file stream is returned:
|
1537
1252
|
#
|
1538
|
-
#
|
1539
|
-
# directives.
|
1253
|
+
# open('t.txt') # => #<File:t.txt>
|
1540
1254
|
#
|
1541
|
-
#
|
1542
|
-
#
|
1543
|
-
# description of permissions.
|
1255
|
+
# With a block given, calls the block with the open file stream, then closes the
|
1256
|
+
# stream:
|
1544
1257
|
#
|
1545
|
-
#
|
1546
|
-
# and the IO will be automatically closed when the block terminates. The call
|
1547
|
-
# returns the value of the block.
|
1258
|
+
# open('t.txt') {|f| p f } # => #<File:t.txt (closed)>
|
1548
1259
|
#
|
1549
|
-
#
|
1550
|
-
# connected to the caller by a pair of pipes. The returned IO object may be
|
1551
|
-
# used to write to the standard input and read from the standard output of this
|
1552
|
-
# subprocess.
|
1260
|
+
# Output:
|
1553
1261
|
#
|
1554
|
-
#
|
1555
|
-
# and this subprocess is connected to the parent. If the command is not `"-"`,
|
1556
|
-
# the subprocess runs the command. Note that the command may be processed by
|
1557
|
-
# shell if it contains shell metacharacters.
|
1262
|
+
# #<File:t.txt>
|
1558
1263
|
#
|
1559
|
-
#
|
1560
|
-
# `nil`. If a block is associated with the open call, that block will run twice
|
1561
|
-
# --- once in the parent and once in the child.
|
1264
|
+
# See File.open for details.
|
1562
1265
|
#
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
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`.
|
1566
1275
|
#
|
1567
|
-
#
|
1276
|
+
# Writes the given objects to `$stdout`; returns `nil`. Appends the output
|
1277
|
+
# record separator `$OUTPUT_RECORD_SEPARATOR` `$\`), if it is not `nil`.
|
1568
1278
|
#
|
1569
|
-
#
|
1279
|
+
# With argument `objects` given, for each object:
|
1570
1280
|
#
|
1571
|
-
#
|
1572
|
-
#
|
1573
|
-
#
|
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`.
|
1574
1285
|
#
|
1575
|
-
#
|
1286
|
+
# With default separators:
|
1576
1287
|
#
|
1577
|
-
#
|
1288
|
+
# objects = [0, 0.0, Rational(0, 1), Complex(0, 0), :zero, 'zero']
|
1289
|
+
# $OUTPUT_RECORD_SEPARATOR
|
1290
|
+
# $OUTPUT_FIELD_SEPARATOR
|
1291
|
+
# print(*objects)
|
1578
1292
|
#
|
1579
|
-
#
|
1293
|
+
# Output:
|
1580
1294
|
#
|
1581
|
-
#
|
1582
|
-
#
|
1583
|
-
#
|
1295
|
+
# nil
|
1296
|
+
# nil
|
1297
|
+
# 00.00/10+0izerozero
|
1584
1298
|
#
|
1585
|
-
#
|
1299
|
+
# With specified separators:
|
1586
1300
|
#
|
1587
|
-
#
|
1301
|
+
# $OUTPUT_RECORD_SEPARATOR = "\n"
|
1302
|
+
# $OUTPUT_FIELD_SEPARATOR = ','
|
1303
|
+
# print(*objects)
|
1588
1304
|
#
|
1589
|
-
#
|
1305
|
+
# Output:
|
1590
1306
|
#
|
1591
|
-
#
|
1592
|
-
# if f.nil?
|
1593
|
-
# puts "in Child"
|
1594
|
-
# exit
|
1595
|
-
# else
|
1596
|
-
# puts "Got: #{f.gets}"
|
1597
|
-
# end
|
1307
|
+
# 0,0.0,0/1,0+0i,zero,zero
|
1598
1308
|
#
|
1599
|
-
#
|
1309
|
+
# With no argument given, writes the content of `$_` (which is usually the most
|
1310
|
+
# recent user input):
|
1600
1311
|
#
|
1601
|
-
#
|
1312
|
+
# gets # Sets $_ to the most recent user input.
|
1313
|
+
# print # Prints $_.
|
1602
1314
|
#
|
1603
|
-
|
1604
|
-
#
|
1605
|
-
# open "|-" do |f|
|
1606
|
-
# if f then
|
1607
|
-
# # parent process
|
1608
|
-
# puts "Got: #{f.gets}"
|
1609
|
-
# else
|
1610
|
-
# # child process
|
1611
|
-
# puts "in Child"
|
1612
|
-
# end
|
1613
|
-
# end
|
1614
|
-
#
|
1615
|
-
# Produces:
|
1616
|
-
#
|
1617
|
-
# Got: in Child
|
1618
|
-
#
|
1619
|
-
def self?.open: (String name, ?String mode, ?Integer perm) -> IO?
|
1620
|
-
| [T] (String name, ?String mode, ?Integer perm) { (IO) -> T } -> T
|
1315
|
+
def self?.print: (*_ToS args) -> nil
|
1621
1316
|
|
1622
1317
|
# <!--
|
1623
1318
|
# rdoc-file=io.c
|
1624
|
-
# -
|
1319
|
+
# - printf(format_string, *objects) -> nil
|
1320
|
+
# - printf(io, format_string, *objects) -> nil
|
1625
1321
|
# -->
|
1626
|
-
#
|
1627
|
-
# is not `nil`, its contents will appear between each field. If the output
|
1628
|
-
# record separator (`$\`) is not `nil`, it will be appended to the output. If no
|
1629
|
-
# arguments are given, prints `$_`. Objects that aren't strings will be
|
1630
|
-
# converted by calling their `to_s` method.
|
1322
|
+
# Equivalent to:
|
1631
1323
|
#
|
1632
|
-
#
|
1633
|
-
# $, = ", "
|
1634
|
-
# $\ = "\n"
|
1635
|
-
# print "cat", [1,2,3], 99
|
1324
|
+
# io.write(sprintf(format_string, *objects))
|
1636
1325
|
#
|
1637
|
-
#
|
1326
|
+
# For details on `format_string`, see [Format
|
1327
|
+
# Specifications](rdoc-ref:format_specifications.rdoc).
|
1638
1328
|
#
|
1639
|
-
#
|
1640
|
-
#
|
1329
|
+
# With the single argument `format_string`, formats `objects` into the string,
|
1330
|
+
# then writes the formatted string to $stdout:
|
1641
1331
|
#
|
1642
|
-
|
1643
|
-
|
1644
|
-
#
|
1645
|
-
#
|
1646
|
-
#
|
1647
|
-
#
|
1648
|
-
#
|
1649
|
-
#
|
1650
|
-
#
|
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
|
1651
1346
|
#
|
1652
|
-
#
|
1653
|
-
# $stdout.write(sprintf(string, obj, ...))
|
1347
|
+
# With no arguments, does nothing.
|
1654
1348
|
#
|
1655
|
-
def self?.printf: (
|
1656
|
-
| (String
|
1657
|
-
| () -> nil
|
1349
|
+
def self?.printf: () -> nil
|
1350
|
+
| (String fmt, *untyped args) -> nil
|
1351
|
+
| (_Writer io, string fmt, *untyped args) -> nil
|
1658
1352
|
|
1659
1353
|
# <!--
|
1660
1354
|
# rdoc-file=proc.c
|
@@ -1662,7 +1356,7 @@ module Kernel : BasicObject
|
|
1662
1356
|
# -->
|
1663
1357
|
# Equivalent to Proc.new.
|
1664
1358
|
#
|
1665
|
-
def self?.proc: () { () -> untyped } -> Proc
|
1359
|
+
def self?.proc: () { (?) -> untyped } -> Proc
|
1666
1360
|
|
1667
1361
|
# <!--
|
1668
1362
|
# rdoc-file=proc.c
|
@@ -1675,47 +1369,59 @@ module Kernel : BasicObject
|
|
1675
1369
|
|
1676
1370
|
# <!--
|
1677
1371
|
# rdoc-file=io.c
|
1678
|
-
# - putc(int)
|
1372
|
+
# - putc(int) -> int
|
1679
1373
|
# -->
|
1680
1374
|
# Equivalent to:
|
1681
1375
|
#
|
1682
1376
|
# $stdout.putc(int)
|
1683
1377
|
#
|
1684
|
-
#
|
1685
|
-
# multi-byte characters.
|
1378
|
+
# See IO#putc for important information regarding multi-byte characters.
|
1686
1379
|
#
|
1687
|
-
def self?.putc: (
|
1688
|
-
| (String
|
1380
|
+
def self?.putc: [T < _ToInt] (T chr) -> T
|
1381
|
+
| (String chr) -> String
|
1689
1382
|
|
1690
1383
|
# <!--
|
1691
1384
|
# rdoc-file=io.c
|
1692
|
-
# - puts(
|
1385
|
+
# - puts(*objects) -> nil
|
1693
1386
|
# -->
|
1694
1387
|
# Equivalent to
|
1695
1388
|
#
|
1696
|
-
# $stdout.puts(
|
1389
|
+
# $stdout.puts(objects)
|
1697
1390
|
#
|
1698
|
-
def self?.puts: (*
|
1391
|
+
def self?.puts: (*_ToS objects) -> nil
|
1699
1392
|
|
1700
1393
|
# <!--
|
1701
1394
|
# rdoc-file=io.c
|
1702
|
-
# - p(
|
1703
|
-
# - p(
|
1704
|
-
# - p
|
1395
|
+
# - p(object) -> obj
|
1396
|
+
# - p(*objects) -> array of objects
|
1397
|
+
# - p -> nil
|
1705
1398
|
# -->
|
1706
|
-
# For each object
|
1707
|
-
# program's standard output.
|
1399
|
+
# For each object `obj`, executes:
|
1708
1400
|
#
|
1709
|
-
#
|
1710
|
-
# s = S['dave', 'TX']
|
1711
|
-
# p s
|
1401
|
+
# $stdout.write(obj.inspect, "\n")
|
1712
1402
|
#
|
1713
|
-
#
|
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
|
1714
1412
|
#
|
1715
|
-
#
|
1413
|
+
# Output:
|
1716
1414
|
#
|
1717
|
-
|
1718
|
-
|
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
|
1719
1425
|
|
1720
1426
|
# <!--
|
1721
1427
|
# rdoc-file=lib/pp.rb
|
@@ -1723,10 +1429,11 @@ module Kernel : BasicObject
|
|
1723
1429
|
# -->
|
1724
1430
|
# prints arguments in pretty form.
|
1725
1431
|
#
|
1726
|
-
# pp returns argument(s).
|
1432
|
+
# `#pp` returns argument(s).
|
1727
1433
|
#
|
1728
1434
|
def self?.pp: [T] (T arg0) -> T
|
1729
|
-
| (*untyped
|
1435
|
+
| (untyped, untyped, *untyped) -> Array[untyped]
|
1436
|
+
| () -> nil
|
1730
1437
|
|
1731
1438
|
# <!--
|
1732
1439
|
# rdoc-file=random.c
|
@@ -1744,7 +1451,7 @@ module Kernel : BasicObject
|
|
1744
1451
|
# rand(100) #=> 12
|
1745
1452
|
#
|
1746
1453
|
# When `max` is a Range, `rand` returns a random number where
|
1747
|
-
# range.member?(number) == true
|
1454
|
+
# `range.member?(number) == true`.
|
1748
1455
|
#
|
1749
1456
|
# Negative or floating point values for `max` are allowed, but may give
|
1750
1457
|
# surprising results.
|
@@ -1758,65 +1465,98 @@ module Kernel : BasicObject
|
|
1758
1465
|
#
|
1759
1466
|
# See also Random.rand.
|
1760
1467
|
#
|
1761
|
-
def self?.rand: () -> Float
|
1762
|
-
| (
|
1763
|
-
| (::Range[Integer] arg0) -> Integer
|
1764
|
-
| (::Range[Float] arg0) -> Float
|
1468
|
+
def self?.rand: (?0) -> Float
|
1469
|
+
| (int arg0) -> Integer
|
1470
|
+
| (::Range[Integer] arg0) -> Integer?
|
1471
|
+
| (::Range[Float] arg0) -> Float?
|
1765
1472
|
|
1766
1473
|
# <!--
|
1767
1474
|
# rdoc-file=io.c
|
1768
|
-
# - readline(sep
|
1769
|
-
# - readline(limit) -> string
|
1770
|
-
# - readline(sep, limit) -> string
|
1475
|
+
# - readline(sep = $/, chomp: false) -> string
|
1476
|
+
# - readline(limit, chomp: false) -> string
|
1477
|
+
# - readline(sep, limit, chomp: false) -> string
|
1771
1478
|
# -->
|
1772
|
-
# Equivalent to Kernel
|
1773
|
-
#
|
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.
|
1774
1488
|
#
|
1775
1489
|
def self?.readline: (?String arg0, ?Integer arg1) -> String
|
1776
1490
|
|
1777
1491
|
# <!--
|
1778
1492
|
# rdoc-file=io.c
|
1779
|
-
# - readlines(sep
|
1780
|
-
# - readlines(limit)
|
1781
|
-
# - readlines(sep, limit) -> array
|
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
|
1782
1496
|
# -->
|
1783
|
-
# Returns an array containing the lines returned by calling
|
1784
|
-
#
|
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)).
|
1785
1499
|
#
|
1786
|
-
|
1787
|
-
|
1788
|
-
#
|
1789
|
-
#
|
1790
|
-
#
|
1791
|
-
#
|
1792
|
-
#
|
1793
|
-
#
|
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)).
|
1794
1534
|
#
|
1795
|
-
#
|
1796
|
-
#
|
1797
|
-
# `$LOAD_PATH` (`$:`). If the filename starts with './' or '../', resolution is
|
1798
|
-
# based on Dir.pwd.
|
1535
|
+
# Optional keyword argument `chomp` specifies whether line separators are to be
|
1536
|
+
# omitted:
|
1799
1537
|
#
|
1800
|
-
#
|
1801
|
-
#
|
1802
|
-
# on the current platform, Ruby loads the shared library as a Ruby extension.
|
1803
|
-
# Otherwise, Ruby tries adding ".rb", ".so", and so on to the name until found.
|
1804
|
-
# If the file named cannot be found, a LoadError will be raised.
|
1538
|
+
# $ cat t.txt | ruby -e "p readlines(chomp: true)"
|
1539
|
+
# ["First line", "Second line", "", "Fourth line", "Fifth line"]
|
1805
1540
|
#
|
1806
|
-
#
|
1807
|
-
#
|
1808
|
-
# 'socket.dll'` will load the socket extension.
|
1541
|
+
# Optional keyword arguments `enc_opts` specify encoding options; see [Encoding
|
1542
|
+
# options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
1809
1543
|
#
|
1810
|
-
|
1811
|
-
|
1812
|
-
#
|
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.
|
1813
1552
|
#
|
1814
|
-
#
|
1815
|
-
#
|
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).
|
1816
1557
|
#
|
1817
|
-
#
|
1818
|
-
#
|
1819
|
-
# propagated to the loading environment.
|
1558
|
+
# The normal `require` functionality of returning false if that file has already
|
1559
|
+
# been loaded is preserved.
|
1820
1560
|
#
|
1821
1561
|
def self?.require: (String path) -> bool
|
1822
1562
|
|
@@ -1824,33 +1564,49 @@ module Kernel : BasicObject
|
|
1824
1564
|
# rdoc-file=load.c
|
1825
1565
|
# - require_relative(string) -> true or false
|
1826
1566
|
# -->
|
1827
|
-
# Ruby tries to load the library named *string* relative to the
|
1828
|
-
#
|
1829
|
-
#
|
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.
|
1830
1571
|
#
|
1831
1572
|
def self?.require_relative: (String feature) -> bool
|
1832
1573
|
|
1833
1574
|
# <!--
|
1834
1575
|
# rdoc-file=io.c
|
1835
|
-
# - IO.select(
|
1576
|
+
# - IO.select(read_ios, write_ios = [], error_ios = [], timeout = nil) -> array or nil
|
1836
1577
|
# -->
|
1837
|
-
#
|
1838
|
-
# until one or more of
|
1839
|
-
#
|
1840
|
-
#
|
1841
|
-
#
|
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.
|
1842
1598
|
#
|
1843
1599
|
# IO.select peeks the buffer of IO objects for testing readability. If the IO
|
1844
1600
|
# buffer is not empty, IO.select immediately notifies readability. This "peek"
|
1845
1601
|
# only happens for IO objects. It does not happen for IO-like objects such as
|
1846
1602
|
# OpenSSL::SSL::SSLSocket.
|
1847
1603
|
#
|
1848
|
-
# The best way to use IO.select is invoking it after
|
1849
|
-
# #read_nonblock, #write_nonblock, etc. The methods raise an exception which
|
1850
|
-
# extended by IO::WaitReadable or IO::WaitWritable. The modules notify how
|
1851
|
-
# caller should wait with IO.select. If IO::WaitReadable is raised, the
|
1852
|
-
# should wait for reading. If IO::WaitWritable is raised, the caller
|
1853
|
-
# wait for writing.
|
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.
|
1854
1610
|
#
|
1855
1611
|
# So, blocking read (#readpartial) can be emulated using #read_nonblock and
|
1856
1612
|
# IO.select as follows:
|
@@ -1865,7 +1621,7 @@ module Kernel : BasicObject
|
|
1865
1621
|
# retry
|
1866
1622
|
# end
|
1867
1623
|
#
|
1868
|
-
# Especially, the combination of
|
1624
|
+
# Especially, the combination of non-blocking methods and IO.select is preferred
|
1869
1625
|
# for IO like objects such as OpenSSL::SSL::SSLSocket. It has #to_io method to
|
1870
1626
|
# return underlying IO object. IO.select calls #to_io to obtain the file
|
1871
1627
|
# descriptor to wait.
|
@@ -1891,13 +1647,13 @@ module Kernel : BasicObject
|
|
1891
1647
|
# blocking. So, the caller should wait for ready for writability as above
|
1892
1648
|
# example.
|
1893
1649
|
#
|
1894
|
-
# The combination of
|
1650
|
+
# The combination of non-blocking methods and IO.select is also useful for
|
1895
1651
|
# streams such as tty, pipe socket socket when multiple processes read from a
|
1896
1652
|
# stream.
|
1897
1653
|
#
|
1898
1654
|
# Finally, Linux kernel developers don't guarantee that readability of select(2)
|
1899
|
-
# means readability of following read(2) even for a single process
|
1900
|
-
# 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)
|
1901
1657
|
#
|
1902
1658
|
# Invoking IO.select before IO#readpartial works well as usual. However it is
|
1903
1659
|
# not the best way to use IO.select.
|
@@ -1924,18 +1680,7 @@ module Kernel : BasicObject
|
|
1924
1680
|
# string = string.byteslice(written..-1)
|
1925
1681
|
# end
|
1926
1682
|
#
|
1927
|
-
#
|
1928
|
-
# read_array
|
1929
|
-
# : an array of IO objects that wait until ready for read
|
1930
|
-
# write_array
|
1931
|
-
# : an array of IO objects that wait until ready for write
|
1932
|
-
# error_array
|
1933
|
-
# : an array of IO objects that wait for exceptions
|
1934
|
-
# timeout
|
1935
|
-
# : a numeric value in second
|
1936
|
-
#
|
1937
|
-
#
|
1938
|
-
# ### Example
|
1683
|
+
# Example:
|
1939
1684
|
#
|
1940
1685
|
# rp, wp = IO.pipe
|
1941
1686
|
# mesg = "ping "
|
@@ -1957,7 +1702,7 @@ module Kernel : BasicObject
|
|
1957
1702
|
# end
|
1958
1703
|
# }
|
1959
1704
|
#
|
1960
|
-
#
|
1705
|
+
# Output:
|
1961
1706
|
#
|
1962
1707
|
# ping pong
|
1963
1708
|
# ping pong
|
@@ -1965,117 +1710,121 @@ module Kernel : BasicObject
|
|
1965
1710
|
# (snipped)
|
1966
1711
|
# ping
|
1967
1712
|
#
|
1968
|
-
def self?.select: (::Array[IO] read, ?::Array[IO] write, ?::Array[IO] error, ?
|
1713
|
+
def self?.select: (::Array[IO] read, ?::Array[IO] write, ?::Array[IO] error, ?Time::_Timeout timeout) -> ::Array[String]
|
1969
1714
|
|
1970
1715
|
# <!--
|
1971
1716
|
# rdoc-file=process.c
|
1972
|
-
# - sleep(
|
1717
|
+
# - sleep(secs = nil) -> slept_secs
|
1973
1718
|
# -->
|
1974
|
-
# Suspends the current thread for
|
1975
|
-
#
|
1976
|
-
# seconds
|
1977
|
-
#
|
1978
|
-
#
|
1979
|
-
#
|
1980
|
-
# Time.new
|
1981
|
-
# sleep 1.2
|
1982
|
-
# Time.new
|
1983
|
-
#
|
1984
|
-
|
1985
|
-
|
1986
|
-
def self?.sleep: () -> bot
|
1987
|
-
| ((Integer | Float | _Divmod) duration) -> Integer
|
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
|
1988
1731
|
|
1732
|
+
%a{steep:deprecated}
|
1989
1733
|
interface _Divmod
|
1990
1734
|
def divmod: (Numeric) -> [ Numeric, Numeric ]
|
1991
1735
|
end
|
1992
1736
|
|
1993
1737
|
# <!--
|
1994
1738
|
# rdoc-file=io.c
|
1995
|
-
# - syscall(
|
1739
|
+
# - syscall(integer_callno, *arguments) -> integer
|
1996
1740
|
# -->
|
1997
|
-
#
|
1998
|
-
#
|
1741
|
+
# Invokes Posix system call [syscall(2)](https://linux.die.net/man/2/syscall),
|
1742
|
+
# which calls a specified function.
|
1999
1743
|
#
|
2000
|
-
#
|
2001
|
-
#
|
2002
|
-
#
|
2003
|
-
#
|
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.
|
2004
1748
|
#
|
2005
|
-
#
|
2006
|
-
#
|
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.
|
2007
1752
|
#
|
2008
|
-
#
|
1753
|
+
# Arguments `integer_callno` and `argument`, as well as the returned value, are
|
1754
|
+
# platform-dependent.
|
2009
1755
|
#
|
2010
|
-
#
|
2011
|
-
#
|
2012
|
-
# hello
|
1756
|
+
# Note: Method `syscall` is essentially unsafe and unportable. The DL (Fiddle)
|
1757
|
+
# library is preferred for safer and a bit more portable programming.
|
2013
1758
|
#
|
2014
|
-
#
|
2015
|
-
# system function just fails with NotImplementedError.
|
2016
|
-
#
|
2017
|
-
# **Note:** `syscall` is essentially unsafe and unportable. Feel free to shoot
|
2018
|
-
# your foot. The DL (Fiddle) library is preferred for safer and a bit more
|
2019
|
-
# portable programming.
|
1759
|
+
# Not implemented on all platforms.
|
2020
1760
|
#
|
2021
1761
|
def self?.syscall: (Integer num, *untyped args) -> untyped
|
2022
1762
|
|
2023
1763
|
# <!--
|
2024
1764
|
# rdoc-file=file.c
|
2025
|
-
# - test(
|
2026
|
-
# -->
|
2027
|
-
#
|
2028
|
-
#
|
2029
|
-
#
|
2030
|
-
#
|
2031
|
-
#
|
2032
|
-
#
|
2033
|
-
#
|
2034
|
-
#
|
2035
|
-
#
|
2036
|
-
#
|
2037
|
-
#
|
2038
|
-
#
|
2039
|
-
#
|
2040
|
-
#
|
2041
|
-
#
|
2042
|
-
#
|
2043
|
-
#
|
2044
|
-
#
|
2045
|
-
#
|
2046
|
-
#
|
2047
|
-
#
|
2048
|
-
#
|
2049
|
-
#
|
2050
|
-
#
|
2051
|
-
#
|
2052
|
-
#
|
2053
|
-
#
|
2054
|
-
#
|
2055
|
-
#
|
2056
|
-
#
|
2057
|
-
#
|
2058
|
-
#
|
2059
|
-
#
|
2060
|
-
#
|
2061
|
-
#
|
2062
|
-
#
|
2063
|
-
#
|
2064
|
-
#
|
2065
|
-
#
|
2066
|
-
#
|
2067
|
-
#
|
2068
|
-
#
|
2069
|
-
#
|
2070
|
-
#
|
2071
|
-
#
|
2072
|
-
#
|
2073
|
-
#
|
2074
|
-
#
|
2075
|
-
#
|
2076
|
-
#
|
2077
|
-
#
|
2078
|
-
#
|
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.
|
2079
1828
|
#
|
2080
1829
|
def self?.test: (String | Integer cmd, String | IO file1, ?String | IO file2) -> (TrueClass | FalseClass | Time | nil | Integer)
|
2081
1830
|
|
@@ -2088,7 +1837,7 @@ module Kernel : BasicObject
|
|
2088
1837
|
# optional second parameter supplies a return value for the `catch` block, which
|
2089
1838
|
# otherwise defaults to `nil`. For examples, see Kernel::catch.
|
2090
1839
|
#
|
2091
|
-
def self?.throw: (
|
1840
|
+
def self?.throw: (untyped tag, ?untyped obj) -> bot
|
2092
1841
|
|
2093
1842
|
# <!--
|
2094
1843
|
# rdoc-file=warning.rb
|
@@ -2099,420 +1848,1249 @@ module Kernel : BasicObject
|
|
2099
1848
|
# newline character to the string if the string does not end in a newline, and
|
2100
1849
|
# calls Warning.warn with the string.
|
2101
1850
|
#
|
2102
|
-
#
|
1851
|
+
# warn("warning 1", "warning 2")
|
2103
1852
|
#
|
2104
|
-
#
|
1853
|
+
# *produces:*
|
2105
1854
|
#
|
2106
|
-
#
|
2107
|
-
#
|
1855
|
+
# warning 1
|
1856
|
+
# warning 2
|
2108
1857
|
#
|
2109
1858
|
# If the `uplevel` keyword argument is given, the string will be prepended with
|
2110
1859
|
# information for the given caller frame in the same format used by the
|
2111
1860
|
# `rb_warn` C function.
|
2112
1861
|
#
|
2113
|
-
#
|
2114
|
-
#
|
2115
|
-
#
|
2116
|
-
#
|
1862
|
+
# # In baz.rb
|
1863
|
+
# def foo
|
1864
|
+
# warn("invalid call to foo", uplevel: 1)
|
1865
|
+
# end
|
2117
1866
|
#
|
2118
|
-
#
|
2119
|
-
#
|
2120
|
-
#
|
1867
|
+
# def bar
|
1868
|
+
# foo
|
1869
|
+
# end
|
2121
1870
|
#
|
2122
|
-
#
|
1871
|
+
# bar
|
2123
1872
|
#
|
2124
|
-
#
|
1873
|
+
# *produces:*
|
2125
1874
|
#
|
2126
|
-
#
|
1875
|
+
# baz.rb:6: warning: invalid call to foo
|
2127
1876
|
#
|
2128
1877
|
# If `category` keyword argument is given, passes the category to
|
2129
|
-
# `Warning.warn`. The category given must be
|
2130
|
-
# categories:
|
1878
|
+
# `Warning.warn`. The category given must be one of the following categories:
|
2131
1879
|
#
|
2132
1880
|
# :deprecated
|
2133
1881
|
# : Used for warning for deprecated functionality that may be removed in the
|
2134
1882
|
# future.
|
1883
|
+
#
|
2135
1884
|
# :experimental
|
2136
1885
|
# : Used for experimental features that may change in future releases.
|
2137
1886
|
#
|
2138
|
-
|
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
|
2139
1892
|
|
2140
1893
|
# <!--
|
2141
1894
|
# rdoc-file=process.c
|
2142
|
-
# - exec([env,]
|
1895
|
+
# - exec([env, ] command_line, options = {})
|
1896
|
+
# - exec([env, ] exe_path, *args, options = {})
|
2143
1897
|
# -->
|
2144
|
-
# Replaces the current process by
|
2145
|
-
#
|
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).
|
2146
1910
|
#
|
2147
|
-
# `
|
2148
|
-
#
|
2149
|
-
# `exec(cmdname, arg1, ...)`
|
2150
|
-
# : command name and one or more arguments (no shell)
|
2151
|
-
# `exec([cmdname, argv0], arg1, ...)`
|
2152
|
-
# : command name, [argv](0) and zero or more arguments (no shell)
|
1911
|
+
# Argument `env`, if given, is a hash that affects `ENV` for the new process;
|
1912
|
+
# see [Execution Environment](rdoc-ref:Process@Execution+Environment).
|
2153
1913
|
#
|
1914
|
+
# Argument `options` is a hash of options for the new process; see [Execution
|
1915
|
+
# Options](rdoc-ref:Process@Execution+Options).
|
2154
1916
|
#
|
2155
|
-
#
|
2156
|
-
# shell expansion before being executed.
|
1917
|
+
# The first required argument is one of the following:
|
2157
1918
|
#
|
2158
|
-
#
|
2159
|
-
#
|
2160
|
-
#
|
2161
|
-
# `COMSPEC`.
|
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.
|
2162
1922
|
#
|
2163
|
-
#
|
2164
|
-
# rules:
|
1923
|
+
# **Argument `command_line`**
|
2165
1924
|
#
|
2166
|
-
#
|
2167
|
-
#
|
2168
|
-
#
|
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:
|
2169
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.
|
2170
1932
|
#
|
2171
|
-
#
|
2172
|
-
# meta character).
|
1933
|
+
# The command line may also contain arguments and options for the command:
|
2173
1934
|
#
|
2174
|
-
#
|
2175
|
-
# and IO#pid for IO.popen) is the pid of the invoked command, not shell.
|
1935
|
+
# exec('echo "Foo"')
|
2176
1936
|
#
|
2177
|
-
#
|
2178
|
-
# command name and the rest are passed as parameters to command with no shell
|
2179
|
-
# expansion.
|
1937
|
+
# Output:
|
2180
1938
|
#
|
2181
|
-
#
|
2182
|
-
# two-element array at the beginning of the command, the first element is the
|
2183
|
-
# command to be executed, and the second argument is used as the `argv[0]`
|
2184
|
-
# value, which may show up in process listings.
|
1939
|
+
# Foo
|
2185
1940
|
#
|
2186
|
-
#
|
2187
|
-
#
|
2188
|
-
# program (including open file descriptors).
|
1941
|
+
# See [Execution Shell](rdoc-ref:Process@Execution+Shell) for details about the
|
1942
|
+
# shell.
|
2189
1943
|
#
|
2190
|
-
#
|
2191
|
-
# ::spawn for details.
|
1944
|
+
# Raises an exception if the new process could not execute.
|
2192
1945
|
#
|
2193
|
-
#
|
2194
|
-
# found) a SystemCallError exception is raised.
|
1946
|
+
# **Argument `exe_path`**
|
2195
1947
|
#
|
2196
|
-
#
|
2197
|
-
# `exec(2)` system call. See ::spawn for more details about the given `options`.
|
1948
|
+
# Argument `exe_path` is one of the following:
|
2198
1949
|
#
|
2199
|
-
# The
|
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.
|
2200
1953
|
#
|
2201
|
-
#
|
1954
|
+
# Example:
|
2202
1955
|
#
|
2203
|
-
#
|
2204
|
-
# not acceptable.
|
1956
|
+
# exec('/usr/bin/date')
|
2205
1957
|
#
|
2206
|
-
#
|
2207
|
-
# # never get here
|
1958
|
+
# Output:
|
2208
1959
|
#
|
2209
|
-
#
|
2210
|
-
# # never get here
|
1960
|
+
# Sat Aug 26 09:38:00 AM CDT 2023
|
2211
1961
|
#
|
2212
|
-
|
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
|
2213
1982
|
|
2214
1983
|
type redirect_fd = Integer | :in | :out | :err | IO | String | [ String ] | [ String, string | int ] | [ String, string | int, int ] | [ :child, int ] | :close
|
2215
1984
|
|
2216
1985
|
# <!--
|
2217
1986
|
# rdoc-file=process.c
|
2218
|
-
# - spawn([env,]
|
2219
|
-
# -
|
2220
|
-
# -->
|
2221
|
-
#
|
2222
|
-
#
|
2223
|
-
#
|
2224
|
-
#
|
2225
|
-
#
|
2226
|
-
# pid = spawn(RbConfig.ruby, "-eputs'Hello, world!'")
|
2227
|
-
# Process.wait pid
|
2228
|
-
#
|
2229
|
-
# This method is similar to Kernel#system but it doesn't wait for the command to
|
2230
|
-
# finish.
|
2231
|
-
#
|
2232
|
-
# The parent process should use Process.wait to collect the termination status
|
2233
|
-
# of its child or use Process.detach to register disinterest in their status;
|
2234
|
-
# otherwise, the operating system may accumulate zombie processes.
|
2235
|
-
#
|
2236
|
-
# spawn has bunch of options to specify process attributes:
|
2237
|
-
#
|
2238
|
-
# env: hash
|
2239
|
-
# name => val : set the environment variable
|
2240
|
-
# name => nil : unset the environment variable
|
2241
|
-
#
|
2242
|
-
# the keys and the values except for +nil+ must be strings.
|
2243
|
-
# command...:
|
2244
|
-
# commandline : command line string which is passed to the standard shell
|
2245
|
-
# cmdname, arg1, ... : command name and one or more arguments (This form does not use the shell. See below for caveats.)
|
2246
|
-
# [cmdname, argv0], arg1, ... : command name, argv[0] and zero or more arguments (no shell)
|
2247
|
-
# options: hash
|
2248
|
-
# clearing environment variables:
|
2249
|
-
# :unsetenv_others => true : clear environment variables except specified by env
|
2250
|
-
# :unsetenv_others => false : don't clear (default)
|
2251
|
-
# process group:
|
2252
|
-
# :pgroup => true or 0 : make a new process group
|
2253
|
-
# :pgroup => pgid : join the specified process group
|
2254
|
-
# :pgroup => nil : don't change the process group (default)
|
2255
|
-
# create new process group: Windows only
|
2256
|
-
# :new_pgroup => true : the new process is the root process of a new process group
|
2257
|
-
# :new_pgroup => false : don't create a new process group (default)
|
2258
|
-
# resource limit: resourcename is core, cpu, data, etc. See Process.setrlimit.
|
2259
|
-
# :rlimit_resourcename => limit
|
2260
|
-
# :rlimit_resourcename => [cur_limit, max_limit]
|
2261
|
-
# umask:
|
2262
|
-
# :umask => int
|
2263
|
-
# redirection:
|
2264
|
-
# key:
|
2265
|
-
# FD : single file descriptor in child process
|
2266
|
-
# [FD, FD, ...] : multiple file descriptor in child process
|
2267
|
-
# value:
|
2268
|
-
# FD : redirect to the file descriptor in parent process
|
2269
|
-
# string : redirect to file with open(string, "r" or "w")
|
2270
|
-
# [string] : redirect to file with open(string, File::RDONLY)
|
2271
|
-
# [string, open_mode] : redirect to file with open(string, open_mode, 0644)
|
2272
|
-
# [string, open_mode, perm] : redirect to file with open(string, open_mode, perm)
|
2273
|
-
# [:child, FD] : redirect to the redirected file descriptor
|
2274
|
-
# :close : close the file descriptor in child process
|
2275
|
-
# FD is one of follows
|
2276
|
-
# :in : the file descriptor 0 which is the standard input
|
2277
|
-
# :out : the file descriptor 1 which is the standard output
|
2278
|
-
# :err : the file descriptor 2 which is the standard error
|
2279
|
-
# integer : the file descriptor of specified the integer
|
2280
|
-
# io : the file descriptor specified as io.fileno
|
2281
|
-
# file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not
|
2282
|
-
# :close_others => false : inherit
|
2283
|
-
# current directory:
|
2284
|
-
# :chdir => str
|
2285
|
-
#
|
2286
|
-
# The `cmdname, arg1, ...` form does not use the shell. However, on different
|
2287
|
-
# OSes, different things are provided as built-in commands. An example of this
|
2288
|
-
# is +'echo'+, which is a built-in on Windows, but is a normal program on Linux
|
2289
|
-
# and Mac OS X. This means that `Process.spawn 'echo', '%Path%'` will display
|
2290
|
-
# the contents of the `%Path%` environment variable on Windows, but
|
2291
|
-
# `Process.spawn 'echo', '$PATH'` prints the literal `$PATH`.
|
2292
|
-
#
|
2293
|
-
# If a hash is given as `env`, the environment is updated by `env` before
|
2294
|
-
# `exec(2)` in the child process. If a pair in `env` has nil as the value, the
|
2295
|
-
# variable is deleted.
|
2296
|
-
#
|
2297
|
-
# # set FOO as BAR and unset BAZ.
|
2298
|
-
# pid = spawn({"FOO"=>"BAR", "BAZ"=>nil}, command)
|
2299
|
-
#
|
2300
|
-
# If a hash is given as `options`, it specifies process group, create new
|
2301
|
-
# process group, resource limit, current directory, umask and redirects for the
|
2302
|
-
# child process. Also, it can be specified to clear environment variables.
|
2303
|
-
#
|
2304
|
-
# The `:unsetenv_others` key in `options` specifies to clear environment
|
2305
|
-
# variables, other than specified by `env`.
|
2306
|
-
#
|
2307
|
-
# pid = spawn(command, :unsetenv_others=>true) # no environment variable
|
2308
|
-
# pid = spawn({"FOO"=>"BAR"}, command, :unsetenv_others=>true) # FOO only
|
2309
|
-
#
|
2310
|
-
# The `:pgroup` key in `options` specifies a process group. The corresponding
|
2311
|
-
# value should be true, zero, a positive integer, or nil. true and zero cause
|
2312
|
-
# the process to be a process leader of a new process group. A non-zero positive
|
2313
|
-
# integer causes the process to join the provided process group. The default
|
2314
|
-
# value, nil, causes the process to remain in the same process group.
|
2315
|
-
#
|
2316
|
-
# pid = spawn(command, :pgroup=>true) # process leader
|
2317
|
-
# pid = spawn(command, :pgroup=>10) # belongs to the process group 10
|
2318
|
-
#
|
2319
|
-
# The `:new_pgroup` key in `options` specifies to pass
|
2320
|
-
# `CREATE_NEW_PROCESS_GROUP` flag to `CreateProcessW()` that is Windows API.
|
2321
|
-
# This option is only for Windows. true means the new process is the root
|
2322
|
-
# process of the new process group. The new process has CTRL+C disabled. This
|
2323
|
-
# flag is necessary for `Process.kill(:SIGINT, pid)` on the subprocess.
|
2324
|
-
# :new_pgroup is false by default.
|
2325
|
-
#
|
2326
|
-
# pid = spawn(command, :new_pgroup=>true) # new process group
|
2327
|
-
# pid = spawn(command, :new_pgroup=>false) # same process group
|
2328
|
-
#
|
2329
|
-
# The `:rlimit_`*foo* key specifies a resource limit. *foo* should be one of
|
2330
|
-
# resource types such as `core`. The corresponding value should be an integer or
|
2331
|
-
# an array which have one or two integers: same as cur_limit and max_limit
|
2332
|
-
# arguments for Process.setrlimit.
|
2333
|
-
#
|
2334
|
-
# cur, max = Process.getrlimit(:CORE)
|
2335
|
-
# pid = spawn(command, :rlimit_core=>[0,max]) # disable core temporary.
|
2336
|
-
# pid = spawn(command, :rlimit_core=>max) # enable core dump
|
2337
|
-
# pid = spawn(command, :rlimit_core=>0) # never dump core.
|
2338
|
-
#
|
2339
|
-
# The `:umask` key in `options` specifies the umask.
|
2340
|
-
#
|
2341
|
-
# pid = spawn(command, :umask=>077)
|
2342
|
-
#
|
2343
|
-
# The :in, :out, :err, an integer, an IO and an array key specifies a
|
2344
|
-
# redirection. The redirection maps a file descriptor in the child process.
|
2345
|
-
#
|
2346
|
-
# For example, stderr can be merged into stdout as follows:
|
2347
|
-
#
|
2348
|
-
# pid = spawn(command, :err=>:out)
|
2349
|
-
# pid = spawn(command, 2=>1)
|
2350
|
-
# pid = spawn(command, STDERR=>:out)
|
2351
|
-
# pid = spawn(command, STDERR=>STDOUT)
|
2352
|
-
#
|
2353
|
-
# The hash keys specifies a file descriptor in the child process started by
|
2354
|
-
# #spawn. :err, 2 and STDERR specifies the standard error stream (stderr).
|
2355
|
-
#
|
2356
|
-
# The hash values specifies a file descriptor in the parent process which
|
2357
|
-
# invokes #spawn. :out, 1 and STDOUT specifies the standard output stream
|
2358
|
-
# (stdout).
|
2359
|
-
#
|
2360
|
-
# In the above example, the standard output in the child process is not
|
2361
|
-
# specified. So it is inherited from the parent process.
|
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`.
|
2362
1994
|
#
|
2363
|
-
#
|
1995
|
+
# This method has potential security vulnerabilities if called with untrusted
|
1996
|
+
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
2364
1997
|
#
|
2365
|
-
#
|
1998
|
+
# Returns the process ID (pid) of the new process, without waiting for it to
|
1999
|
+
# complete.
|
2366
2000
|
#
|
2367
|
-
#
|
2368
|
-
# pid = spawn(command, :out=>"/dev/null") # write mode
|
2369
|
-
# pid = spawn(command, :err=>"log") # write mode
|
2370
|
-
# pid = spawn(command, [:out, :err]=>"/dev/null") # write mode
|
2371
|
-
# pid = spawn(command, 3=>"/dev/null") # read mode
|
2001
|
+
# To avoid zombie processes, the parent process should call either:
|
2372
2002
|
#
|
2373
|
-
#
|
2374
|
-
#
|
2003
|
+
# * Process.wait, to collect the termination statuses of its children.
|
2004
|
+
# * Process.detach, to register disinterest in their status.
|
2375
2005
|
#
|
2376
|
-
#
|
2377
|
-
#
|
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).
|
2378
2010
|
#
|
2379
|
-
#
|
2380
|
-
#
|
2381
|
-
# pid = spawn(command, :out=>["log", "w"]) # 0644 assumed
|
2382
|
-
# pid = spawn(command, :out=>["log", "w", 0600])
|
2383
|
-
# pid = spawn(command, :out=>["log", File::WRONLY|File::EXCL|File::CREAT, 0600])
|
2011
|
+
# Argument `env`, if given, is a hash that affects `ENV` for the new process;
|
2012
|
+
# see [Execution Environment](rdoc-ref:Process@Execution+Environment).
|
2384
2013
|
#
|
2385
|
-
#
|
2386
|
-
#
|
2387
|
-
# The permission should be an integer. If the permission is omitted or nil, 0644
|
2388
|
-
# is assumed.
|
2014
|
+
# Argument `options` is a hash of options for the new process; see [Execution
|
2015
|
+
# Options](rdoc-ref:Process@Execution+Options).
|
2389
2016
|
#
|
2390
|
-
#
|
2391
|
-
# are redirected.
|
2017
|
+
# The first required argument is one of the following:
|
2392
2018
|
#
|
2393
|
-
#
|
2394
|
-
#
|
2395
|
-
#
|
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.
|
2396
2022
|
#
|
2397
|
-
#
|
2398
|
-
# means the file descriptor in the child process. This is different from fd. For
|
2399
|
-
# example, :err=>:out means redirecting child stderr to parent stdout. But
|
2400
|
-
# :err=>[:child, :out] means redirecting child stderr to child stdout. They
|
2401
|
-
# differ if stdout is redirected in the child process as follows.
|
2023
|
+
# **Argument `command_line`**
|
2402
2024
|
#
|
2403
|
-
#
|
2404
|
-
#
|
2405
|
-
#
|
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:
|
2406
2028
|
#
|
2407
|
-
#
|
2408
|
-
#
|
2409
|
-
#
|
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
|
2410
2037
|
#
|
2411
|
-
#
|
2412
|
-
# p io.read #=> "out\nerr\n"
|
2038
|
+
# The command line may also contain arguments and options for the command:
|
2413
2039
|
#
|
2414
|
-
#
|
2040
|
+
# spawn('echo "Foo"') # => 799031
|
2041
|
+
# Process.wait # => 799031
|
2415
2042
|
#
|
2416
|
-
#
|
2043
|
+
# Output:
|
2417
2044
|
#
|
2418
|
-
#
|
2419
|
-
# "standard" descriptors are 0, 1 and 2. This behavior is specified by
|
2420
|
-
# :close_others option. :close_others doesn't affect the standard descriptors
|
2421
|
-
# which are closed only if :close is specified explicitly.
|
2045
|
+
# Foo
|
2422
2046
|
#
|
2423
|
-
#
|
2424
|
-
#
|
2047
|
+
# See [Execution Shell](rdoc-ref:Process@Execution+Shell) for details about the
|
2048
|
+
# shell.
|
2425
2049
|
#
|
2426
|
-
#
|
2050
|
+
# Raises an exception if the new process could not execute.
|
2427
2051
|
#
|
2428
|
-
#
|
2429
|
-
# :close_others option.
|
2052
|
+
# **Argument `exe_path`**
|
2430
2053
|
#
|
2431
|
-
#
|
2054
|
+
# Argument `exe_path` is one of the following:
|
2432
2055
|
#
|
2433
|
-
#
|
2434
|
-
#
|
2435
|
-
#
|
2436
|
-
# w.close
|
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.
|
2437
2059
|
#
|
2438
|
-
#
|
2060
|
+
# spawn('/usr/bin/date') # Path to date on Unix-style system.
|
2061
|
+
# Process.wait
|
2439
2062
|
#
|
2440
|
-
#
|
2441
|
-
# system(command, f=>:close) # don't inherit f.
|
2063
|
+
# Output:
|
2442
2064
|
#
|
2443
|
-
#
|
2065
|
+
# Mon Aug 28 11:43:10 AM CDT 2023
|
2444
2066
|
#
|
2445
|
-
#
|
2446
|
-
#
|
2447
|
-
# log_r, log_w = IO.pipe
|
2448
|
-
# pid = spawn("valgrind", "--log-fd=#{log_w.fileno}", "echo", "a", log_w=>log_w)
|
2449
|
-
# log_w.close
|
2450
|
-
# p log_r.read
|
2067
|
+
# Ruby invokes the executable directly. This form does not use the shell; see
|
2068
|
+
# [Arguments args](rdoc-ref:Process@Arguments+args) for caveats.
|
2451
2069
|
#
|
2452
|
-
#
|
2070
|
+
# If one or more `args` is given, each is an argument or option to be passed to
|
2071
|
+
# the executable:
|
2453
2072
|
#
|
2454
|
-
#
|
2073
|
+
# spawn('echo', 'C*') # => 799392
|
2074
|
+
# Process.wait # => 799392
|
2075
|
+
# spawn('echo', 'hello', 'world') # => 799393
|
2076
|
+
# Process.wait # => 799393
|
2455
2077
|
#
|
2456
|
-
#
|
2457
|
-
# specifies file descriptors in the parent process. So the above specifies
|
2458
|
-
# exchanging stdout and stderr. Internally, `spawn` uses an extra file
|
2459
|
-
# descriptor to resolve such cyclic file descriptor mapping.
|
2078
|
+
# Output:
|
2460
2079
|
#
|
2461
|
-
#
|
2080
|
+
# C*
|
2081
|
+
# hello world
|
2082
|
+
#
|
2083
|
+
# Raises an exception if the new process could not execute.
|
2462
2084
|
#
|
2463
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
|
2464
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
|
2465
2087
|
|
2466
2088
|
# <!--
|
2467
2089
|
# rdoc-file=process.c
|
2468
|
-
# - system([env,]
|
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
|
2469
2423
|
# -->
|
2470
|
-
#
|
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.
|
2471
2427
|
#
|
2472
|
-
#
|
2473
|
-
#
|
2474
|
-
# `
|
2475
|
-
# : command name and one or more arguments (no shell)
|
2476
|
-
# `[cmdname, argv0], arg1, ...`
|
2477
|
-
# : command name, `argv[0]` and zero or more arguments (no shell)
|
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`):
|
2478
2431
|
#
|
2432
|
+
# obj = "a"
|
2433
|
+
# other = obj.dup
|
2479
2434
|
#
|
2480
|
-
#
|
2481
|
-
#
|
2482
|
-
#
|
2435
|
+
# obj == other #=> true
|
2436
|
+
# obj.equal? other #=> false
|
2437
|
+
# obj.equal? obj #=> true
|
2483
2438
|
#
|
2484
|
-
#
|
2485
|
-
#
|
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.
|
2486
2444
|
#
|
2487
|
-
#
|
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:
|
2488
2449
|
#
|
2489
|
-
#
|
2490
|
-
#
|
2450
|
+
# 1 == 1.0 #=> true
|
2451
|
+
# 1.eql? 1.0 #=> false
|
2491
2452
|
#
|
2492
|
-
|
2493
|
-
|
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"
|
2494
2493
|
#
|
2495
2494
|
# *produces:*
|
2496
2495
|
#
|
2497
|
-
#
|
2498
|
-
#
|
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
|
2499
2512
|
#
|
2500
|
-
|
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`.
|
2501
2521
|
#
|
2502
|
-
#
|
2503
|
-
#
|
2504
|
-
#
|
2505
|
-
# # => nil
|
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.
|
2506
2525
|
#
|
2507
|
-
#
|
2508
|
-
#
|
2509
|
-
#
|
2510
|
-
#
|
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.
|
2511
2530
|
#
|
2512
|
-
#
|
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.
|
2513
2533
|
#
|
2514
|
-
|
2515
|
-
|
2516
|
-
|
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]
|
2517
2837
|
|
2518
|
-
|
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
|