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/io.rbs
CHANGED
@@ -1,230 +1,90 @@
|
|
1
1
|
# <!-- rdoc-file=io.c -->
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
2
|
+
# An instance of class IO (commonly called a *stream*) represents an
|
3
|
+
# input/output stream in the underlying operating system. Class IO is the basis
|
4
|
+
# for input and output in Ruby.
|
5
5
|
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# The Kernel#open method can create an IO (or File) object for these types of
|
11
|
-
# arguments:
|
12
|
-
#
|
13
|
-
# * A plain string represents a filename suitable for the underlying operating
|
14
|
-
# system.
|
15
|
-
#
|
16
|
-
# * A string starting with `"|"` indicates a subprocess. The remainder of the
|
17
|
-
# string following the `"|"` is invoked as a process with appropriate
|
18
|
-
# input/output channels connected to it.
|
19
|
-
#
|
20
|
-
# * A string equal to `"|-"` will create another Ruby instance as a
|
21
|
-
# subprocess.
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# The IO may be opened with different file modes (read-only, write-only) and
|
25
|
-
# encodings for proper conversion. See IO.new for these options. See
|
26
|
-
# Kernel#open for details of the various command formats described above.
|
27
|
-
#
|
28
|
-
# IO.popen, the Open3 library, or Process#spawn may also be used to communicate
|
29
|
-
# with subprocesses through an IO.
|
30
|
-
#
|
31
|
-
# Ruby will convert pathnames between different operating system conventions if
|
32
|
-
# possible. For instance, on a Windows system the filename
|
33
|
-
# `"/gumby/ruby/test.rb"` will be opened as `"\gumby\ruby\test.rb"`. When
|
34
|
-
# specifying a Windows-style filename in a Ruby string, remember to escape the
|
35
|
-
# backslashes:
|
36
|
-
#
|
37
|
-
# "C:\\gumby\\ruby\\test.rb"
|
38
|
-
#
|
39
|
-
# Our examples here will use the Unix-style forward slashes; File::ALT_SEPARATOR
|
40
|
-
# can be used to get the platform-specific separator character.
|
6
|
+
# Class File is the only class in the Ruby core that is a subclass of IO. Some
|
7
|
+
# classes in the Ruby standard library are also subclasses of IO; these include
|
8
|
+
# TCPSocket and UDPSocket.
|
41
9
|
#
|
42
10
|
# The global constant ARGF (also accessible as `$<`) provides an IO-like stream
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# access the name of the file currently being read.
|
46
|
-
#
|
47
|
-
# ## io/console
|
48
|
-
#
|
49
|
-
# The io/console extension provides methods for interacting with the console.
|
50
|
-
# The console can be accessed from IO.console or the standard input/output/error
|
51
|
-
# IO objects.
|
52
|
-
#
|
53
|
-
# Requiring io/console adds the following methods:
|
54
|
-
#
|
55
|
-
# * IO::console
|
56
|
-
# * IO#raw
|
57
|
-
# * IO#raw!
|
58
|
-
# * IO#cooked
|
59
|
-
# * IO#cooked!
|
60
|
-
# * IO#getch
|
61
|
-
# * IO#echo=
|
62
|
-
# * IO#echo?
|
63
|
-
# * IO#noecho
|
64
|
-
# * IO#winsize
|
65
|
-
# * IO#winsize=
|
66
|
-
# * IO#iflush
|
67
|
-
# * IO#ioflush
|
68
|
-
# * IO#oflush
|
69
|
-
#
|
70
|
-
#
|
71
|
-
# Example:
|
72
|
-
#
|
73
|
-
# require 'io/console'
|
74
|
-
# rows, columns = $stdout.winsize
|
75
|
-
# puts "Your screen is #{columns} wide and #{rows} tall"
|
76
|
-
#
|
77
|
-
# ## Example Files
|
78
|
-
#
|
79
|
-
# Many examples here use these filenames and their corresponding files:
|
80
|
-
#
|
81
|
-
# * `t.txt`: A text-only file that is assumed to exist via:
|
82
|
-
#
|
83
|
-
# text = <<~EOT
|
84
|
-
# This is line one.
|
85
|
-
# This is the second line.
|
86
|
-
# This is the third line.
|
87
|
-
# EOT
|
88
|
-
# File.write('t.txt', text)
|
89
|
-
#
|
90
|
-
# * `t.dat`: A data file that is assumed to exist via:
|
91
|
-
#
|
92
|
-
# data = "\u9990\u9991\u9992\u9993\u9994"
|
93
|
-
# f = File.open('t.dat', 'wb:UTF-16')
|
94
|
-
# f.write(data)
|
95
|
-
# f.close
|
96
|
-
#
|
97
|
-
# * `t.rus`: A Russian-language text file that is assumed to exist via:
|
98
|
-
#
|
99
|
-
# File.write('t.rus', "\u{442 435 441 442}")
|
100
|
-
#
|
101
|
-
# * `t.tmp`: A file that is assumed *not* to exist.
|
11
|
+
# that allows access to all file paths found in ARGV (or found in STDIN if ARGV
|
12
|
+
# is empty). ARGF is not itself a subclass of IO.
|
102
13
|
#
|
14
|
+
# Class StringIO provides an IO-like stream that handles a String. StringIO is
|
15
|
+
# not itself a subclass of IO.
|
103
16
|
#
|
104
|
-
#
|
17
|
+
# Important objects based on IO include:
|
105
18
|
#
|
106
|
-
#
|
107
|
-
#
|
19
|
+
# * $stdin.
|
20
|
+
# * $stdout.
|
21
|
+
# * $stderr.
|
22
|
+
# * Instances of class File.
|
108
23
|
#
|
109
|
-
#
|
110
|
-
# * Whether the stream is positioned at its beginning or its end.
|
111
|
-
# * Whether the stream treats data as text-only or binary.
|
112
|
-
# * The external and internal encodings.
|
24
|
+
# An instance of IO may be created using:
|
113
25
|
#
|
26
|
+
# * IO.new: returns a new IO object for the given integer file descriptor.
|
27
|
+
# * IO.open: passes a new IO object to the given block.
|
28
|
+
# * IO.popen: returns a new IO object that is connected to the $stdin and
|
29
|
+
# $stdout of a newly-launched subprocess.
|
30
|
+
# * Kernel#open: Returns a new IO object connected to a given source: stream,
|
31
|
+
# file, or subprocess.
|
114
32
|
#
|
115
|
-
#
|
33
|
+
# Like a File stream, an IO stream has:
|
116
34
|
#
|
117
|
-
#
|
118
|
-
#
|
35
|
+
# * A read/write mode, which may be read-only, write-only, or read/write; see
|
36
|
+
# [Read/Write Mode](rdoc-ref:File@Read-2FWrite+Mode).
|
37
|
+
# * A data mode, which may be text-only or binary; see [Data
|
38
|
+
# Mode](rdoc-ref:File@Data+Mode).
|
39
|
+
# * Internal and external encodings; see [Encodings](rdoc-ref:File@Encodings).
|
119
40
|
#
|
120
|
-
#
|
121
|
-
# * `File::WRONLY`: Open for writing only.
|
122
|
-
# * `File::RDWR`: Open for reading and writing.
|
123
|
-
# * `File::APPEND`: Open for appending only.
|
124
|
-
# * `File::CREAT`: Create file if it does not exist.
|
125
|
-
# * `File::EXCL`: Raise an exception if `File::CREAT` is given and the file
|
126
|
-
# exists.
|
41
|
+
# And like other IO streams, it has:
|
127
42
|
#
|
43
|
+
# * A position, which determines where in the stream the next read or write is
|
44
|
+
# to occur; see [Position](rdoc-ref:IO@Position).
|
45
|
+
# * A line number, which is a special, line-oriented, "position" (different
|
46
|
+
# from the position mentioned above); see [Line
|
47
|
+
# Number](rdoc-ref:IO@Line+Number).
|
128
48
|
#
|
129
|
-
#
|
49
|
+
# ## Extension `io/console`
|
130
50
|
#
|
131
|
-
#
|
132
|
-
#
|
51
|
+
# Extension `io/console` provides numerous methods for interacting with the
|
52
|
+
# console; requiring it adds numerous methods to class IO.
|
133
53
|
#
|
134
|
-
#
|
135
|
-
# integer.
|
136
|
-
#
|
137
|
-
# ### Mode Specified As a String
|
138
|
-
#
|
139
|
-
# When `mode` is a string it must begin with one of the following:
|
140
|
-
#
|
141
|
-
# * `'r'`: Read-only stream, positioned at the beginning; the stream cannot be
|
142
|
-
# changed to writable.
|
143
|
-
# * `'w'`: Write-only stream, positioned at the beginning; the stream cannot
|
144
|
-
# be changed to readable.
|
145
|
-
# * `'a'`: Write-only stream, positioned at the end; every write appends to
|
146
|
-
# the end; the stream cannot be changed to readable.
|
147
|
-
# * `'r+'`: Read-write stream, positioned at the beginning.
|
148
|
-
# * `'w+'`: Read-write stream, positioned at the end.
|
149
|
-
# * `'a+'`: Read-write stream, positioned at the end.
|
150
|
-
#
|
151
|
-
#
|
152
|
-
# For a writable file stream (that is, any except read-only), the file is
|
153
|
-
# truncated to zero if it exists, and is created if it does not exist.
|
154
|
-
#
|
155
|
-
# Examples:
|
156
|
-
#
|
157
|
-
# File.open('t.txt', 'r')
|
158
|
-
# File.open('t.tmp', 'w')
|
159
|
-
#
|
160
|
-
# Either of the following may be suffixed to any of the above:
|
161
|
-
#
|
162
|
-
# * `'t'`: Text data; sets the default external encoding to `Encoding::UTF_8`;
|
163
|
-
# on Windows, enables conversion between EOL and CRLF.
|
164
|
-
# * `'b'`: Binary data; sets the default external encoding to
|
165
|
-
# `Encoding::ASCII_8BIT`; on Windows, suppresses conversion between EOL and
|
166
|
-
# CRLF.
|
167
|
-
#
|
168
|
-
#
|
169
|
-
# If neither is given, the stream defaults to text data.
|
170
|
-
#
|
171
|
-
# Examples:
|
172
|
-
#
|
173
|
-
# File.open('t.txt', 'rt')
|
174
|
-
# File.open('t.dat', 'rb')
|
175
|
-
#
|
176
|
-
# The following may be suffixed to any writable mode above:
|
177
|
-
#
|
178
|
-
# * `'x'`: Creates the file if it does not exist; raises an exception if the
|
179
|
-
# file exists.
|
180
|
-
#
|
181
|
-
#
|
182
|
-
# Example:
|
183
|
-
#
|
184
|
-
# File.open('t.tmp', 'wx')
|
185
|
-
#
|
186
|
-
# Finally, the mode string may specify encodings -- either external encoding
|
187
|
-
# only or both external and internal encodings -- by appending one or both
|
188
|
-
# encoding names, separated by colons:
|
54
|
+
# ## Example Files
|
189
55
|
#
|
190
|
-
#
|
191
|
-
# f.external_encoding # => #<Encoding:ASCII-8BIT>
|
192
|
-
# f.internal_encoding # => nil
|
193
|
-
# f = File.new('t.dat', 'rb:UTF-16')
|
194
|
-
# f.external_encoding # => #<Encoding:UTF-16 (dummy)>
|
195
|
-
# f.internal_encoding # => nil
|
196
|
-
# f = File.new('t.dat', 'rb:UTF-16:UTF-16')
|
197
|
-
# f.external_encoding # => #<Encoding:UTF-16 (dummy)>
|
198
|
-
# f.internal_encoding # => #<Encoding:UTF-16>
|
56
|
+
# Many examples here use these variables:
|
199
57
|
#
|
200
|
-
#
|
58
|
+
# # English text with newlines.
|
59
|
+
# text = <<~EOT
|
60
|
+
# First line
|
61
|
+
# Second line
|
201
62
|
#
|
202
|
-
#
|
203
|
-
#
|
63
|
+
# Fourth line
|
64
|
+
# Fifth line
|
65
|
+
# EOT
|
204
66
|
#
|
205
|
-
#
|
67
|
+
# # Russian text.
|
68
|
+
# russian = "\u{442 435 441 442}" # => "тест"
|
206
69
|
#
|
207
|
-
#
|
208
|
-
#
|
70
|
+
# # Binary data.
|
71
|
+
# data = "\u9990\u9991\u9992\u9993\u9994"
|
209
72
|
#
|
210
|
-
#
|
211
|
-
#
|
212
|
-
# internal to external encoding. For further details about transcoding input and
|
213
|
-
# output, see Encoding.
|
73
|
+
# # Text file.
|
74
|
+
# File.write('t.txt', text)
|
214
75
|
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
# determine the encoding. For UTF-16 encodings the file open mode must be
|
218
|
-
# binary. If the BOM is found, it is stripped and the external encoding from the
|
219
|
-
# BOM is used.
|
76
|
+
# # File with Russian text.
|
77
|
+
# File.write('t.rus', russian)
|
220
78
|
#
|
221
|
-
#
|
222
|
-
#
|
79
|
+
# # File with binary data.
|
80
|
+
# f = File.new('t.dat', 'wb:UTF-16')
|
81
|
+
# f.write(data)
|
82
|
+
# f.close
|
223
83
|
#
|
224
84
|
# ## Open Options
|
225
85
|
#
|
226
|
-
# A number of IO methods accept
|
227
|
-
#
|
86
|
+
# A number of IO methods accept optional keyword arguments that determine how a
|
87
|
+
# new stream is to be opened:
|
228
88
|
#
|
229
89
|
# * `:mode`: Stream mode.
|
230
90
|
# * `:flags`: Integer file open flags; If `mode` is also given, the two are
|
@@ -241,430 +101,514 @@
|
|
241
101
|
# otherwise.
|
242
102
|
# * `:autoclose`: If a truthy value, specifies that the `fd` will close when
|
243
103
|
# the stream closes; otherwise it remains open.
|
244
|
-
#
|
104
|
+
# * `:path:` If a string value is provided, it is used in #inspect and is
|
105
|
+
# available as #path method.
|
245
106
|
#
|
246
107
|
# Also available are the options offered in String#encode, which may control
|
247
|
-
# conversion between external internal encoding.
|
108
|
+
# conversion between external and internal encoding.
|
248
109
|
#
|
249
|
-
# ##
|
110
|
+
# ## Basic IO
|
250
111
|
#
|
251
|
-
#
|
252
|
-
#
|
112
|
+
# You can perform basic stream IO with these methods, which typically operate on
|
113
|
+
# multi-byte strings:
|
253
114
|
#
|
254
|
-
# *
|
115
|
+
# * IO#read: Reads and returns some or all of the remaining bytes from the
|
116
|
+
# stream.
|
117
|
+
# * IO#write: Writes zero or more strings to the stream; each given object
|
118
|
+
# that is not already a string is converted via `to_s`.
|
255
119
|
#
|
120
|
+
# ### Position
|
256
121
|
#
|
257
|
-
#
|
122
|
+
# An IO stream has a nonnegative integer *position*, which is the byte offset at
|
123
|
+
# which the next read or write is to occur. A new stream has position zero (and
|
124
|
+
# line number zero); method `rewind` resets the position (and line number) to
|
125
|
+
# zero.
|
258
126
|
#
|
259
|
-
#
|
260
|
-
#
|
127
|
+
# These methods discard [buffers](rdoc-ref:IO@Buffering) and the
|
128
|
+
# Encoding::Converter instances used for that IO.
|
261
129
|
#
|
262
|
-
#
|
263
|
-
# position is `n` (*bytes*) may not have `n` *characters* preceding the current
|
264
|
-
# position -- there may be fewer.
|
130
|
+
# The relevant methods:
|
265
131
|
#
|
266
|
-
#
|
132
|
+
# * IO#tell (aliased as `#pos`): Returns the current position (in bytes) in
|
133
|
+
# the stream.
|
134
|
+
# * IO#pos=: Sets the position of the stream to a given integer `new_position`
|
135
|
+
# (in bytes).
|
136
|
+
# * IO#seek: Sets the position of the stream to a given integer `offset` (in
|
137
|
+
# bytes), relative to a given position `whence` (indicating the beginning,
|
138
|
+
# end, or current position).
|
139
|
+
# * IO#rewind: Positions the stream at the beginning (also resetting the line
|
140
|
+
# number).
|
267
141
|
#
|
268
|
-
#
|
269
|
-
# * At the end (position `self.size`) if its mode is `'a'`, `'w+'`, or `'a+'`.
|
142
|
+
# ### Open and Closed Streams
|
270
143
|
#
|
144
|
+
# A new IO stream may be open for reading, open for writing, or both.
|
271
145
|
#
|
272
|
-
#
|
146
|
+
# A stream is automatically closed when claimed by the garbage collector.
|
273
147
|
#
|
274
|
-
#
|
275
|
-
# * IO#eof? and its alias IO#eof return whether the position is at the end of
|
276
|
-
# a readable stream.
|
148
|
+
# Attempted reading or writing on a closed stream raises an exception.
|
277
149
|
#
|
150
|
+
# The relevant methods:
|
278
151
|
#
|
279
|
-
#
|
152
|
+
# * IO#close: Closes the stream for both reading and writing.
|
153
|
+
# * IO#close_read: Closes the stream for reading.
|
154
|
+
# * IO#close_write: Closes the stream for writing.
|
155
|
+
# * IO#closed?: Returns whether the stream is closed.
|
280
156
|
#
|
281
|
-
#
|
282
|
-
# f.tell # => 0
|
283
|
-
# f.readline # => "This is line one.\n"
|
284
|
-
# f.tell # => 19
|
285
|
-
# f.readline # => "This is the second line.\n"
|
286
|
-
# f.tell # => 45
|
287
|
-
# f.eof? # => false
|
288
|
-
# f.readline # => "Here's the third line.\n"
|
289
|
-
# f.eof? # => true
|
157
|
+
# ### End-of-Stream
|
290
158
|
#
|
291
|
-
#
|
159
|
+
# You can query whether a stream is positioned at its end:
|
292
160
|
#
|
293
|
-
#
|
294
|
-
#
|
295
|
-
# f.write('foo') # => 3
|
296
|
-
# f.tell # => 3
|
297
|
-
# f.write('bar') # => 3
|
298
|
-
# f.tell # => 6
|
161
|
+
# * IO#eof? (also aliased as `#eof`): Returns whether the stream is at
|
162
|
+
# end-of-stream.
|
299
163
|
#
|
300
|
-
#
|
164
|
+
# You can reposition to end-of-stream by using method IO#seek:
|
301
165
|
#
|
302
|
-
# f = File.
|
303
|
-
# f.
|
304
|
-
#
|
305
|
-
#
|
166
|
+
# f = File.new('t.txt')
|
167
|
+
# f.eof? # => false
|
168
|
+
# f.seek(0, :END)
|
169
|
+
# f.eof? # => true
|
170
|
+
# f.close
|
306
171
|
#
|
307
|
-
#
|
172
|
+
# Or by reading all stream content (which is slower than using IO#seek):
|
308
173
|
#
|
309
|
-
#
|
310
|
-
#
|
311
|
-
#
|
174
|
+
# f.rewind
|
175
|
+
# f.eof? # => false
|
176
|
+
# f.read # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
177
|
+
# f.eof? # => true
|
312
178
|
#
|
313
|
-
#
|
179
|
+
# ## Line IO
|
314
180
|
#
|
315
|
-
#
|
316
|
-
#
|
181
|
+
# Class IO supports line-oriented [input](rdoc-ref:IO@Line+Input) and
|
182
|
+
# [output](rdoc-ref:IO@Line+Output)
|
317
183
|
#
|
184
|
+
# ### Line Input
|
318
185
|
#
|
319
|
-
#
|
186
|
+
# Class IO supports line-oriented input for [files](rdoc-ref:IO@File+Line+Input)
|
187
|
+
# and [IO streams](rdoc-ref:IO@Stream+Line+Input)
|
320
188
|
#
|
321
|
-
#
|
322
|
-
# line number in the stream where the next read will occur.
|
189
|
+
# #### File Line Input
|
323
190
|
#
|
324
|
-
#
|
191
|
+
# You can read lines from a file using these methods:
|
325
192
|
#
|
326
|
-
#
|
193
|
+
# * IO.foreach: Reads each line and passes it to the given block.
|
194
|
+
# * IO.readlines: Reads and returns all lines in an array.
|
327
195
|
#
|
328
|
-
#
|
196
|
+
# For each of these methods:
|
329
197
|
#
|
330
|
-
#
|
331
|
-
#
|
332
|
-
#
|
333
|
-
#
|
334
|
-
#
|
335
|
-
# f.lineno # => 2
|
336
|
-
# f.readline # => "Here's the third line.\n"
|
337
|
-
# f.lineno # => 3
|
338
|
-
# f.eof? # => true
|
198
|
+
# * You can specify [open options](rdoc-ref:IO@Open+Options).
|
199
|
+
# * Line parsing depends on the effective *line separator*; see [Line
|
200
|
+
# Separator](rdoc-ref:IO@Line+Separator).
|
201
|
+
# * The length of each returned line depends on the effective *line limit*;
|
202
|
+
# see [Line Limit](rdoc-ref:IO@Line+Limit).
|
339
203
|
#
|
340
|
-
#
|
204
|
+
# #### Stream Line Input
|
341
205
|
#
|
342
|
-
#
|
343
|
-
# f.each_line do |line|
|
344
|
-
# p "position=#{f.pos} eof?=#{f.eof?} line=#{line}"
|
345
|
-
# end
|
206
|
+
# You can read lines from an IO stream using these methods:
|
346
207
|
#
|
347
|
-
#
|
208
|
+
# * IO#each_line: Reads each remaining line, passing it to the given block.
|
209
|
+
# * IO#gets: Returns the next line.
|
210
|
+
# * IO#readline: Like #gets, but raises an exception at end-of-stream.
|
211
|
+
# * IO#readlines: Returns all remaining lines in an array.
|
348
212
|
#
|
349
|
-
#
|
350
|
-
# "position=45 eof?=false line=This is the second line.\n"
|
351
|
-
# "position=70 eof?=true line=This is the third line.\n"
|
213
|
+
# For each of these methods:
|
352
214
|
#
|
353
|
-
#
|
215
|
+
# * Reading may begin mid-line, depending on the stream's *position*; see
|
216
|
+
# [Position](rdoc-ref:IO@Position).
|
217
|
+
# * Line parsing depends on the effective *line separator*; see [Line
|
218
|
+
# Separator](rdoc-ref:IO@Line+Separator).
|
219
|
+
# * The length of each returned line depends on the effective *line limit*;
|
220
|
+
# see [Line Limit](rdoc-ref:IO@Line+Limit).
|
354
221
|
#
|
355
|
-
#
|
222
|
+
# ##### Line Separator
|
356
223
|
#
|
357
|
-
#
|
358
|
-
#
|
359
|
-
# *
|
360
|
-
# Enumerable](Enumerable.html#module-Enumerable-label-What-27s+Here), which
|
361
|
-
# provides dozens of additional methods.
|
224
|
+
# Each of the [line input methods](rdoc-ref:IO@Line+Input) uses a *line
|
225
|
+
# separator*: the string that determines what is considered a line; it is
|
226
|
+
# sometimes called the *input record separator*.
|
362
227
|
#
|
228
|
+
# The default line separator is taken from global variable `$/`, whose initial
|
229
|
+
# value is `"\n"`.
|
363
230
|
#
|
364
|
-
#
|
231
|
+
# Generally, the line to be read next is all data from the current
|
232
|
+
# [position](rdoc-ref:IO@Position) to the next line separator (but see [Special
|
233
|
+
# Line Separator Values](rdoc-ref:IO@Special+Line+Separator+Values)):
|
365
234
|
#
|
366
|
-
#
|
367
|
-
#
|
368
|
-
#
|
369
|
-
#
|
370
|
-
#
|
371
|
-
#
|
372
|
-
#
|
373
|
-
#
|
374
|
-
# * [Low-Level Access](#class-IO-label-Low-Level+Access)
|
375
|
-
# * [Other](#class-IO-label-Other)
|
235
|
+
# f = File.new('t.txt')
|
236
|
+
# # Method gets with no sep argument returns the next line, according to $/.
|
237
|
+
# f.gets # => "First line\n"
|
238
|
+
# f.gets # => "Second line\n"
|
239
|
+
# f.gets # => "\n"
|
240
|
+
# f.gets # => "Fourth line\n"
|
241
|
+
# f.gets # => "Fifth line\n"
|
242
|
+
# f.close
|
376
243
|
#
|
244
|
+
# You can use a different line separator by passing argument `sep`:
|
377
245
|
#
|
378
|
-
#
|
246
|
+
# f = File.new('t.txt')
|
247
|
+
# f.gets('l') # => "First l"
|
248
|
+
# f.gets('li') # => "ine\nSecond li"
|
249
|
+
# f.gets('lin') # => "ne\n\nFourth lin"
|
250
|
+
# f.gets # => "e\n"
|
251
|
+
# f.close
|
379
252
|
#
|
380
|
-
#
|
381
|
-
# : Creates and returns a new IO object for the given integer file
|
382
|
-
# descriptor.
|
253
|
+
# Or by setting global variable `$/`:
|
383
254
|
#
|
384
|
-
#
|
385
|
-
#
|
255
|
+
# f = File.new('t.txt')
|
256
|
+
# $/ = 'l'
|
257
|
+
# f.gets # => "First l"
|
258
|
+
# f.gets # => "ine\nSecond l"
|
259
|
+
# f.gets # => "ine\n\nFourth l"
|
260
|
+
# f.close
|
386
261
|
#
|
387
|
-
#
|
388
|
-
# : Creates a connected pair of reader and writer IO objects.
|
262
|
+
# ##### Special Line Separator Values
|
389
263
|
#
|
390
|
-
#
|
391
|
-
#
|
264
|
+
# Each of the [line input methods](rdoc-ref:IO@Line+Input) accepts two special
|
265
|
+
# values for parameter `sep`:
|
392
266
|
#
|
393
|
-
#
|
394
|
-
# : Selects which given IO instances are ready for reading,
|
267
|
+
# * `nil`: The entire stream is to be read ("slurped") into a single string:
|
395
268
|
#
|
396
|
-
#
|
269
|
+
# f = File.new('t.txt')
|
270
|
+
# f.gets(nil) # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
271
|
+
# f.close
|
397
272
|
#
|
273
|
+
# * `''` (the empty string): The next "paragraph" is to be read (paragraphs
|
274
|
+
# being separated by two consecutive line separators):
|
398
275
|
#
|
399
|
-
#
|
276
|
+
# f = File.new('t.txt')
|
277
|
+
# f.gets('') # => "First line\nSecond line\n\n"
|
278
|
+
# f.gets('') # => "Fourth line\nFifth line\n"
|
279
|
+
# f.close
|
400
280
|
#
|
401
|
-
#
|
402
|
-
# : Returns a binary string with all or a subset of bytes from the given
|
403
|
-
# file.
|
281
|
+
# ##### Line Limit
|
404
282
|
#
|
405
|
-
#
|
406
|
-
#
|
283
|
+
# Each of the [line input methods](rdoc-ref:IO@Line+Input) uses an integer *line
|
284
|
+
# limit*, which restricts the number of bytes that may be returned. (A
|
285
|
+
# multi-byte character will not be split, and so a returned line may be slightly
|
286
|
+
# longer than the limit).
|
407
287
|
#
|
408
|
-
#
|
409
|
-
#
|
288
|
+
# The default limit value is `-1`; any negative limit value means that there is
|
289
|
+
# no limit.
|
410
290
|
#
|
411
|
-
#
|
412
|
-
# : Returns the next 8-bit byte read from `self` as an integer.
|
291
|
+
# If there is no limit, the line is determined only by `sep`.
|
413
292
|
#
|
414
|
-
# #
|
415
|
-
#
|
293
|
+
# # Text with 1-byte characters.
|
294
|
+
# File.open('t.txt') {|f| f.gets(1) } # => "F"
|
295
|
+
# File.open('t.txt') {|f| f.gets(2) } # => "Fi"
|
296
|
+
# File.open('t.txt') {|f| f.gets(3) } # => "Fir"
|
297
|
+
# File.open('t.txt') {|f| f.gets(4) } # => "Firs"
|
298
|
+
# # No more than one line.
|
299
|
+
# File.open('t.txt') {|f| f.gets(10) } # => "First line"
|
300
|
+
# File.open('t.txt') {|f| f.gets(11) } # => "First line\n"
|
301
|
+
# File.open('t.txt') {|f| f.gets(12) } # => "First line\n"
|
416
302
|
#
|
417
|
-
# #
|
418
|
-
#
|
303
|
+
# # Text with 2-byte characters, which will not be split.
|
304
|
+
# File.open('t.rus') {|f| f.gets(1).size } # => 1
|
305
|
+
# File.open('t.rus') {|f| f.gets(2).size } # => 1
|
306
|
+
# File.open('t.rus') {|f| f.gets(3).size } # => 2
|
307
|
+
# File.open('t.rus') {|f| f.gets(4).size } # => 2
|
419
308
|
#
|
420
|
-
#
|
421
|
-
# : Returns all or the next *n* bytes read from `self`, not updating the
|
422
|
-
# receiver's offset.
|
309
|
+
# ##### Line Separator and Line Limit
|
423
310
|
#
|
424
|
-
#
|
425
|
-
# : Returns all remaining or the next *n* bytes read from `self` for a
|
426
|
-
# given *n*.
|
311
|
+
# With arguments `sep` and `limit` given, combines the two behaviors:
|
427
312
|
#
|
428
|
-
#
|
429
|
-
#
|
430
|
-
# mode.
|
313
|
+
# * Returns the next line as determined by line separator `sep`.
|
314
|
+
# * But returns no more bytes than are allowed by the limit `limit`.
|
431
315
|
#
|
432
|
-
#
|
433
|
-
# : Returns the next byte read from `self`; same as #getbyte, but raises
|
434
|
-
# an exception on end-of-file.
|
316
|
+
# Example:
|
435
317
|
#
|
436
|
-
# #
|
437
|
-
#
|
438
|
-
# an exception on end-of-file.
|
318
|
+
# File.open('t.txt') {|f| f.gets('li', 20) } # => "First li"
|
319
|
+
# File.open('t.txt') {|f| f.gets('li', 2) } # => "Fi"
|
439
320
|
#
|
440
|
-
#
|
441
|
-
# : Returns the next line read from `self`; same as #getline, but raises
|
442
|
-
# an exception of end-of-file.
|
321
|
+
# ##### Line Number
|
443
322
|
#
|
444
|
-
#
|
445
|
-
# : Returns an array of all lines read read from `self`.
|
323
|
+
# A readable IO stream has a non-negative integer *line number*:
|
446
324
|
#
|
447
|
-
#
|
448
|
-
#
|
325
|
+
# * IO#lineno: Returns the line number.
|
326
|
+
# * IO#lineno=: Resets and returns the line number.
|
449
327
|
#
|
328
|
+
# Unless modified by a call to method IO#lineno=, the line number is the number
|
329
|
+
# of lines read by certain line-oriented methods, according to the effective
|
330
|
+
# [line separator](rdoc-ref:IO@Line+Separator):
|
450
331
|
#
|
332
|
+
# * IO.foreach: Increments the line number on each call to the block.
|
333
|
+
# * IO#each_line: Increments the line number on each call to the block.
|
334
|
+
# * IO#gets: Increments the line number.
|
335
|
+
# * IO#readline: Increments the line number.
|
336
|
+
# * IO#readlines: Increments the line number for each line read.
|
451
337
|
#
|
452
|
-
#
|
338
|
+
# A new stream is initially has line number zero (and position zero); method
|
339
|
+
# `rewind` resets the line number (and position) to zero:
|
453
340
|
#
|
454
|
-
#
|
455
|
-
#
|
456
|
-
#
|
341
|
+
# f = File.new('t.txt')
|
342
|
+
# f.lineno # => 0
|
343
|
+
# f.gets # => "First line\n"
|
344
|
+
# f.lineno # => 1
|
345
|
+
# f.rewind
|
346
|
+
# f.lineno # => 0
|
347
|
+
# f.close
|
457
348
|
#
|
458
|
-
#
|
459
|
-
# : Writes the given string to `self`.
|
349
|
+
# Reading lines from a stream usually changes its line number:
|
460
350
|
#
|
461
|
-
#
|
462
|
-
#
|
351
|
+
# f = File.new('t.txt', 'r')
|
352
|
+
# f.lineno # => 0
|
353
|
+
# f.readline # => "This is line one.\n"
|
354
|
+
# f.lineno # => 1
|
355
|
+
# f.readline # => "This is the second line.\n"
|
356
|
+
# f.lineno # => 2
|
357
|
+
# f.readline # => "Here's the third line.\n"
|
358
|
+
# f.lineno # => 3
|
359
|
+
# f.eof? # => true
|
360
|
+
# f.close
|
463
361
|
#
|
464
|
-
#
|
465
|
-
# : Prints last read line or given objects to `self`.
|
362
|
+
# Iterating over lines in a stream usually changes its line number:
|
466
363
|
#
|
467
|
-
#
|
468
|
-
#
|
364
|
+
# File.open('t.txt') do |f|
|
365
|
+
# f.each_line do |line|
|
366
|
+
# p "position=#{f.pos} eof?=#{f.eof?} lineno=#{f.lineno}"
|
367
|
+
# end
|
368
|
+
# end
|
469
369
|
#
|
470
|
-
#
|
471
|
-
# : Writes a character to `self`.
|
370
|
+
# Output:
|
472
371
|
#
|
473
|
-
#
|
474
|
-
#
|
372
|
+
# "position=11 eof?=false lineno=1"
|
373
|
+
# "position=23 eof?=false lineno=2"
|
374
|
+
# "position=24 eof?=false lineno=3"
|
375
|
+
# "position=36 eof?=false lineno=4"
|
376
|
+
# "position=47 eof?=true lineno=5"
|
475
377
|
#
|
476
|
-
#
|
477
|
-
#
|
478
|
-
# receiver's offset.
|
378
|
+
# Unlike the stream's [position](rdoc-ref:IO@Position), the line number does not
|
379
|
+
# affect where the next read or write will occur:
|
479
380
|
#
|
480
|
-
#
|
481
|
-
#
|
381
|
+
# f = File.new('t.txt')
|
382
|
+
# f.lineno = 1000
|
383
|
+
# f.lineno # => 1000
|
384
|
+
# f.gets # => "First line\n"
|
385
|
+
# f.lineno # => 1001
|
386
|
+
# f.close
|
482
387
|
#
|
483
|
-
#
|
484
|
-
# : Writes one or more given strings to `self` in non-blocking mode.
|
388
|
+
# Associated with the line number is the global variable `$.`:
|
485
389
|
#
|
390
|
+
# * When a stream is opened, `$.` is not set; its value is left over from
|
391
|
+
# previous activity in the process:
|
486
392
|
#
|
393
|
+
# $. = 41
|
394
|
+
# f = File.new('t.txt')
|
395
|
+
# $. = 41
|
396
|
+
# # => 41
|
397
|
+
# f.close
|
487
398
|
#
|
488
|
-
#
|
399
|
+
# * When a stream is read, `$.` is set to the line number for that stream:
|
400
|
+
#
|
401
|
+
# f0 = File.new('t.txt')
|
402
|
+
# f1 = File.new('t.dat')
|
403
|
+
# f0.readlines # => ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
404
|
+
# $. # => 5
|
405
|
+
# f1.readlines # => ["\xFE\xFF\x99\x90\x99\x91\x99\x92\x99\x93\x99\x94"]
|
406
|
+
# $. # => 1
|
407
|
+
# f0.close
|
408
|
+
# f1.close
|
409
|
+
#
|
410
|
+
# * Methods IO#rewind and IO#seek do not affect `$.`:
|
411
|
+
#
|
412
|
+
# f = File.new('t.txt')
|
413
|
+
# f.readlines # => ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
414
|
+
# $. # => 5
|
415
|
+
# f.rewind
|
416
|
+
# f.seek(0, :SET)
|
417
|
+
# $. # => 5
|
418
|
+
# f.close
|
489
419
|
#
|
490
|
-
#
|
491
|
-
# : Returns the current line number in `self`.
|
420
|
+
# ### Line Output
|
492
421
|
#
|
493
|
-
#
|
494
|
-
# : Sets the line number is `self`.
|
422
|
+
# You can write to an IO stream line-by-line using this method:
|
495
423
|
#
|
496
|
-
#
|
497
|
-
# : Returns the current byte offset in `self`.
|
424
|
+
# * IO#puts: Writes objects to the stream.
|
498
425
|
#
|
499
|
-
#
|
500
|
-
# : Sets the byte offset in `self`.
|
426
|
+
# ## Character IO
|
501
427
|
#
|
502
|
-
#
|
503
|
-
# : Reassociates `self` with a new or existing IO stream.
|
428
|
+
# You can process an IO stream character-by-character using these methods:
|
504
429
|
#
|
505
|
-
#
|
506
|
-
# :
|
430
|
+
# * IO#getc: Reads and returns the next character from the stream.
|
431
|
+
# * IO#readchar: Like #getc, but raises an exception at end-of-stream.
|
432
|
+
# * IO#ungetc: Pushes back ("unshifts") a character or integer onto the
|
433
|
+
# stream.
|
434
|
+
# * IO#putc: Writes a character to the stream.
|
435
|
+
# * IO#each_char: Reads each remaining character in the stream, passing the
|
436
|
+
# character to the given block.
|
507
437
|
#
|
508
|
-
#
|
509
|
-
# : Sets the offset for `self` relative to given position.
|
438
|
+
# ## Byte IO
|
510
439
|
#
|
440
|
+
# You can process an IO stream byte-by-byte using these methods:
|
511
441
|
#
|
442
|
+
# * IO#getbyte: Returns the next 8-bit byte as an integer in range 0..255.
|
443
|
+
# * IO#readbyte: Like #getbyte, but raises an exception if at end-of-stream.
|
444
|
+
# * IO#ungetbyte: Pushes back ("unshifts") a byte back onto the stream.
|
445
|
+
# * IO#each_byte: Reads each remaining byte in the stream, passing the byte to
|
446
|
+
# the given block.
|
512
447
|
#
|
513
|
-
#
|
448
|
+
# ## Codepoint IO
|
514
449
|
#
|
515
|
-
#
|
516
|
-
# : Yields each line of given file to the block.
|
450
|
+
# You can process an IO stream codepoint-by-codepoint:
|
517
451
|
#
|
518
|
-
#
|
519
|
-
#
|
452
|
+
# * IO#each_codepoint: Reads each remaining codepoint, passing it to the given
|
453
|
+
# block.
|
520
454
|
#
|
521
|
-
#
|
522
|
-
# : Calls the given block with each successive byte in `self` as an
|
523
|
-
# integer.
|
455
|
+
# ## What's Here
|
524
456
|
#
|
525
|
-
#
|
526
|
-
# : Calls the given block with each successive character in `self` as a
|
527
|
-
# string.
|
457
|
+
# First, what's elsewhere. Class IO:
|
528
458
|
#
|
529
|
-
#
|
530
|
-
#
|
531
|
-
#
|
459
|
+
# * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
|
460
|
+
# * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
|
461
|
+
# provides dozens of additional methods.
|
532
462
|
#
|
463
|
+
# Here, class IO provides methods that are useful for:
|
533
464
|
#
|
465
|
+
# * [Creating](rdoc-ref:IO@Creating)
|
466
|
+
# * [Reading](rdoc-ref:IO@Reading)
|
467
|
+
# * [Writing](rdoc-ref:IO@Writing)
|
468
|
+
# * [Positioning](rdoc-ref:IO@Positioning)
|
469
|
+
# * [Iterating](rdoc-ref:IO@Iterating)
|
470
|
+
# * [Settings](rdoc-ref:IO@Settings)
|
471
|
+
# * [Querying](rdoc-ref:IO@Querying)
|
472
|
+
# * [Buffering](rdoc-ref:IO@Buffering)
|
473
|
+
# * [Low-Level Access](rdoc-ref:IO@Low-Level+Access)
|
474
|
+
# * [Other](rdoc-ref:IO@Other)
|
534
475
|
#
|
535
|
-
# ###
|
476
|
+
# ### Creating
|
536
477
|
#
|
537
|
-
#
|
538
|
-
#
|
478
|
+
# * ::new (aliased as ::for_fd): Creates and returns a new IO object for the
|
479
|
+
# given integer file descriptor.
|
480
|
+
# * ::open: Creates a new IO object.
|
481
|
+
# * ::pipe: Creates a connected pair of reader and writer IO objects.
|
482
|
+
# * ::popen: Creates an IO object to interact with a subprocess.
|
483
|
+
# * ::select: Selects which given IO instances are ready for reading, writing,
|
484
|
+
# or have pending exceptions.
|
539
485
|
#
|
540
|
-
#
|
541
|
-
# : Sets `self` to binary mode.
|
486
|
+
# ### Reading
|
542
487
|
#
|
543
|
-
#
|
544
|
-
#
|
488
|
+
# * ::binread: Returns a binary string with all or a subset of bytes from the
|
489
|
+
# given file.
|
490
|
+
# * ::read: Returns a string with all or a subset of bytes from the given
|
491
|
+
# file.
|
492
|
+
# * ::readlines: Returns an array of strings, which are the lines from the
|
493
|
+
# given file.
|
494
|
+
# * #getbyte: Returns the next 8-bit byte read from `self` as an integer.
|
495
|
+
# * #getc: Returns the next character read from `self` as a string.
|
496
|
+
# * #gets: Returns the line read from `self`.
|
497
|
+
# * #pread: Returns all or the next *n* bytes read from `self`, not updating
|
498
|
+
# the receiver's offset.
|
499
|
+
# * #read: Returns all remaining or the next *n* bytes read from `self` for a
|
500
|
+
# given *n*.
|
501
|
+
# * #read_nonblock: the next *n* bytes read from `self` for a given *n*, in
|
502
|
+
# non-block mode.
|
503
|
+
# * #readbyte: Returns the next byte read from `self`; same as #getbyte, but
|
504
|
+
# raises an exception on end-of-stream.
|
505
|
+
# * #readchar: Returns the next character read from `self`; same as #getc, but
|
506
|
+
# raises an exception on end-of-stream.
|
507
|
+
# * #readline: Returns the next line read from `self`; same as #getline, but
|
508
|
+
# raises an exception of end-of-stream.
|
509
|
+
# * #readlines: Returns an array of all lines read read from `self`.
|
510
|
+
# * #readpartial: Returns up to the given number of bytes from `self`.
|
545
511
|
#
|
546
|
-
#
|
547
|
-
# : Sets the close-on-exec flag.
|
512
|
+
# ### Writing
|
548
513
|
#
|
549
|
-
#
|
550
|
-
#
|
514
|
+
# * ::binwrite: Writes the given string to the file at the given filepath, in
|
515
|
+
# binary mode.
|
516
|
+
# * ::write: Writes the given string to `self`.
|
517
|
+
# * #<<: Appends the given string to `self`.
|
518
|
+
# * #print: Prints last read line or given objects to `self`.
|
519
|
+
# * #printf: Writes to `self` based on the given format string and objects.
|
520
|
+
# * #putc: Writes a character to `self`.
|
521
|
+
# * #puts: Writes lines to `self`, making sure line ends with a newline.
|
522
|
+
# * #pwrite: Writes the given string at the given offset, not updating the
|
523
|
+
# receiver's offset.
|
524
|
+
# * #write: Writes one or more given strings to `self`.
|
525
|
+
# * #write_nonblock: Writes one or more given strings to `self` in
|
526
|
+
# non-blocking mode.
|
551
527
|
#
|
552
|
-
#
|
553
|
-
# : Closes `self` for writing.
|
528
|
+
# ### Positioning
|
554
529
|
#
|
555
|
-
#
|
556
|
-
#
|
530
|
+
# * #lineno: Returns the current line number in `self`.
|
531
|
+
# * #lineno=: Sets the line number is `self`.
|
532
|
+
# * #pos (aliased as #tell): Returns the current byte offset in `self`.
|
533
|
+
# * #pos=: Sets the byte offset in `self`.
|
534
|
+
# * #reopen: Reassociates `self` with a new or existing IO stream.
|
535
|
+
# * #rewind: Positions `self` to the beginning of input.
|
536
|
+
# * #seek: Sets the offset for `self` relative to given position.
|
557
537
|
#
|
558
|
-
#
|
559
|
-
# : Sets the encoding for `self`, based on its Unicode byte-order-mark.
|
538
|
+
# ### Iterating
|
560
539
|
#
|
561
|
-
#
|
562
|
-
#
|
540
|
+
# * ::foreach: Yields each line of given file to the block.
|
541
|
+
# * #each (aliased as #each_line): Calls the given block with each successive
|
542
|
+
# line in `self`.
|
543
|
+
# * #each_byte: Calls the given block with each successive byte in `self` as
|
544
|
+
# an integer.
|
545
|
+
# * #each_char: Calls the given block with each successive character in `self`
|
546
|
+
# as a string.
|
547
|
+
# * #each_codepoint: Calls the given block with each successive codepoint in
|
548
|
+
# `self` as an integer.
|
563
549
|
#
|
550
|
+
# ### Settings
|
564
551
|
#
|
552
|
+
# * #autoclose=: Sets whether `self` auto-closes.
|
553
|
+
# * #binmode: Sets `self` to binary mode.
|
554
|
+
# * #close: Closes `self`.
|
555
|
+
# * #close_on_exec=: Sets the close-on-exec flag.
|
556
|
+
# * #close_read: Closes `self` for reading.
|
557
|
+
# * #close_write: Closes `self` for writing.
|
558
|
+
# * #set_encoding: Sets the encoding for `self`.
|
559
|
+
# * #set_encoding_by_bom: Sets the encoding for `self`, based on its Unicode
|
560
|
+
# byte-order-mark.
|
561
|
+
# * #sync=: Sets the sync-mode to the given value.
|
565
562
|
#
|
566
563
|
# ### Querying
|
567
564
|
#
|
568
|
-
#
|
569
|
-
#
|
570
|
-
#
|
571
|
-
#
|
572
|
-
# :
|
573
|
-
#
|
574
|
-
#
|
575
|
-
# :
|
576
|
-
#
|
577
|
-
#
|
578
|
-
# :
|
579
|
-
#
|
580
|
-
#
|
581
|
-
# :
|
582
|
-
#
|
583
|
-
# #external_encoding
|
584
|
-
# : Returns the external encoding object for `self`.
|
585
|
-
#
|
586
|
-
# #fileno (aliased as #to_i)
|
587
|
-
# : Returns the integer file descriptor for `self`
|
588
|
-
#
|
589
|
-
# #internal_encoding
|
590
|
-
# : Returns the internal encoding object for `self`.
|
591
|
-
#
|
592
|
-
# #pid
|
593
|
-
# : Returns the process ID of a child process associated with `self`, if
|
594
|
-
# `self` was created by ::popen.
|
595
|
-
#
|
596
|
-
# #stat
|
597
|
-
# : Returns the File::Stat object containing status information for
|
598
|
-
# `self`.
|
599
|
-
#
|
600
|
-
# #sync
|
601
|
-
# : Returns whether `self` is in sync-mode.
|
602
|
-
#
|
603
|
-
# #tty (aliased as #isatty)
|
604
|
-
# : Returns whether `self` is a terminal.
|
605
|
-
#
|
606
|
-
#
|
565
|
+
# * #autoclose?: Returns whether `self` auto-closes.
|
566
|
+
# * #binmode?: Returns whether `self` is in binary mode.
|
567
|
+
# * #close_on_exec?: Returns the close-on-exec flag for `self`.
|
568
|
+
# * #closed?: Returns whether `self` is closed.
|
569
|
+
# * #eof? (aliased as #eof): Returns whether `self` is at end-of-stream.
|
570
|
+
# * #external_encoding: Returns the external encoding object for `self`.
|
571
|
+
# * #fileno (aliased as #to_i): Returns the integer file descriptor for `self`
|
572
|
+
# * #internal_encoding: Returns the internal encoding object for `self`.
|
573
|
+
# * #pid: Returns the process ID of a child process associated with `self`, if
|
574
|
+
# `self` was created by ::popen.
|
575
|
+
# * #stat: Returns the File::Stat object containing status information for
|
576
|
+
# `self`.
|
577
|
+
# * #sync: Returns whether `self` is in sync-mode.
|
578
|
+
# * #tty? (aliased as #isatty): Returns whether `self` is a terminal.
|
607
579
|
#
|
608
580
|
# ### Buffering
|
609
581
|
#
|
610
|
-
#
|
611
|
-
# :
|
612
|
-
#
|
613
|
-
#
|
614
|
-
#
|
615
|
-
#
|
616
|
-
#
|
617
|
-
# #fsync
|
618
|
-
# : Immediately writes all buffered data and attributes in `self` to disk.
|
619
|
-
#
|
620
|
-
# #ungetbyte
|
621
|
-
# : Prepends buffer for `self` with given integer byte or string.
|
622
|
-
#
|
623
|
-
# #ungetc
|
624
|
-
# : Prepends buffer for `self` with given string.
|
625
|
-
#
|
626
|
-
#
|
582
|
+
# * #fdatasync: Immediately writes all buffered data in `self` to disk.
|
583
|
+
# * #flush: Flushes any buffered data within `self` to the underlying
|
584
|
+
# operating system.
|
585
|
+
# * #fsync: Immediately writes all buffered data and attributes in `self` to
|
586
|
+
# disk.
|
587
|
+
# * #ungetbyte: Prepends buffer for `self` with given integer byte or string.
|
588
|
+
# * #ungetc: Prepends buffer for `self` with given string.
|
627
589
|
#
|
628
590
|
# ### Low-Level Access
|
629
591
|
#
|
630
|
-
#
|
631
|
-
#
|
632
|
-
#
|
633
|
-
#
|
634
|
-
#
|
635
|
-
#
|
636
|
-
#
|
637
|
-
#
|
638
|
-
# :
|
639
|
-
#
|
640
|
-
#
|
641
|
-
#
|
642
|
-
# : Passes a low-level command to the device specified by the given file
|
643
|
-
# descriptor.
|
644
|
-
#
|
645
|
-
# #sysread
|
646
|
-
# : Returns up to the next *n* bytes read from self using a low-level
|
647
|
-
# read.
|
648
|
-
#
|
649
|
-
# #sysseek
|
650
|
-
# : Sets the offset for `self`.
|
651
|
-
#
|
652
|
-
# #syswrite
|
653
|
-
# : Writes the given string to `self` using a low-level write.
|
654
|
-
#
|
655
|
-
#
|
592
|
+
# * ::sysopen: Opens the file given by its path, returning the integer file
|
593
|
+
# descriptor.
|
594
|
+
# * #advise: Announces the intention to access data from `self` in a specific
|
595
|
+
# way.
|
596
|
+
# * #fcntl: Passes a low-level command to the file specified by the given file
|
597
|
+
# descriptor.
|
598
|
+
# * #ioctl: Passes a low-level command to the device specified by the given
|
599
|
+
# file descriptor.
|
600
|
+
# * #sysread: Returns up to the next *n* bytes read from self using a
|
601
|
+
# low-level read.
|
602
|
+
# * #sysseek: Sets the offset for `self`.
|
603
|
+
# * #syswrite: Writes the given string to `self` using a low-level write.
|
656
604
|
#
|
657
605
|
# ### Other
|
658
606
|
#
|
659
|
-
#
|
660
|
-
#
|
661
|
-
#
|
662
|
-
#
|
663
|
-
#
|
664
|
-
# : Returns a new IO object resulting from converting the given object.
|
665
|
-
#
|
666
|
-
# #inspect
|
667
|
-
# : Returns the string representation of `self`.
|
607
|
+
# * ::copy_stream: Copies data from a source to a destination, each of which
|
608
|
+
# is a filepath or an IO-like object.
|
609
|
+
# * ::try_convert: Returns a new IO object resulting from converting the given
|
610
|
+
# object.
|
611
|
+
# * #inspect: Returns the string representation of `self`.
|
668
612
|
#
|
669
613
|
%a{annotate:rdoc:source:from=io.c}
|
670
614
|
class IO < Object
|
@@ -677,8 +621,8 @@ class IO < Object
|
|
677
621
|
# - self << object -> self
|
678
622
|
# -->
|
679
623
|
# Writes the given `object` to `self`, which must be opened for writing (see
|
680
|
-
# [Modes](
|
681
|
-
# it is converted via method `to_s`:
|
624
|
+
# [Access Modes](rdoc-ref:File@Access+Modes)); returns `self`; if `object` is
|
625
|
+
# not a string, it is converted via method `to_s`:
|
682
626
|
#
|
683
627
|
# $stdout << 'Hello' << ', ' << 'World!' << "\n"
|
684
628
|
# $stdout << 'foo' << :bar << 2 << "\n"
|
@@ -692,56 +636,33 @@ class IO < Object
|
|
692
636
|
|
693
637
|
# <!--
|
694
638
|
# rdoc-file=io.c
|
695
|
-
# -
|
639
|
+
# - advise(advice, offset = 0, len = 0) -> nil
|
696
640
|
# -->
|
697
|
-
#
|
698
|
-
#
|
699
|
-
#
|
700
|
-
#
|
701
|
-
# *advice* is one of the following symbols:
|
641
|
+
# Invokes Posix system call
|
642
|
+
# [posix_fadvise(2)](https://linux.die.net/man/2/posix_fadvise), which announces
|
643
|
+
# an intention to access data from the current file in a particular manner.
|
702
644
|
#
|
703
|
-
#
|
704
|
-
# : No advice to give; the default assumption for an open file.
|
705
|
-
# :sequential
|
706
|
-
# : The data will be accessed sequentially with lower offsets read before
|
707
|
-
# higher ones.
|
708
|
-
# :random
|
709
|
-
# : The data will be accessed in random order.
|
710
|
-
# :willneed
|
711
|
-
# : The data will be accessed in the near future.
|
712
|
-
# :dontneed
|
713
|
-
# : The data will not be accessed in the near future.
|
714
|
-
# :noreuse
|
715
|
-
# : The data will only be accessed once.
|
645
|
+
# The arguments and results are platform-dependent.
|
716
646
|
#
|
647
|
+
# The relevant data is specified by:
|
717
648
|
#
|
718
|
-
# The
|
719
|
-
#
|
649
|
+
# * `offset`: The offset of the first byte of data.
|
650
|
+
# * `len`: The number of bytes to be accessed; if `len` is zero, or is larger
|
651
|
+
# than the number of bytes remaining, all remaining bytes will be accessed.
|
720
652
|
#
|
721
|
-
#
|
722
|
-
# extends for *len* bytes. If *len* is 0, the region ends at the last byte of
|
723
|
-
# the file. By default, both *offset* and *len* are 0, meaning that the advice
|
724
|
-
# applies to the entire file.
|
653
|
+
# Argument `advice` is one of the following symbols:
|
725
654
|
#
|
726
|
-
#
|
655
|
+
# * `:normal`: The application has no advice to give about its access pattern
|
656
|
+
# for the specified data. If no advice is given for an open file, this is
|
657
|
+
# the default assumption.
|
658
|
+
# * `:sequential`: The application expects to access the specified data
|
659
|
+
# sequentially (with lower offsets read before higher ones).
|
660
|
+
# * `:random`: The specified data will be accessed in random order.
|
661
|
+
# * `:noreuse`: The specified data will be accessed only once.
|
662
|
+
# * `:willneed`: The specified data will be accessed in the near future.
|
663
|
+
# * `:dontneed`: The specified data will not be accessed in the near future.
|
727
664
|
#
|
728
|
-
#
|
729
|
-
# : The IO stream is closed.
|
730
|
-
# Errno::EBADF
|
731
|
-
# : The file descriptor of the current file is invalid.
|
732
|
-
# Errno::EINVAL
|
733
|
-
# : An invalid value for *advice* was given.
|
734
|
-
# Errno::ESPIPE
|
735
|
-
# : The file descriptor of the current file refers to a FIFO or pipe. (Linux
|
736
|
-
# raises Errno::EINVAL in this case).
|
737
|
-
# TypeError
|
738
|
-
# : Either *advice* was not a Symbol, or one of the other arguments was not an
|
739
|
-
# Integer.
|
740
|
-
# RangeError
|
741
|
-
# : One of the arguments given was too big/small.
|
742
|
-
#
|
743
|
-
# This list is not exhaustive; other Errno
|
744
|
-
# : exceptions are also possible.
|
665
|
+
# Not implemented on all platforms.
|
745
666
|
#
|
746
667
|
def advise: (:normal | :sequential | :random | :willneed | :dontneed | :noreuse advise, ?Integer offset, ?Integer len) -> nil
|
747
668
|
|
@@ -751,70 +672,90 @@ class IO < Object
|
|
751
672
|
# -->
|
752
673
|
# Sets auto-close flag.
|
753
674
|
#
|
754
|
-
# f = open(
|
755
|
-
# IO.for_fd(f.fileno)
|
756
|
-
# #
|
757
|
-
# f.gets # may cause Errno::EBADF
|
675
|
+
# f = File.open(File::NULL)
|
676
|
+
# IO.for_fd(f.fileno).close
|
677
|
+
# f.gets # raises Errno::EBADF
|
758
678
|
#
|
759
|
-
# f = open(
|
760
|
-
# IO.for_fd(f.fileno)
|
761
|
-
#
|
679
|
+
# f = File.open(File::NULL)
|
680
|
+
# g = IO.for_fd(f.fileno)
|
681
|
+
# g.autoclose = false
|
682
|
+
# g.close
|
762
683
|
# f.gets # won't cause Errno::EBADF
|
763
684
|
#
|
764
|
-
def autoclose=: (boolish) ->
|
685
|
+
def autoclose=: (boolish bool) -> boolish
|
765
686
|
|
766
687
|
# <!--
|
767
688
|
# rdoc-file=io.c
|
768
689
|
# - ios.autoclose? -> true or false
|
769
690
|
# -->
|
770
|
-
# Returns `true` if the underlying file descriptor of *ios* will be closed
|
771
|
-
#
|
691
|
+
# Returns `true` if the underlying file descriptor of *ios* will be closed at
|
692
|
+
# its finalization or at calling #close, otherwise `false`.
|
772
693
|
#
|
773
694
|
def autoclose?: () -> bool
|
774
695
|
|
775
696
|
# <!--
|
776
697
|
# rdoc-file=io.c
|
777
|
-
# -
|
698
|
+
# - binmode -> self
|
778
699
|
# -->
|
779
|
-
#
|
780
|
-
#
|
700
|
+
# Sets the stream's data mode as binary (see [Data
|
701
|
+
# Mode](rdoc-ref:File@Data+Mode)).
|
781
702
|
#
|
782
|
-
#
|
783
|
-
# * encoding conversion disabled
|
784
|
-
# * content is treated as ASCII-8BIT
|
703
|
+
# A stream's data mode may not be changed from binary to text.
|
785
704
|
#
|
786
705
|
def binmode: () -> self
|
787
706
|
|
788
707
|
# <!--
|
789
708
|
# rdoc-file=io.c
|
790
|
-
# -
|
709
|
+
# - binmode? -> true or false
|
791
710
|
# -->
|
792
|
-
# Returns `true` if
|
711
|
+
# Returns `true` if the stream is on binary mode, `false` otherwise. See [Data
|
712
|
+
# Mode](rdoc-ref:File@Data+Mode).
|
793
713
|
#
|
794
714
|
def binmode?: () -> bool
|
795
715
|
|
796
716
|
# <!--
|
797
717
|
# rdoc-file=io.c
|
798
|
-
# -
|
718
|
+
# - close -> nil
|
799
719
|
# -->
|
800
|
-
# Closes
|
801
|
-
#
|
802
|
-
#
|
803
|
-
#
|
720
|
+
# Closes the stream for both reading and writing if open for either or both;
|
721
|
+
# returns `nil`. See [Open and Closed
|
722
|
+
# Streams](rdoc-ref:IO@Open+and+Closed+Streams).
|
723
|
+
#
|
724
|
+
# If the stream is open for writing, flushes any buffered writes to the
|
725
|
+
# operating system before closing.
|
726
|
+
#
|
727
|
+
# If the stream was opened by IO.popen, sets global variable `$?` (child exit
|
728
|
+
# status).
|
729
|
+
#
|
730
|
+
# It is not an error to close an IO object that has already been closed. It just
|
731
|
+
# returns nil.
|
732
|
+
#
|
733
|
+
# Example:
|
734
|
+
#
|
735
|
+
# IO.popen('ruby', 'r+') do |pipe|
|
736
|
+
# puts pipe.closed?
|
737
|
+
# pipe.close
|
738
|
+
# puts $?
|
739
|
+
# puts pipe.closed?
|
740
|
+
# end
|
741
|
+
#
|
742
|
+
# Output:
|
804
743
|
#
|
805
|
-
#
|
744
|
+
# false
|
745
|
+
# pid 13760 exit 0
|
746
|
+
# true
|
806
747
|
#
|
807
|
-
#
|
748
|
+
# Related: IO#close_read, IO#close_write, IO#closed?.
|
808
749
|
#
|
809
|
-
def close: () ->
|
750
|
+
def close: () -> nil
|
810
751
|
|
811
752
|
# <!--
|
812
753
|
# rdoc-file=io.c
|
813
|
-
# -
|
754
|
+
# - self.close_on_exec = bool -> true or false
|
814
755
|
# -->
|
815
756
|
# Sets a close-on-exec flag.
|
816
757
|
#
|
817
|
-
# f = open(
|
758
|
+
# f = File.open(File::NULL)
|
818
759
|
# f.close_on_exec = true
|
819
760
|
# system("cat", "/proc/self/fd/#{f.fileno}") # cat: /proc/self/fd/3: No such file or directory
|
820
761
|
# f.closed? #=> false
|
@@ -825,163 +766,171 @@ class IO < Object
|
|
825
766
|
# (via system() method for example). If you really needs file descriptor
|
826
767
|
# inheritance to child process, use spawn()'s argument such as fd=>fd.
|
827
768
|
#
|
828
|
-
def close_on_exec=: (boolish) ->
|
769
|
+
def close_on_exec=: (boolish bool) -> nil
|
829
770
|
|
830
771
|
# <!--
|
831
772
|
# rdoc-file=io.c
|
832
|
-
# -
|
773
|
+
# - close_on_exec? -> true or false
|
833
774
|
# -->
|
834
|
-
# Returns `true` if
|
775
|
+
# Returns `true` if the stream will be closed on exec, `false` otherwise:
|
835
776
|
#
|
836
|
-
# f = open(
|
837
|
-
# f.close_on_exec?
|
838
|
-
# f.close_on_exec = true
|
839
|
-
# f.close_on_exec? #=> true
|
777
|
+
# f = File.open('t.txt')
|
778
|
+
# f.close_on_exec? # => true
|
840
779
|
# f.close_on_exec = false
|
841
|
-
# f.close_on_exec?
|
780
|
+
# f.close_on_exec? # => false
|
781
|
+
# f.close
|
842
782
|
#
|
843
783
|
def close_on_exec?: () -> bool
|
844
784
|
|
845
785
|
# <!--
|
846
786
|
# rdoc-file=io.c
|
847
|
-
# -
|
787
|
+
# - close_read -> nil
|
848
788
|
# -->
|
849
|
-
# Closes the
|
850
|
-
#
|
851
|
-
# is not duplexed.
|
789
|
+
# Closes the stream for reading if open for reading; returns `nil`. See [Open
|
790
|
+
# and Closed Streams](rdoc-ref:IO@Open+and+Closed+Streams).
|
852
791
|
#
|
853
|
-
#
|
854
|
-
#
|
855
|
-
# f.readlines
|
792
|
+
# If the stream was opened by IO.popen and is also closed for writing, sets
|
793
|
+
# global variable `$?` (child exit status).
|
856
794
|
#
|
857
|
-
#
|
795
|
+
# Example:
|
796
|
+
#
|
797
|
+
# IO.popen('ruby', 'r+') do |pipe|
|
798
|
+
# puts pipe.closed?
|
799
|
+
# pipe.close_write
|
800
|
+
# puts pipe.closed?
|
801
|
+
# pipe.close_read
|
802
|
+
# puts $?
|
803
|
+
# puts pipe.closed?
|
804
|
+
# end
|
805
|
+
#
|
806
|
+
# Output:
|
858
807
|
#
|
859
|
-
#
|
860
|
-
#
|
808
|
+
# false
|
809
|
+
# false
|
810
|
+
# pid 14748 exit 0
|
811
|
+
# true
|
861
812
|
#
|
862
|
-
#
|
813
|
+
# Related: IO#close, IO#close_write, IO#closed?.
|
863
814
|
#
|
864
|
-
def close_read: () ->
|
815
|
+
def close_read: () -> nil
|
865
816
|
|
866
817
|
# <!--
|
867
818
|
# rdoc-file=io.c
|
868
|
-
# -
|
819
|
+
# - close_write -> nil
|
869
820
|
# -->
|
870
|
-
# Closes the
|
871
|
-
#
|
872
|
-
# is not duplexed.
|
821
|
+
# Closes the stream for writing if open for writing; returns `nil`. See [Open
|
822
|
+
# and Closed Streams](rdoc-ref:IO@Open+and+Closed+Streams).
|
873
823
|
#
|
874
|
-
#
|
875
|
-
# f.close_write
|
876
|
-
# f.print "nowhere"
|
824
|
+
# Flushes any buffered writes to the operating system before closing.
|
877
825
|
#
|
878
|
-
#
|
826
|
+
# If the stream was opened by IO.popen and is also closed for reading, sets
|
827
|
+
# global variable `$?` (child exit status).
|
879
828
|
#
|
880
|
-
#
|
881
|
-
#
|
882
|
-
#
|
829
|
+
# IO.popen('ruby', 'r+') do |pipe|
|
830
|
+
# puts pipe.closed?
|
831
|
+
# pipe.close_read
|
832
|
+
# puts pipe.closed?
|
833
|
+
# pipe.close_write
|
834
|
+
# puts $?
|
835
|
+
# puts pipe.closed?
|
836
|
+
# end
|
883
837
|
#
|
884
|
-
#
|
838
|
+
# Output:
|
885
839
|
#
|
886
|
-
|
887
|
-
|
888
|
-
#
|
889
|
-
#
|
890
|
-
# - ios.closed? -> true or false
|
891
|
-
# -->
|
892
|
-
# Returns `true` if *ios* is completely closed (for duplex streams, both reader
|
893
|
-
# and writer), `false` otherwise.
|
840
|
+
# false
|
841
|
+
# false
|
842
|
+
# pid 15044 exit 0
|
843
|
+
# true
|
894
844
|
#
|
895
|
-
#
|
896
|
-
# f.close #=> nil
|
897
|
-
# f.closed? #=> true
|
898
|
-
# f = IO.popen("/bin/sh","r+")
|
899
|
-
# f.close_write #=> nil
|
900
|
-
# f.closed? #=> false
|
901
|
-
# f.close_read #=> nil
|
902
|
-
# f.closed? #=> true
|
845
|
+
# Related: IO#close, IO#close_read, IO#closed?.
|
903
846
|
#
|
904
|
-
def
|
847
|
+
def close_write: () -> nil
|
905
848
|
|
906
849
|
# <!--
|
907
850
|
# rdoc-file=io.c
|
908
|
-
# -
|
909
|
-
# - ios.each(limit [, getline_args]) {|line| block } -> ios
|
910
|
-
# - ios.each(sep, limit [, getline_args]) {|line| block } -> ios
|
911
|
-
# - ios.each(...) -> an_enumerator
|
912
|
-
# - ios.each_line(sep=$/ [, getline_args]) {|line| block } -> ios
|
913
|
-
# - ios.each_line(limit [, getline_args]) {|line| block } -> ios
|
914
|
-
# - ios.each_line(sep, limit [, getline_args]) {|line| block } -> ios
|
915
|
-
# - ios.each_line(...) -> an_enumerator
|
851
|
+
# - closed? -> true or false
|
916
852
|
# -->
|
917
|
-
#
|
918
|
-
#
|
853
|
+
# Returns `true` if the stream is closed for both reading and writing, `false`
|
854
|
+
# otherwise. See [Open and Closed Streams](rdoc-ref:IO@Open+and+Closed+Streams).
|
919
855
|
#
|
920
|
-
#
|
921
|
-
#
|
922
|
-
#
|
923
|
-
#
|
856
|
+
# IO.popen('ruby', 'r+') do |pipe|
|
857
|
+
# puts pipe.closed?
|
858
|
+
# pipe.close_read
|
859
|
+
# puts pipe.closed?
|
860
|
+
# pipe.close_write
|
861
|
+
# puts pipe.closed?
|
862
|
+
# end
|
924
863
|
#
|
925
|
-
#
|
864
|
+
# Output:
|
926
865
|
#
|
927
|
-
#
|
928
|
-
#
|
929
|
-
#
|
930
|
-
# 4: And so on...
|
866
|
+
# false
|
867
|
+
# false
|
868
|
+
# true
|
931
869
|
#
|
932
|
-
#
|
870
|
+
# Related: IO#close_read, IO#close_write, IO#close.
|
933
871
|
#
|
934
|
-
def
|
935
|
-
| (?String sep, ?Integer limit) -> ::Enumerator[String, self]
|
872
|
+
def closed?: () -> bool
|
936
873
|
|
937
874
|
# <!--
|
938
875
|
# rdoc-file=io.c
|
939
|
-
# -
|
940
|
-
# -
|
876
|
+
# - each_byte {|byte| ... } -> self
|
877
|
+
# - each_byte -> enumerator
|
941
878
|
# -->
|
942
|
-
# Calls the given block
|
943
|
-
#
|
944
|
-
# raised.
|
879
|
+
# Calls the given block with each byte (0..255) in the stream; returns `self`.
|
880
|
+
# See [Byte IO](rdoc-ref:IO@Byte+IO).
|
945
881
|
#
|
946
|
-
#
|
882
|
+
# f = File.new('t.rus')
|
883
|
+
# a = []
|
884
|
+
# f.each_byte {|b| a << b }
|
885
|
+
# a # => [209, 130, 208, 181, 209, 129, 209, 130]
|
886
|
+
# f.close
|
947
887
|
#
|
948
|
-
#
|
949
|
-
# checksum = 0
|
950
|
-
# f.each_byte {|x| checksum ^= x } #=> #<File:testfile>
|
951
|
-
# checksum #=> 12
|
888
|
+
# Returns an Enumerator if no block is given.
|
952
889
|
#
|
953
|
-
|
890
|
+
# Related: IO#each_char, IO#each_codepoint.
|
891
|
+
#
|
892
|
+
def each_byte: () { (Integer byte) -> void } -> self
|
954
893
|
| () -> ::Enumerator[Integer, self]
|
955
894
|
|
956
895
|
# <!--
|
957
896
|
# rdoc-file=io.c
|
958
|
-
# -
|
959
|
-
# -
|
897
|
+
# - each_char {|c| ... } -> self
|
898
|
+
# - each_char -> enumerator
|
960
899
|
# -->
|
961
|
-
# Calls the given block
|
962
|
-
#
|
963
|
-
#
|
900
|
+
# Calls the given block with each character in the stream; returns `self`. See
|
901
|
+
# [Character IO](rdoc-ref:IO@Character+IO).
|
902
|
+
#
|
903
|
+
# f = File.new('t.rus')
|
904
|
+
# a = []
|
905
|
+
# f.each_char {|c| a << c.ord }
|
906
|
+
# a # => [1090, 1077, 1089, 1090]
|
907
|
+
# f.close
|
964
908
|
#
|
965
|
-
#
|
909
|
+
# Returns an Enumerator if no block is given.
|
966
910
|
#
|
967
|
-
#
|
968
|
-
# f.each_char {|c| print c, ' ' } #=> #<File:testfile>
|
911
|
+
# Related: IO#each_byte, IO#each_codepoint.
|
969
912
|
#
|
970
|
-
def each_char: () { (String
|
913
|
+
def each_char: () { (String c) -> void } -> self
|
971
914
|
| () -> ::Enumerator[String, self]
|
972
915
|
|
973
916
|
# <!--
|
974
917
|
# rdoc-file=io.c
|
975
|
-
# -
|
976
|
-
# -
|
918
|
+
# - each_codepoint {|c| ... } -> self
|
919
|
+
# - each_codepoint -> enumerator
|
977
920
|
# -->
|
978
|
-
#
|
979
|
-
# as an argument. The stream must be opened for reading or an IOError will be
|
980
|
-
# raised.
|
921
|
+
# Calls the given block with each codepoint in the stream; returns `self`:
|
981
922
|
#
|
982
|
-
#
|
923
|
+
# f = File.new('t.rus')
|
924
|
+
# a = []
|
925
|
+
# f.each_codepoint {|c| a << c }
|
926
|
+
# a # => [1090, 1077, 1089, 1090]
|
927
|
+
# f.close
|
928
|
+
#
|
929
|
+
# Returns an Enumerator if no block is given.
|
930
|
+
#
|
931
|
+
# Related: IO#each_byte, IO#each_char.
|
983
932
|
#
|
984
|
-
def each_codepoint: () { (Integer
|
933
|
+
def each_codepoint: () { (Integer c) -> void } -> self
|
985
934
|
| () -> ::Enumerator[Integer, self]
|
986
935
|
|
987
936
|
# <!--
|
@@ -989,15 +938,16 @@ class IO < Object
|
|
989
938
|
# - eof -> true or false
|
990
939
|
# -->
|
991
940
|
# Returns `true` if the stream is positioned at its end, `false` otherwise; see
|
992
|
-
# [Position](
|
941
|
+
# [Position](rdoc-ref:IO@Position):
|
993
942
|
#
|
994
943
|
# f = File.open('t.txt')
|
995
944
|
# f.eof # => false
|
996
945
|
# f.seek(0, :END) # => 0
|
997
946
|
# f.eof # => true
|
947
|
+
# f.close
|
998
948
|
#
|
999
949
|
# Raises an exception unless the stream is opened for reading; see
|
1000
|
-
# [Mode](
|
950
|
+
# [Mode](rdoc-ref:File@Access+Modes).
|
1001
951
|
#
|
1002
952
|
# If `self` is a stream such as pipe or socket, this method blocks until the
|
1003
953
|
# other end sends some data or closes it:
|
@@ -1017,22 +967,23 @@ class IO < Object
|
|
1017
967
|
# not behave as you intend with IO#eof?, unless you call IO#rewind first (which
|
1018
968
|
# is not available for some streams).
|
1019
969
|
#
|
1020
|
-
# I#eof? is an alias for IO#eof.
|
1021
|
-
#
|
1022
970
|
def eof: () -> bool
|
1023
971
|
|
1024
972
|
# <!--
|
1025
973
|
# rdoc-file=io.c
|
1026
|
-
# -
|
974
|
+
# - fcntl(integer_cmd, argument) -> integer
|
1027
975
|
# -->
|
1028
|
-
#
|
1029
|
-
#
|
1030
|
-
#
|
1031
|
-
#
|
1032
|
-
#
|
1033
|
-
#
|
976
|
+
# Invokes Posix system call [fcntl(2)](https://linux.die.net/man/2/fcntl), which
|
977
|
+
# provides a mechanism for issuing low-level commands to control or query a
|
978
|
+
# file-oriented I/O stream. Arguments and results are platform dependent.
|
979
|
+
#
|
980
|
+
# If `argument` is a number, its value is passed directly; if it is a string, it
|
981
|
+
# is interpreted as a binary sequence of bytes. (Array#pack might be a useful
|
982
|
+
# way to build this string.)
|
1034
983
|
#
|
1035
|
-
|
984
|
+
# Not implemented on all platforms.
|
985
|
+
#
|
986
|
+
def fcntl: (Integer integer_cmd, String | Integer argument) -> Integer
|
1036
987
|
|
1037
988
|
# <!--
|
1038
989
|
# rdoc-file=io.c
|
@@ -1054,8 +1005,7 @@ class IO < Object
|
|
1054
1005
|
# $stdout.fileno # => 1
|
1055
1006
|
# $stderr.fileno # => 2
|
1056
1007
|
# File.open('t.txt').fileno # => 10
|
1057
|
-
#
|
1058
|
-
# IO#to_i is an alias for IO#fileno.
|
1008
|
+
# f.close
|
1059
1009
|
#
|
1060
1010
|
def fileno: () -> Integer
|
1061
1011
|
|
@@ -1086,263 +1036,155 @@ class IO < Object
|
|
1086
1036
|
# * IO#fsync: Ensures both that data is flushed from internal buffers, and
|
1087
1037
|
# that data is written to disk.
|
1088
1038
|
#
|
1089
|
-
#
|
1090
1039
|
# Raises an exception if the operating system does not support `fsync(2)`.
|
1091
1040
|
#
|
1092
1041
|
def fsync: () -> Integer?
|
1093
1042
|
|
1094
1043
|
# <!--
|
1095
1044
|
# rdoc-file=io.c
|
1096
|
-
# -
|
1045
|
+
# - getbyte -> integer or nil
|
1097
1046
|
# -->
|
1098
|
-
#
|
1099
|
-
# of
|
1047
|
+
# Reads and returns the next byte (in range 0..255) from the stream; returns
|
1048
|
+
# `nil` if already at end-of-stream. See [Byte IO](rdoc-ref:IO@Byte+IO).
|
1100
1049
|
#
|
1101
|
-
# f = File.
|
1102
|
-
# f.getbyte
|
1103
|
-
# f.
|
1050
|
+
# f = File.open('t.txt')
|
1051
|
+
# f.getbyte # => 70
|
1052
|
+
# f.close
|
1053
|
+
# f = File.open('t.rus')
|
1054
|
+
# f.getbyte # => 209
|
1055
|
+
# f.close
|
1056
|
+
#
|
1057
|
+
# Related: IO#readbyte (may raise EOFError).
|
1104
1058
|
#
|
1105
1059
|
def getbyte: () -> Integer?
|
1106
1060
|
|
1107
1061
|
# <!--
|
1108
1062
|
# rdoc-file=io.c
|
1109
|
-
# -
|
1063
|
+
# - getc -> character or nil
|
1110
1064
|
# -->
|
1111
|
-
# Reads
|
1112
|
-
#
|
1065
|
+
# Reads and returns the next 1-character string from the stream; returns `nil`
|
1066
|
+
# if already at end-of-stream. See [Character IO](rdoc-ref:IO@Character+IO).
|
1113
1067
|
#
|
1114
|
-
# f = File.
|
1115
|
-
# f.getc
|
1116
|
-
# f.
|
1068
|
+
# f = File.open('t.txt')
|
1069
|
+
# f.getc # => "F"
|
1070
|
+
# f.close
|
1071
|
+
# f = File.open('t.rus')
|
1072
|
+
# f.getc.ord # => 1090
|
1073
|
+
# f.close
|
1074
|
+
#
|
1075
|
+
# Related: IO#readchar (may raise EOFError).
|
1117
1076
|
#
|
1118
1077
|
def getc: () -> String?
|
1119
1078
|
|
1120
1079
|
# <!--
|
1121
1080
|
# rdoc-file=io.c
|
1122
|
-
# - gets(sep = $/,
|
1123
|
-
# - gets(limit,
|
1124
|
-
# - gets(sep, limit,
|
1081
|
+
# - gets(sep = $/, chomp: false) -> string or nil
|
1082
|
+
# - gets(limit, chomp: false) -> string or nil
|
1083
|
+
# - gets(sep, limit, chomp: false) -> string or nil
|
1125
1084
|
# -->
|
1126
|
-
# Reads and returns
|
1085
|
+
# Reads and returns a line from the stream; assigns the return value to `$_`.
|
1086
|
+
# See [Line IO](rdoc-ref:IO@Line+IO).
|
1127
1087
|
#
|
1128
1088
|
# With no arguments given, returns the next line as determined by line separator
|
1129
1089
|
# `$/`, or `nil` if none:
|
1130
1090
|
#
|
1131
1091
|
# f = File.open('t.txt')
|
1132
|
-
# f.gets # => "
|
1133
|
-
# $_ # => "
|
1134
|
-
# f.gets # => "
|
1135
|
-
# f.gets # => "
|
1092
|
+
# f.gets # => "First line\n"
|
1093
|
+
# $_ # => "First line\n"
|
1094
|
+
# f.gets # => "\n"
|
1095
|
+
# f.gets # => "Fourth line\n"
|
1096
|
+
# f.gets # => "Fifth line\n"
|
1136
1097
|
# f.gets # => nil
|
1098
|
+
# f.close
|
1137
1099
|
#
|
1138
|
-
# With string argument `sep` given,
|
1139
|
-
# line
|
1100
|
+
# With only string argument `sep` given, returns the next line as determined by
|
1101
|
+
# line separator `sep`, or `nil` if none; see [Line
|
1102
|
+
# Separator](rdoc-ref:IO@Line+Separator):
|
1140
1103
|
#
|
1141
|
-
# f = File.
|
1142
|
-
# f.gets('
|
1143
|
-
# f.gets('
|
1144
|
-
# f.gets('
|
1145
|
-
# f.gets
|
1146
|
-
# f.
|
1147
|
-
#
|
1148
|
-
# Note two special values for `sep`:
|
1104
|
+
# f = File.new('t.txt')
|
1105
|
+
# f.gets('l') # => "First l"
|
1106
|
+
# f.gets('li') # => "ine\nSecond li"
|
1107
|
+
# f.gets('lin') # => "ne\n\nFourth lin"
|
1108
|
+
# f.gets # => "e\n"
|
1109
|
+
# f.close
|
1149
1110
|
#
|
1150
|
-
#
|
1151
|
-
# * `''` (empty string): The next "paragraph" is read and returned, the
|
1152
|
-
# paragraph separator being two successive line separators.
|
1111
|
+
# The two special values for `sep` are honored:
|
1153
1112
|
#
|
1113
|
+
# f = File.new('t.txt')
|
1114
|
+
# # Get all.
|
1115
|
+
# f.gets(nil) # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
1116
|
+
# f.rewind
|
1117
|
+
# # Get paragraph (up to two line separators).
|
1118
|
+
# f.gets('') # => "First line\nSecond line\n\n"
|
1119
|
+
# f.close
|
1154
1120
|
#
|
1155
|
-
# With integer argument `limit` given,
|
1121
|
+
# With only integer argument `limit` given, limits the number of bytes in the
|
1122
|
+
# line; see [Line Limit](rdoc-ref:IO@Line+Limit):
|
1156
1123
|
#
|
1157
|
-
# # Text with 1-byte characters.
|
1158
|
-
# File.open('t.txt') {|f| f.gets(1) } # => "T"
|
1159
|
-
# File.open('t.txt') {|f| f.gets(2) } # => "Th"
|
1160
|
-
# File.open('t.txt') {|f| f.gets(3) } # => "Thi"
|
1161
|
-
# File.open('t.txt') {|f| f.gets(4) } # => "This"
|
1162
1124
|
# # No more than one line.
|
1163
|
-
# File.open('t.txt') {|f| f.gets(
|
1164
|
-
# File.open('t.txt') {|f| f.gets(
|
1165
|
-
# File.open('t.txt') {|f| f.gets(
|
1166
|
-
#
|
1167
|
-
# # Text with 2-byte characters, which will not be split.
|
1168
|
-
# File.open('t.rus') {|f| f.gets(1).size } # => 1
|
1169
|
-
# File.open('t.rus') {|f| f.gets(2).size } # => 1
|
1170
|
-
# File.open('t.rus') {|f| f.gets(3).size } # => 2
|
1171
|
-
# File.open('t.rus') {|f| f.gets(4).size } # => 2
|
1172
|
-
#
|
1173
|
-
# With arguments `sep` and `limit`, combines the two behaviors above:
|
1174
|
-
#
|
1175
|
-
# * Returns the next line as determined by line separator `sep`, or `nil` if
|
1176
|
-
# none.
|
1177
|
-
# * But returns no more than `limit+1` bytes.
|
1125
|
+
# File.open('t.txt') {|f| f.gets(10) } # => "First line"
|
1126
|
+
# File.open('t.txt') {|f| f.gets(11) } # => "First line\n"
|
1127
|
+
# File.open('t.txt') {|f| f.gets(12) } # => "First line\n"
|
1178
1128
|
#
|
1129
|
+
# With arguments `sep` and `limit` given, combines the two behaviors (see [Line
|
1130
|
+
# Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
|
1179
1131
|
#
|
1180
|
-
#
|
1181
|
-
#
|
1132
|
+
# Optional keyword argument `chomp` specifies whether line separators are to be
|
1133
|
+
# omitted:
|
1182
1134
|
#
|
1183
1135
|
# f = File.open('t.txt')
|
1184
1136
|
# # Chomp the lines.
|
1185
|
-
# f.gets(chomp: true) # => "
|
1186
|
-
# f.gets(chomp: true) # => "
|
1187
|
-
# f.gets(chomp: true) # => "
|
1137
|
+
# f.gets(chomp: true) # => "First line"
|
1138
|
+
# f.gets(chomp: true) # => "Second line"
|
1139
|
+
# f.gets(chomp: true) # => ""
|
1140
|
+
# f.gets(chomp: true) # => "Fourth line"
|
1141
|
+
# f.gets(chomp: true) # => "Fifth line"
|
1188
1142
|
# f.gets(chomp: true) # => nil
|
1143
|
+
# f.close
|
1189
1144
|
#
|
1190
|
-
def gets: (?
|
1145
|
+
def gets: (string? sep, ?int limit, ?chomp: boolish) -> String?
|
1146
|
+
| (?int limit, ?chomp: boolish) -> String?
|
1191
1147
|
|
1192
1148
|
# <!--
|
1193
1149
|
# rdoc-file=io.c
|
1194
|
-
# - IO.new(fd
|
1150
|
+
# - IO.new(fd, mode = 'r', **opts) -> io
|
1195
1151
|
# -->
|
1196
|
-
#
|
1197
|
-
# and `mode` string. `opt` may be used to specify parts of `mode` in a more
|
1198
|
-
# readable fashion. See also IO.sysopen and IO.for_fd.
|
1199
|
-
#
|
1200
|
-
# IO.new is called by various File and IO opening methods such as IO::open,
|
1201
|
-
# Kernel#open, and File::open.
|
1202
|
-
#
|
1203
|
-
# ### Open Mode
|
1204
|
-
#
|
1205
|
-
# When `mode` is an integer it must be combination of the modes defined in
|
1206
|
-
# File::Constants (`File::RDONLY`, `File::WRONLY|File::CREAT`). See the open(2)
|
1207
|
-
# man page for more information.
|
1208
|
-
#
|
1209
|
-
# When `mode` is a string it must be in one of the following forms:
|
1210
|
-
#
|
1211
|
-
# fmode
|
1212
|
-
# fmode ":" ext_enc
|
1213
|
-
# fmode ":" ext_enc ":" int_enc
|
1214
|
-
# fmode ":" "BOM|UTF-*"
|
1215
|
-
#
|
1216
|
-
# `fmode` is an IO open mode string, `ext_enc` is the external encoding for the
|
1217
|
-
# IO and `int_enc` is the internal encoding.
|
1218
|
-
#
|
1219
|
-
# #### IO Open Mode
|
1220
|
-
#
|
1221
|
-
# Ruby allows the following open modes:
|
1222
|
-
#
|
1223
|
-
# "r" Read-only, starts at beginning of file (default mode).
|
1224
|
-
#
|
1225
|
-
# "r+" Read-write, starts at beginning of file.
|
1226
|
-
#
|
1227
|
-
# "w" Write-only, truncates existing file
|
1228
|
-
# to zero length or creates a new file for writing.
|
1229
|
-
#
|
1230
|
-
# "w+" Read-write, truncates existing file to zero length
|
1231
|
-
# or creates a new file for reading and writing.
|
1232
|
-
#
|
1233
|
-
# "a" Write-only, each write call appends data at end of file.
|
1234
|
-
# Creates a new file for writing if file does not exist.
|
1235
|
-
#
|
1236
|
-
# "a+" Read-write, each write call appends data at end of file.
|
1237
|
-
# Creates a new file for reading and writing if file does
|
1238
|
-
# not exist.
|
1239
|
-
#
|
1240
|
-
# The following modes must be used separately, and along with one or more of the
|
1241
|
-
# modes seen above.
|
1242
|
-
#
|
1243
|
-
# "b" Binary file mode
|
1244
|
-
# Suppresses EOL <-> CRLF conversion on Windows. And
|
1245
|
-
# sets external encoding to ASCII-8BIT unless explicitly
|
1246
|
-
# specified.
|
1247
|
-
#
|
1248
|
-
# "t" Text file mode
|
1249
|
-
#
|
1250
|
-
# The exclusive access mode ("x") can be used together with "w" to ensure the
|
1251
|
-
# file is created. Errno::EEXIST is raised when it already exists. It may not be
|
1252
|
-
# supported with all kinds of streams (e.g. pipes).
|
1253
|
-
#
|
1254
|
-
# When the open mode of original IO is read only, the mode cannot be changed to
|
1255
|
-
# be writable. Similarly, the open mode cannot be changed from write only to
|
1256
|
-
# readable.
|
1257
|
-
#
|
1258
|
-
# When such a change is attempted the error is raised in different locations
|
1259
|
-
# according to the platform.
|
1260
|
-
#
|
1261
|
-
# ### IO Encoding
|
1262
|
-
#
|
1263
|
-
# When `ext_enc` is specified, strings read will be tagged by the encoding when
|
1264
|
-
# reading, and strings output will be converted to the specified encoding when
|
1265
|
-
# writing.
|
1266
|
-
#
|
1267
|
-
# When `ext_enc` and `int_enc` are specified read strings will be converted from
|
1268
|
-
# `ext_enc` to `int_enc` upon input, and written strings will be converted from
|
1269
|
-
# `int_enc` to `ext_enc` upon output. See Encoding for further details of
|
1270
|
-
# transcoding on input and output.
|
1271
|
-
#
|
1272
|
-
# If "BOM|UTF-8", "BOM|UTF-16LE" or "BOM|UTF16-BE" are used, Ruby checks for a
|
1273
|
-
# Unicode BOM in the input document to help determine the encoding. For UTF-16
|
1274
|
-
# encodings the file open mode must be binary. When present, the BOM is
|
1275
|
-
# stripped and the external encoding from the BOM is used. When the BOM is
|
1276
|
-
# missing the given Unicode encoding is used as `ext_enc`. (The BOM-set
|
1277
|
-
# encoding option is case insensitive, so "bom|utf-8" is also valid.)
|
1278
|
-
#
|
1279
|
-
# ### Options
|
1280
|
-
#
|
1281
|
-
# `opt` can be used instead of `mode` for improved readability. The following
|
1282
|
-
# keys are supported:
|
1283
|
-
#
|
1284
|
-
# :mode
|
1285
|
-
# : Same as `mode` parameter
|
1286
|
-
#
|
1287
|
-
# :flags
|
1288
|
-
# : Specifies file open flags as integer. If `mode` parameter is given, this
|
1289
|
-
# parameter will be bitwise-ORed.
|
1290
|
-
#
|
1291
|
-
# :external_encoding
|
1292
|
-
# : External encoding for the IO.
|
1293
|
-
#
|
1294
|
-
# :internal_encoding
|
1295
|
-
# : Internal encoding for the IO. "-" is a synonym for the default internal
|
1296
|
-
# encoding.
|
1297
|
-
#
|
1298
|
-
# If the value is `nil` no conversion occurs.
|
1299
|
-
#
|
1300
|
-
# :encoding
|
1301
|
-
# : Specifies external and internal encodings as "extern:intern".
|
1302
|
-
#
|
1303
|
-
# :textmode
|
1304
|
-
# : If the value is truth value, same as "t" in argument `mode`.
|
1305
|
-
#
|
1306
|
-
# :binmode
|
1307
|
-
# : If the value is truth value, same as "b" in argument `mode`.
|
1308
|
-
#
|
1309
|
-
# :autoclose
|
1310
|
-
# : If the value is `false`, the `fd` will be kept open after this IO instance
|
1311
|
-
# gets finalized.
|
1152
|
+
# Creates and returns a new IO object (file stream) from a file descriptor.
|
1312
1153
|
#
|
1154
|
+
# IO.new may be useful for interaction with low-level libraries. For
|
1155
|
+
# higher-level interactions, it may be simpler to create the file stream using
|
1156
|
+
# File.open.
|
1313
1157
|
#
|
1314
|
-
#
|
1315
|
-
# between the external encoding and the internal encoding.
|
1158
|
+
# Argument `fd` must be a valid file descriptor (integer):
|
1316
1159
|
#
|
1317
|
-
#
|
1160
|
+
# path = 't.tmp'
|
1161
|
+
# fd = IO.sysopen(path) # => 3
|
1162
|
+
# IO.new(fd) # => #<IO:fd 3>
|
1318
1163
|
#
|
1319
|
-
#
|
1320
|
-
#
|
1321
|
-
# $stderr.puts "Hello"
|
1322
|
-
# a.puts "World"
|
1164
|
+
# The new IO object does not inherit encoding (because the integer file
|
1165
|
+
# descriptor does not have an encoding):
|
1323
1166
|
#
|
1324
|
-
#
|
1167
|
+
# fd = IO.sysopen('t.rus', 'rb')
|
1168
|
+
# io = IO.new(fd)
|
1169
|
+
# io.external_encoding # => #<Encoding:UTF-8> # Not ASCII-8BIT.
|
1325
1170
|
#
|
1326
|
-
#
|
1327
|
-
#
|
1171
|
+
# Optional argument `mode` (defaults to 'r') must specify a valid mode; see
|
1172
|
+
# [Access Modes](rdoc-ref:File@Access+Modes):
|
1328
1173
|
#
|
1329
|
-
#
|
1174
|
+
# IO.new(fd, 'w') # => #<IO:fd 3>
|
1175
|
+
# IO.new(fd, File::WRONLY) # => #<IO:fd 3>
|
1330
1176
|
#
|
1331
|
-
#
|
1177
|
+
# Optional keyword arguments `opts` specify:
|
1332
1178
|
#
|
1333
|
-
#
|
1334
|
-
#
|
1335
|
-
# io.puts "Hello, World!"
|
1179
|
+
# * [Open Options](rdoc-ref:IO@Open+Options).
|
1180
|
+
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
1336
1181
|
#
|
1337
|
-
#
|
1338
|
-
# io = IO.new(fd, mode: 'w', cr_newline: true,
|
1339
|
-
# external_encoding: Encoding::UTF_16LE)
|
1340
|
-
# io.puts "Hello, World!"
|
1182
|
+
# Examples:
|
1341
1183
|
#
|
1342
|
-
#
|
1343
|
-
#
|
1184
|
+
# IO.new(fd, internal_encoding: nil) # => #<IO:fd 3>
|
1185
|
+
# IO.new(fd, autoclose: true) # => #<IO:fd 3>
|
1344
1186
|
#
|
1345
|
-
def initialize: (
|
1187
|
+
def initialize: ( int fd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> void
|
1346
1188
|
|
1347
1189
|
# <!--
|
1348
1190
|
# rdoc-file=io.c
|
@@ -1352,83 +1194,83 @@ class IO < Object
|
|
1352
1194
|
#
|
1353
1195
|
# f = File.open('t.txt')
|
1354
1196
|
# f.inspect # => "#<File:t.txt>"
|
1197
|
+
# f.close
|
1355
1198
|
#
|
1356
1199
|
def inspect: () -> String
|
1357
1200
|
|
1358
1201
|
# <!--
|
1359
1202
|
# rdoc-file=io.c
|
1360
|
-
# -
|
1203
|
+
# - internal_encoding -> encoding or nil
|
1361
1204
|
# -->
|
1362
|
-
# Returns the Encoding
|
1363
|
-
#
|
1205
|
+
# Returns the Encoding object that represents the encoding of the internal
|
1206
|
+
# string, if conversion is specified, or `nil` otherwise.
|
1207
|
+
#
|
1208
|
+
# See [Encodings](rdoc-ref:File@Encodings).
|
1364
1209
|
#
|
1365
1210
|
def internal_encoding: () -> Encoding
|
1366
1211
|
|
1367
1212
|
# <!--
|
1368
1213
|
# rdoc-file=io.c
|
1369
|
-
# -
|
1214
|
+
# - ioctl(integer_cmd, argument) -> integer
|
1370
1215
|
# -->
|
1371
|
-
#
|
1372
|
-
#
|
1373
|
-
#
|
1374
|
-
#
|
1375
|
-
#
|
1216
|
+
# Invokes Posix system call [ioctl(2)](https://linux.die.net/man/2/ioctl), which
|
1217
|
+
# issues a low-level command to an I/O device.
|
1218
|
+
#
|
1219
|
+
# Issues a low-level command to an I/O device. The arguments and returned value
|
1220
|
+
# are platform-dependent. The effect of the call is platform-dependent.
|
1221
|
+
#
|
1222
|
+
# If argument `argument` is an integer, it is passed directly; if it is a
|
1223
|
+
# string, it is interpreted as a binary sequence of bytes.
|
1224
|
+
#
|
1225
|
+
# Not implemented on all platforms.
|
1376
1226
|
#
|
1377
|
-
def ioctl: (Integer integer_cmd, String | Integer
|
1227
|
+
def ioctl: (Integer integer_cmd, String | Integer argument) -> Integer
|
1378
1228
|
|
1379
1229
|
# <!--
|
1380
1230
|
# rdoc-file=io.c
|
1381
|
-
# -
|
1382
|
-
# - ios.tty? -> true or false
|
1231
|
+
# - isatty -> true or false
|
1383
1232
|
# -->
|
1384
|
-
# Returns `true` if
|
1385
|
-
# otherwise
|
1233
|
+
# Returns `true` if the stream is associated with a terminal device (tty),
|
1234
|
+
# `false` otherwise:
|
1386
1235
|
#
|
1387
|
-
# File.new(
|
1388
|
-
#
|
1236
|
+
# f = File.new('t.txt').isatty #=> false
|
1237
|
+
# f.close
|
1238
|
+
# f = File.new('/dev/tty').isatty #=> true
|
1239
|
+
# f.close
|
1389
1240
|
#
|
1390
1241
|
def isatty: () -> bool
|
1391
1242
|
|
1392
1243
|
# <!--
|
1393
1244
|
# rdoc-file=io.c
|
1394
|
-
# -
|
1245
|
+
# - lineno -> integer
|
1395
1246
|
# -->
|
1396
|
-
# Returns the current line number
|
1397
|
-
#
|
1398
|
-
# number of newlines encountered. The two values will differ if #gets is called
|
1399
|
-
# with a separator other than newline.
|
1400
|
-
#
|
1401
|
-
# Methods that use `$/` like #each, #lines and #readline will also increment
|
1402
|
-
# #lineno.
|
1403
|
-
#
|
1404
|
-
# See also the `$.` variable.
|
1405
|
-
#
|
1406
|
-
# f = File.new("testfile")
|
1407
|
-
# f.lineno #=> 0
|
1408
|
-
# f.gets #=> "This is line one\n"
|
1409
|
-
# f.lineno #=> 1
|
1410
|
-
# f.gets #=> "This is line two\n"
|
1411
|
-
# f.lineno #=> 2
|
1247
|
+
# Returns the current line number for the stream; see [Line
|
1248
|
+
# Number](rdoc-ref:IO@Line+Number).
|
1412
1249
|
#
|
1413
1250
|
def lineno: () -> Integer
|
1414
1251
|
|
1415
1252
|
# <!--
|
1416
1253
|
# rdoc-file=io.c
|
1417
|
-
# -
|
1254
|
+
# - lineno = integer -> integer
|
1418
1255
|
# -->
|
1419
|
-
#
|
1420
|
-
#
|
1256
|
+
# Sets and returns the line number for the stream; see [Line
|
1257
|
+
# Number](rdoc-ref:IO@Line+Number).
|
1421
1258
|
#
|
1422
|
-
|
1423
|
-
|
1424
|
-
#
|
1425
|
-
#
|
1426
|
-
#
|
1427
|
-
#
|
1428
|
-
#
|
1429
|
-
#
|
1259
|
+
def lineno=: (Integer integer) -> Integer
|
1260
|
+
|
1261
|
+
# <!--
|
1262
|
+
# rdoc-file=io.c
|
1263
|
+
# - path -> string or nil
|
1264
|
+
# -->
|
1265
|
+
# Returns the path associated with the IO, or `nil` if there is no path
|
1266
|
+
# associated with the IO. It is not guaranteed that the path exists on the
|
1267
|
+
# filesystem.
|
1268
|
+
#
|
1269
|
+
# $stdin.path # => "<STDIN>"
|
1430
1270
|
#
|
1431
|
-
|
1271
|
+
# File.open("testfile") {|f| f.path} # => "testfile"
|
1272
|
+
#
|
1273
|
+
def path: () -> String?
|
1432
1274
|
|
1433
1275
|
# <!--
|
1434
1276
|
# rdoc-file=io.c
|
@@ -1452,123 +1294,164 @@ class IO < Object
|
|
1452
1294
|
#
|
1453
1295
|
def pid: () -> Integer
|
1454
1296
|
|
1455
|
-
# <!-- rdoc-file=io.c -->
|
1456
|
-
# Returns the current position (in bytes) in `self` (see
|
1457
|
-
# [Position](#class-IO-label-Position)):
|
1458
|
-
#
|
1459
|
-
# f = File.new('t.txt')
|
1460
|
-
# f.tell # => 0
|
1461
|
-
# f.readline # => "This is line one.\n"
|
1462
|
-
# f.tell # => 19
|
1463
|
-
#
|
1464
|
-
# Related: IO#pos=, IO#seek.
|
1465
|
-
#
|
1466
|
-
# IO#pos is an alias for IO#tell.
|
1467
|
-
#
|
1468
|
-
def pos: () -> Integer
|
1469
|
-
|
1470
1297
|
# <!--
|
1471
1298
|
# rdoc-file=io.c
|
1472
1299
|
# - pos = new_position -> new_position
|
1473
1300
|
# -->
|
1474
1301
|
# Seeks to the given `new_position` (in bytes); see
|
1475
|
-
# [Position](
|
1302
|
+
# [Position](rdoc-ref:IO@Position):
|
1476
1303
|
#
|
1477
1304
|
# f = File.open('t.txt')
|
1478
1305
|
# f.tell # => 0
|
1479
1306
|
# f.pos = 20 # => 20
|
1480
1307
|
# f.tell # => 20
|
1308
|
+
# f.close
|
1481
1309
|
#
|
1482
1310
|
# Related: IO#seek, IO#tell.
|
1483
1311
|
#
|
1484
|
-
def pos=: (Integer
|
1312
|
+
def pos=: (Integer new_position) -> Integer
|
1485
1313
|
|
1486
1314
|
# <!--
|
1487
1315
|
# rdoc-file=io.c
|
1488
|
-
# -
|
1489
|
-
# - ios.print(obj, ...) -> nil
|
1316
|
+
# - print(*objects) -> nil
|
1490
1317
|
# -->
|
1491
|
-
# Writes the given
|
1318
|
+
# Writes the given objects to the stream; returns `nil`. Appends the output
|
1319
|
+
# record separator `$OUTPUT_RECORD_SEPARATOR` (`$\`), if it is not `nil`. See
|
1320
|
+
# [Line IO](rdoc-ref:IO@Line+IO).
|
1492
1321
|
#
|
1493
|
-
#
|
1494
|
-
# will be converted by calling its `to_s` method. When called without arguments,
|
1495
|
-
# prints the contents of `$_`.
|
1322
|
+
# With argument `objects` given, for each object:
|
1496
1323
|
#
|
1497
|
-
#
|
1498
|
-
#
|
1499
|
-
# the output
|
1324
|
+
# * Converts via its method `to_s` if not a string.
|
1325
|
+
# * Writes to the stream.
|
1326
|
+
# * If not the last object, writes the output field separator
|
1327
|
+
# `$OUTPUT_FIELD_SEPARATOR` (`$,`) if it is not `nil`.
|
1500
1328
|
#
|
1501
|
-
#
|
1329
|
+
# With default separators:
|
1502
1330
|
#
|
1503
|
-
#
|
1331
|
+
# f = File.open('t.tmp', 'w+')
|
1332
|
+
# objects = [0, 0.0, Rational(0, 1), Complex(0, 0), :zero, 'zero']
|
1333
|
+
# p $OUTPUT_RECORD_SEPARATOR
|
1334
|
+
# p $OUTPUT_FIELD_SEPARATOR
|
1335
|
+
# f.print(*objects)
|
1336
|
+
# f.rewind
|
1337
|
+
# p f.read
|
1338
|
+
# f.close
|
1339
|
+
#
|
1340
|
+
# Output:
|
1341
|
+
#
|
1342
|
+
# nil
|
1343
|
+
# nil
|
1344
|
+
# "00.00/10+0izerozero"
|
1504
1345
|
#
|
1505
|
-
#
|
1346
|
+
# With specified separators:
|
1506
1347
|
#
|
1507
|
-
|
1348
|
+
# $\ = "\n"
|
1349
|
+
# $, = ','
|
1350
|
+
# f.rewind
|
1351
|
+
# f.print(*objects)
|
1352
|
+
# f.rewind
|
1353
|
+
# p f.read
|
1354
|
+
#
|
1355
|
+
# Output:
|
1356
|
+
#
|
1357
|
+
# "0,0.0,0/1,0+0i,zero,zero\n"
|
1358
|
+
#
|
1359
|
+
# With no argument given, writes the content of `$_` (which is usually the most
|
1360
|
+
# recent user input):
|
1361
|
+
#
|
1362
|
+
# f = File.open('t.tmp', 'w+')
|
1363
|
+
# gets # Sets $_ to the most recent user input.
|
1364
|
+
# f.print
|
1365
|
+
# f.close
|
1366
|
+
#
|
1367
|
+
def print: (*untyped objects) -> nil
|
1508
1368
|
|
1509
1369
|
# <!--
|
1510
1370
|
# rdoc-file=io.c
|
1511
|
-
# -
|
1371
|
+
# - printf(format_string, *objects) -> nil
|
1512
1372
|
# -->
|
1513
|
-
# Formats and writes to
|
1514
|
-
# string. See Kernel#sprintf for details.
|
1373
|
+
# Formats and writes `objects` to the stream.
|
1515
1374
|
#
|
1516
|
-
|
1375
|
+
# For details on `format_string`, see [Format
|
1376
|
+
# Specifications](rdoc-ref:format_specifications.rdoc).
|
1377
|
+
#
|
1378
|
+
def printf: (String format_string, *untyped objects) -> nil
|
1517
1379
|
|
1518
1380
|
# <!--
|
1519
1381
|
# rdoc-file=io.c
|
1520
|
-
# -
|
1382
|
+
# - putc(object) -> object
|
1521
1383
|
# -->
|
1522
|
-
#
|
1523
|
-
#
|
1524
|
-
#
|
1384
|
+
# Writes a character to the stream. See [Character
|
1385
|
+
# IO](rdoc-ref:IO@Character+IO).
|
1386
|
+
#
|
1387
|
+
# If `object` is numeric, converts to integer if necessary, then writes the
|
1388
|
+
# character whose code is the least significant byte; if `object` is a string,
|
1389
|
+
# writes the first character:
|
1525
1390
|
#
|
1526
1391
|
# $stdout.putc "A"
|
1527
1392
|
# $stdout.putc 65
|
1528
1393
|
#
|
1529
|
-
#
|
1394
|
+
# Output:
|
1530
1395
|
#
|
1531
1396
|
# AA
|
1532
1397
|
#
|
1533
|
-
def putc: (Numeric | String
|
1398
|
+
def putc: (Numeric | String object) -> (Numeric | String)
|
1534
1399
|
|
1535
1400
|
# <!--
|
1536
1401
|
# rdoc-file=io.c
|
1537
|
-
# -
|
1402
|
+
# - puts(*objects) -> nil
|
1538
1403
|
# -->
|
1539
|
-
# Writes the given
|
1540
|
-
#
|
1404
|
+
# Writes the given `objects` to the stream, which must be open for writing;
|
1405
|
+
# returns `nil`.\ Writes a newline after each that does not already end with a
|
1406
|
+
# newline sequence. If called without arguments, writes a newline. See [Line
|
1407
|
+
# IO](rdoc-ref:IO@Line+IO).
|
1541
1408
|
#
|
1542
|
-
#
|
1543
|
-
#
|
1544
|
-
# array will be converted by calling its `to_s` method. If called without
|
1545
|
-
# arguments, outputs a single newline.
|
1409
|
+
# Note that each added newline is the character `"\n"<//tt>, not the output
|
1410
|
+
# record separator (<tt>$\`).
|
1546
1411
|
#
|
1547
|
-
#
|
1412
|
+
# Treatment for each object:
|
1548
1413
|
#
|
1549
|
-
# *
|
1414
|
+
# * String: writes the string.
|
1415
|
+
# * Neither string nor array: writes `object.to_s`.
|
1416
|
+
# * Array: writes each element of the array; arrays may be nested.
|
1417
|
+
#
|
1418
|
+
# To keep these examples brief, we define this helper method:
|
1419
|
+
#
|
1420
|
+
# def show(*objects)
|
1421
|
+
# # Puts objects to file.
|
1422
|
+
# f = File.new('t.tmp', 'w+')
|
1423
|
+
# f.puts(objects)
|
1424
|
+
# # Return file content.
|
1425
|
+
# f.rewind
|
1426
|
+
# p f.read
|
1427
|
+
# f.close
|
1428
|
+
# end
|
1429
|
+
#
|
1430
|
+
# # Strings without newlines.
|
1431
|
+
# show('foo', 'bar', 'baz') # => "foo\nbar\nbaz\n"
|
1432
|
+
# # Strings, some with newlines.
|
1433
|
+
# show("foo\n", 'bar', "baz\n") # => "foo\nbar\nbaz\n"
|
1550
1434
|
#
|
1551
|
-
#
|
1552
|
-
#
|
1553
|
-
#
|
1554
|
-
# test
|
1435
|
+
# # Neither strings nor arrays:
|
1436
|
+
# show(0, 0.0, Rational(0, 1), Complex(9, 0), :zero)
|
1437
|
+
# # => "0\n0.0\n0/1\n9+0i\nzero\n"
|
1555
1438
|
#
|
1556
|
-
#
|
1557
|
-
#
|
1439
|
+
# # Array of strings.
|
1440
|
+
# show(['foo', "bar\n", 'baz']) # => "foo\nbar\nbaz\n"
|
1441
|
+
# # Nested arrays.
|
1442
|
+
# show([[[0, 1], 2, 3], 4, 5]) # => "0\n1\n2\n3\n4\n5\n"
|
1558
1443
|
#
|
1559
|
-
def puts: (*untyped
|
1444
|
+
def puts: (*untyped objects) -> nil
|
1560
1445
|
|
1561
1446
|
# <!--
|
1562
1447
|
# rdoc-file=io.c
|
1563
|
-
# - read(maxlen = nil)
|
1564
|
-
# - read(maxlen = nil, out_string) -> out_string or nil
|
1448
|
+
# - read(maxlen = nil, out_string = nil) -> new_string, out_string, or nil
|
1565
1449
|
# -->
|
1566
|
-
# Reads bytes from the stream
|
1567
|
-
#
|
1568
|
-
# * If `maxlen` is `nil`, reads all bytes.
|
1569
|
-
# * Otherwise reads `maxlen` bytes, if available.
|
1570
|
-
# * Otherwise reads all bytes.
|
1450
|
+
# Reads bytes from the stream; the stream must be opened for reading (see
|
1451
|
+
# [Access Modes](rdoc-ref:File@Access+Modes)):
|
1571
1452
|
#
|
1453
|
+
# * If `maxlen` is `nil`, reads all bytes using the stream's data mode.
|
1454
|
+
# * Otherwise reads up to `maxlen` bytes in binary mode.
|
1572
1455
|
#
|
1573
1456
|
# Returns a string (either a new string or the given `out_string`) containing
|
1574
1457
|
# the bytes read. The encoding of the string depends on both `maxLen` and
|
@@ -1581,19 +1464,18 @@ class IO < Object
|
|
1581
1464
|
# * `out_string` given: encoding of `out_string` not modified.
|
1582
1465
|
# * `out_string` not given: ASCII-8BIT is used.
|
1583
1466
|
#
|
1584
|
-
#
|
1585
|
-
#
|
1586
1467
|
# **Without Argument `out_string`**
|
1587
1468
|
#
|
1588
1469
|
# When argument `out_string` is omitted, the returned value is a new string:
|
1589
1470
|
#
|
1590
1471
|
# f = File.new('t.txt')
|
1591
1472
|
# f.read
|
1592
|
-
# # => "
|
1473
|
+
# # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
1593
1474
|
# f.rewind
|
1594
|
-
# f.read(
|
1595
|
-
# f.read(
|
1596
|
-
# f.read(
|
1475
|
+
# f.read(30) # => "First line\r\nSecond line\r\n\r\nFou"
|
1476
|
+
# f.read(30) # => "rth line\r\nFifth line\r\n"
|
1477
|
+
# f.read(30) # => nil
|
1478
|
+
# f.close
|
1597
1479
|
#
|
1598
1480
|
# If `maxlen` is zero, returns an empty string.
|
1599
1481
|
#
|
@@ -1604,18 +1486,19 @@ class IO < Object
|
|
1604
1486
|
#
|
1605
1487
|
# f = File.new('t.txt')
|
1606
1488
|
# s = 'foo' # => "foo"
|
1607
|
-
# f.read(nil, s) # => "
|
1608
|
-
# s # => "
|
1489
|
+
# f.read(nil, s) # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
1490
|
+
# s # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
1609
1491
|
# f.rewind
|
1610
1492
|
# s = 'bar'
|
1611
|
-
# f.read(
|
1612
|
-
# s # => "
|
1493
|
+
# f.read(30, s) # => "First line\r\nSecond line\r\n\r\nFou"
|
1494
|
+
# s # => "First line\r\nSecond line\r\n\r\nFou"
|
1613
1495
|
# s = 'baz'
|
1614
|
-
# f.read(
|
1615
|
-
# s # => "
|
1496
|
+
# f.read(30, s) # => "rth line\r\nFifth line\r\n"
|
1497
|
+
# s # => "rth line\r\nFifth line\r\n"
|
1616
1498
|
# s = 'bat'
|
1617
|
-
# f.read(
|
1499
|
+
# f.read(30, s) # => nil
|
1618
1500
|
# s # => ""
|
1501
|
+
# f.close
|
1619
1502
|
#
|
1620
1503
|
# Note that this method behaves like the fread() function in C. This means it
|
1621
1504
|
# retries to invoke read(2) system calls to read data with the specified maxlen
|
@@ -1627,7 +1510,10 @@ class IO < Object
|
|
1627
1510
|
# If you need the behavior like a single read(2) system call, consider
|
1628
1511
|
# #readpartial, #read_nonblock, and #sysread.
|
1629
1512
|
#
|
1630
|
-
|
1513
|
+
# Related: IO#write.
|
1514
|
+
#
|
1515
|
+
def read: (?nil, ?string outbuf) -> String
|
1516
|
+
| (int? length, ?string outbuf) -> String?
|
1631
1517
|
|
1632
1518
|
# <!--
|
1633
1519
|
# rdoc-file=io.rb
|
@@ -1687,56 +1573,112 @@ class IO < Object
|
|
1687
1573
|
|
1688
1574
|
# <!--
|
1689
1575
|
# rdoc-file=io.c
|
1690
|
-
# -
|
1576
|
+
# - readbyte -> integer
|
1691
1577
|
# -->
|
1692
|
-
# Reads
|
1578
|
+
# Reads and returns the next byte (in range 0..255) from the stream; raises
|
1579
|
+
# EOFError if already at end-of-stream. See [Byte IO](rdoc-ref:IO@Byte+IO).
|
1580
|
+
#
|
1581
|
+
# f = File.open('t.txt')
|
1582
|
+
# f.readbyte # => 70
|
1583
|
+
# f.close
|
1584
|
+
# f = File.open('t.rus')
|
1585
|
+
# f.readbyte # => 209
|
1586
|
+
# f.close
|
1587
|
+
#
|
1588
|
+
# Related: IO#getbyte (will not raise EOFError).
|
1693
1589
|
#
|
1694
1590
|
def readbyte: () -> Integer
|
1695
1591
|
|
1696
1592
|
# <!--
|
1697
1593
|
# rdoc-file=io.c
|
1698
|
-
# -
|
1594
|
+
# - readchar -> string
|
1699
1595
|
# -->
|
1700
|
-
# Reads
|
1596
|
+
# Reads and returns the next 1-character string from the stream; raises EOFError
|
1597
|
+
# if already at end-of-stream. See [Character IO](rdoc-ref:IO@Character+IO).
|
1701
1598
|
#
|
1702
|
-
# f = File.
|
1703
|
-
# f.readchar
|
1704
|
-
# f.
|
1599
|
+
# f = File.open('t.txt')
|
1600
|
+
# f.readchar # => "F"
|
1601
|
+
# f.close
|
1602
|
+
# f = File.open('t.rus')
|
1603
|
+
# f.readchar.ord # => 1090
|
1604
|
+
# f.close
|
1605
|
+
#
|
1606
|
+
# Related: IO#getc (will not raise EOFError).
|
1705
1607
|
#
|
1706
1608
|
def readchar: () -> String
|
1707
1609
|
|
1708
1610
|
# <!--
|
1709
|
-
# rdoc-file=io.
|
1710
|
-
# -
|
1711
|
-
# -
|
1712
|
-
# -
|
1611
|
+
# rdoc-file=io.rb
|
1612
|
+
# - readline(sep = $/, chomp: false) -> string
|
1613
|
+
# - readline(limit, chomp: false) -> string
|
1614
|
+
# - readline(sep, limit, chomp: false) -> string
|
1713
1615
|
# -->
|
1714
|
-
# Reads a line as with IO#gets, but raises
|
1616
|
+
# Reads a line as with IO#gets, but raises EOFError if already at end-of-stream.
|
1715
1617
|
#
|
1716
|
-
|
1618
|
+
# Optional keyword argument `chomp` specifies whether line separators are to be
|
1619
|
+
# omitted.
|
1620
|
+
#
|
1621
|
+
def readline: (?String sep, ?Integer limit, ?chomp: boolish) -> String
|
1717
1622
|
|
1718
1623
|
# <!--
|
1719
1624
|
# rdoc-file=io.c
|
1720
|
-
# -
|
1721
|
-
# -
|
1722
|
-
# -
|
1625
|
+
# - readlines(sep = $/, chomp: false) -> array
|
1626
|
+
# - readlines(limit, chomp: false) -> array
|
1627
|
+
# - readlines(sep, limit, chomp: false) -> array
|
1723
1628
|
# -->
|
1724
|
-
# Reads
|
1725
|
-
#
|
1726
|
-
# returned as a single record. If the first argument is an integer, or an
|
1727
|
-
# optional second argument is given, the returning string would not be longer
|
1728
|
-
# than the given value in bytes. The stream must be opened for reading or an
|
1729
|
-
# IOError will be raised.
|
1629
|
+
# Reads and returns all remaining line from the stream; does not modify `$_`.
|
1630
|
+
# See [Line IO](rdoc-ref:IO@Line+IO).
|
1730
1631
|
#
|
1731
|
-
#
|
1732
|
-
#
|
1632
|
+
# With no arguments given, returns lines as determined by line separator `$/`,
|
1633
|
+
# or `nil` if none:
|
1634
|
+
#
|
1635
|
+
# f = File.new('t.txt')
|
1636
|
+
# f.readlines
|
1637
|
+
# # => ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
1638
|
+
# f.readlines # => []
|
1639
|
+
# f.close
|
1640
|
+
#
|
1641
|
+
# With only string argument `sep` given, returns lines as determined by line
|
1642
|
+
# separator `sep`, or `nil` if none; see [Line
|
1643
|
+
# Separator](rdoc-ref:IO@Line+Separator):
|
1644
|
+
#
|
1645
|
+
# f = File.new('t.txt')
|
1646
|
+
# f.readlines('li')
|
1647
|
+
# # => ["First li", "ne\nSecond li", "ne\n\nFourth li", "ne\nFifth li", "ne\n"]
|
1648
|
+
# f.close
|
1649
|
+
#
|
1650
|
+
# The two special values for `sep` are honored:
|
1651
|
+
#
|
1652
|
+
# f = File.new('t.txt')
|
1653
|
+
# # Get all into one string.
|
1654
|
+
# f.readlines(nil)
|
1655
|
+
# # => ["First line\nSecond line\n\nFourth line\nFifth line\n"]
|
1656
|
+
# # Get paragraphs (up to two line separators).
|
1657
|
+
# f.rewind
|
1658
|
+
# f.readlines('')
|
1659
|
+
# # => ["First line\nSecond line\n\n", "Fourth line\nFifth line\n"]
|
1660
|
+
# f.close
|
1661
|
+
#
|
1662
|
+
# With only integer argument `limit` given, limits the number of bytes in each
|
1663
|
+
# line; see [Line Limit](rdoc-ref:IO@Line+Limit):
|
1664
|
+
#
|
1665
|
+
# f = File.new('t.txt')
|
1666
|
+
# f.readlines(8)
|
1667
|
+
# # => ["First li", "ne\n", "Second l", "ine\n", "\n", "Fourth l", "ine\n", "Fifth li", "ne\n"]
|
1668
|
+
# f.close
|
1669
|
+
#
|
1670
|
+
# With arguments `sep` and `limit` given, combines the two behaviors (see [Line
|
1671
|
+
# Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
|
1733
1672
|
#
|
1734
|
-
#
|
1735
|
-
#
|
1673
|
+
# Optional keyword argument `chomp` specifies whether line separators are to be
|
1674
|
+
# omitted:
|
1736
1675
|
#
|
1737
|
-
#
|
1676
|
+
# f = File.new('t.txt')
|
1677
|
+
# f.readlines(chomp: true)
|
1678
|
+
# # => ["First line", "Second line", "", "Fourth line", "Fifth line"]
|
1679
|
+
# f.close
|
1738
1680
|
#
|
1739
|
-
def readlines: (?String sep, ?Integer limit) -> ::Array[String]
|
1681
|
+
def readlines: (?String sep, ?Integer limit, ?chomp: boolish) -> ::Array[String]
|
1740
1682
|
|
1741
1683
|
# <!--
|
1742
1684
|
# rdoc-file=io.c
|
@@ -1753,25 +1695,25 @@ class IO < Object
|
|
1753
1695
|
# * Otherwise contains all available bytes, if any available.
|
1754
1696
|
# * Otherwise is an empty string.
|
1755
1697
|
#
|
1756
|
-
#
|
1757
1698
|
# With the single non-negative integer argument `maxlen` given, returns a new
|
1758
1699
|
# string:
|
1759
1700
|
#
|
1760
1701
|
# f = File.new('t.txt')
|
1761
|
-
# f.readpartial(
|
1762
|
-
# f.readpartial(
|
1763
|
-
# f.readpartial(
|
1764
|
-
# f.
|
1765
|
-
# f.
|
1702
|
+
# f.readpartial(20) # => "First line\nSecond l"
|
1703
|
+
# f.readpartial(20) # => "ine\n\nFourth line\n"
|
1704
|
+
# f.readpartial(20) # => "Fifth line\n"
|
1705
|
+
# f.readpartial(20) # Raises EOFError.
|
1706
|
+
# f.close
|
1766
1707
|
#
|
1767
1708
|
# With both argument `maxlen` and string argument `out_string` given, returns
|
1768
1709
|
# modified `out_string`:
|
1769
1710
|
#
|
1770
1711
|
# f = File.new('t.txt')
|
1771
1712
|
# s = 'foo'
|
1772
|
-
# f.readpartial(
|
1713
|
+
# f.readpartial(20, s) # => "First line\nSecond l"
|
1773
1714
|
# s = 'bar'
|
1774
1715
|
# f.readpartial(0, s) # => ""
|
1716
|
+
# f.close
|
1775
1717
|
#
|
1776
1718
|
# This method is useful for a stream such as a pipe, a socket, or a tty. It
|
1777
1719
|
# blocks only when no data is immediately available. This means that it blocks
|
@@ -1781,20 +1723,17 @@ class IO < Object
|
|
1781
1723
|
# * The content of the stream is empty.
|
1782
1724
|
# * The stream is not at EOF.
|
1783
1725
|
#
|
1784
|
-
#
|
1785
1726
|
# When blocked, the method waits for either more data or EOF on the stream:
|
1786
1727
|
#
|
1787
1728
|
# * If more data is read, the method returns the data.
|
1788
1729
|
# * If EOF is reached, the method raises EOFError.
|
1789
1730
|
#
|
1790
|
-
#
|
1791
1731
|
# When not blocked, the method responds immediately:
|
1792
1732
|
#
|
1793
1733
|
# * Returns data from the buffer if there is any.
|
1794
1734
|
# * Otherwise returns data from the stream if there is any.
|
1795
1735
|
# * Otherwise raises EOFError if the stream has reached EOF.
|
1796
1736
|
#
|
1797
|
-
#
|
1798
1737
|
# Note that this method is similar to sysread. The differences are:
|
1799
1738
|
#
|
1800
1739
|
# * If the byte buffer is not empty, read from the byte buffer instead of
|
@@ -1803,7 +1742,6 @@ class IO < Object
|
|
1803
1742
|
# meets EWOULDBLOCK and EINTR by read system call, readpartial retries the
|
1804
1743
|
# system call.
|
1805
1744
|
#
|
1806
|
-
#
|
1807
1745
|
# The latter means that readpartial is non-blocking-flag insensitive. It blocks
|
1808
1746
|
# on the situation IO#sysread causes Errno::EWOULDBLOCK as if the fd is blocking
|
1809
1747
|
# mode.
|
@@ -1835,18 +1773,34 @@ class IO < Object
|
|
1835
1773
|
|
1836
1774
|
# <!--
|
1837
1775
|
# rdoc-file=io.c
|
1838
|
-
# -
|
1839
|
-
# -
|
1776
|
+
# - reopen(other_io) -> self
|
1777
|
+
# - reopen(path, mode = 'r', **opts) -> self
|
1840
1778
|
# -->
|
1841
|
-
# Reassociates
|
1842
|
-
#
|
1843
|
-
#
|
1779
|
+
# Reassociates the stream with another stream, which may be of a different
|
1780
|
+
# class. This method may be used to redirect an existing stream to a new
|
1781
|
+
# destination.
|
1782
|
+
#
|
1783
|
+
# With argument `other_io` given, reassociates with that stream:
|
1784
|
+
#
|
1785
|
+
# # Redirect $stdin from a file.
|
1786
|
+
# f = File.open('t.txt')
|
1787
|
+
# $stdin.reopen(f)
|
1788
|
+
# f.close
|
1789
|
+
#
|
1790
|
+
# # Redirect $stdout to a file.
|
1791
|
+
# f = File.open('t.tmp', 'w')
|
1792
|
+
# $stdout.reopen(f)
|
1793
|
+
# f.close
|
1844
1794
|
#
|
1845
|
-
#
|
1846
|
-
#
|
1847
|
-
#
|
1848
|
-
#
|
1849
|
-
#
|
1795
|
+
# With argument `path` given, reassociates with a new stream to that file path:
|
1796
|
+
#
|
1797
|
+
# $stdin.reopen('t.txt')
|
1798
|
+
# $stdout.reopen('t.tmp', 'w')
|
1799
|
+
#
|
1800
|
+
# Optional keyword arguments `opts` specify:
|
1801
|
+
#
|
1802
|
+
# * [Open Options](rdoc-ref:IO@Open+Options).
|
1803
|
+
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
1850
1804
|
#
|
1851
1805
|
def reopen: (IO other_IO_or_path) -> IO
|
1852
1806
|
| (String other_IO_or_path, ?String mode_str) -> IO
|
@@ -1856,18 +1810,19 @@ class IO < Object
|
|
1856
1810
|
# - rewind -> 0
|
1857
1811
|
# -->
|
1858
1812
|
# Repositions the stream to its beginning, setting both the position and the
|
1859
|
-
# line number to zero; see [Position](
|
1860
|
-
# Number](
|
1813
|
+
# line number to zero; see [Position](rdoc-ref:IO@Position) and [Line
|
1814
|
+
# Number](rdoc-ref:IO@Line+Number):
|
1861
1815
|
#
|
1862
1816
|
# f = File.open('t.txt')
|
1863
1817
|
# f.tell # => 0
|
1864
1818
|
# f.lineno # => 0
|
1865
|
-
# f.
|
1866
|
-
# f.tell # =>
|
1819
|
+
# f.gets # => "First line\n"
|
1820
|
+
# f.tell # => 12
|
1867
1821
|
# f.lineno # => 1
|
1868
1822
|
# f.rewind # => 0
|
1869
1823
|
# f.tell # => 0
|
1870
1824
|
# f.lineno # => 0
|
1825
|
+
# f.close
|
1871
1826
|
#
|
1872
1827
|
# Note that this method cannot be used with streams such as pipes, ttys, and
|
1873
1828
|
# sockets.
|
@@ -1879,7 +1834,7 @@ class IO < Object
|
|
1879
1834
|
# - seek(offset, whence = IO::SEEK_SET) -> 0
|
1880
1835
|
# -->
|
1881
1836
|
# Seeks to the position given by integer `offset` (see
|
1882
|
-
# [Position](
|
1837
|
+
# [Position](rdoc-ref:IO@Position)) and constant `whence`, which is one of:
|
1883
1838
|
#
|
1884
1839
|
# * `:CUR` or `IO::SEEK_CUR`: Repositions the stream to its current position
|
1885
1840
|
# plus the given `offset`:
|
@@ -1890,6 +1845,7 @@ class IO < Object
|
|
1890
1845
|
# f.tell # => 20
|
1891
1846
|
# f.seek(-10, :CUR) # => 0
|
1892
1847
|
# f.tell # => 10
|
1848
|
+
# f.close
|
1893
1849
|
#
|
1894
1850
|
# * `:END` or `IO::SEEK_END`: Repositions the stream to its end plus the given
|
1895
1851
|
# `offset`:
|
@@ -1897,11 +1853,12 @@ class IO < Object
|
|
1897
1853
|
# f = File.open('t.txt')
|
1898
1854
|
# f.tell # => 0
|
1899
1855
|
# f.seek(0, :END) # => 0 # Repositions to stream end.
|
1900
|
-
# f.tell # =>
|
1856
|
+
# f.tell # => 52
|
1901
1857
|
# f.seek(-20, :END) # => 0
|
1902
|
-
# f.tell # =>
|
1858
|
+
# f.tell # => 32
|
1903
1859
|
# f.seek(-40, :END) # => 0
|
1904
|
-
# f.tell # =>
|
1860
|
+
# f.tell # => 12
|
1861
|
+
# f.close
|
1905
1862
|
#
|
1906
1863
|
# * `:SET` or `IO:SEEK_SET`: Repositions the stream to the given `offset`:
|
1907
1864
|
#
|
@@ -1911,7 +1868,7 @@ class IO < Object
|
|
1911
1868
|
# f.tell # => 20
|
1912
1869
|
# f.seek(40, :SET) # => 0
|
1913
1870
|
# f.tell # => 40
|
1914
|
-
#
|
1871
|
+
# f.close
|
1915
1872
|
#
|
1916
1873
|
# Related: IO#pos=, IO#tell.
|
1917
1874
|
#
|
@@ -1919,39 +1876,52 @@ class IO < Object
|
|
1919
1876
|
|
1920
1877
|
# <!--
|
1921
1878
|
# rdoc-file=io.c
|
1922
|
-
# -
|
1923
|
-
# -
|
1924
|
-
# -
|
1925
|
-
# - io.set_encoding("ext_enc:int_enc", opt) -> io
|
1926
|
-
# - io.set_encoding(ext_enc, int_enc, opt) -> io
|
1879
|
+
# - set_encoding(ext_enc) -> self
|
1880
|
+
# - set_encoding(ext_enc, int_enc, **enc_opts) -> self
|
1881
|
+
# - set_encoding('ext_enc:int_enc', **enc_opts) -> self
|
1927
1882
|
# -->
|
1928
|
-
#
|
1929
|
-
#
|
1930
|
-
#
|
1931
|
-
# encoding
|
1932
|
-
#
|
1933
|
-
#
|
1934
|
-
#
|
1935
|
-
#
|
1883
|
+
# See [Encodings](rdoc-ref:File@Encodings).
|
1884
|
+
#
|
1885
|
+
# Argument `ext_enc`, if given, must be an Encoding object or a String with the
|
1886
|
+
# encoding name; it is assigned as the encoding for the stream.
|
1887
|
+
#
|
1888
|
+
# Argument `int_enc`, if given, must be an Encoding object or a String with the
|
1889
|
+
# encoding name; it is assigned as the encoding for the internal string.
|
1890
|
+
#
|
1891
|
+
# Argument `'ext_enc:int_enc'`, if given, is a string containing two
|
1892
|
+
# colon-separated encoding names; corresponding Encoding objects are assigned as
|
1893
|
+
# the external and internal encodings for the stream.
|
1894
|
+
#
|
1895
|
+
# If the external encoding of a string is binary/ASCII-8BIT, the internal
|
1896
|
+
# encoding of the string is set to nil, since no transcoding is needed.
|
1897
|
+
#
|
1898
|
+
# Optional keyword arguments `enc_opts` specify [Encoding
|
1899
|
+
# options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
1936
1900
|
#
|
1937
1901
|
def set_encoding: (?String | Encoding ext_or_ext_int_enc) -> self
|
1938
1902
|
| (?String | Encoding ext_or_ext_int_enc, ?String | Encoding int_enc) -> self
|
1939
1903
|
|
1940
1904
|
# <!--
|
1941
1905
|
# rdoc-file=io.c
|
1942
|
-
# -
|
1906
|
+
# - set_encoding_by_bom -> encoding or nil
|
1943
1907
|
# -->
|
1944
|
-
#
|
1945
|
-
#
|
1946
|
-
#
|
1908
|
+
# If the stream begins with a BOM ([byte order
|
1909
|
+
# marker](https://en.wikipedia.org/wiki/Byte_order_mark)), consumes the BOM and
|
1910
|
+
# sets the external encoding accordingly; returns the result encoding if found,
|
1911
|
+
# or `nil` otherwise:
|
1912
|
+
#
|
1913
|
+
# File.write('t.tmp', "\u{FEFF}abc")
|
1914
|
+
# io = File.open('t.tmp', 'rb')
|
1915
|
+
# io.set_encoding_by_bom # => #<Encoding:UTF-8>
|
1916
|
+
# io.close
|
1947
1917
|
#
|
1948
|
-
# File.write(
|
1949
|
-
#
|
1950
|
-
#
|
1918
|
+
# File.write('t.tmp', 'abc')
|
1919
|
+
# io = File.open('t.tmp', 'rb')
|
1920
|
+
# io.set_encoding_by_bom # => nil
|
1921
|
+
# io.close
|
1951
1922
|
#
|
1952
|
-
#
|
1953
|
-
#
|
1954
|
-
# ios.set_encoding_by_bom #=> nil
|
1923
|
+
# Raises an exception if the stream is not binmode or its encoding has already
|
1924
|
+
# been set.
|
1955
1925
|
#
|
1956
1926
|
def set_encoding_by_bom: () -> Encoding?
|
1957
1927
|
|
@@ -1981,6 +1951,7 @@ class IO < Object
|
|
1981
1951
|
# f.sync # => false
|
1982
1952
|
# f.sync = true
|
1983
1953
|
# f.sync # => true
|
1954
|
+
# f.close
|
1984
1955
|
#
|
1985
1956
|
def sync: () -> bool
|
1986
1957
|
|
@@ -1997,80 +1968,126 @@ class IO < Object
|
|
1997
1968
|
# system and is not buffered internally.
|
1998
1969
|
# * `false`: Output may be buffered internally.
|
1999
1970
|
#
|
2000
|
-
#
|
2001
1971
|
# Example;
|
2002
1972
|
#
|
2003
1973
|
# f = File.open('t.tmp', 'w')
|
2004
1974
|
# f.sync # => false
|
2005
1975
|
# f.sync = true
|
2006
1976
|
# f.sync # => true
|
1977
|
+
# f.close
|
2007
1978
|
#
|
2008
1979
|
# Related: IO#fsync.
|
2009
1980
|
#
|
2010
|
-
def sync=: (boolish) ->
|
1981
|
+
def sync=: (boolish boolean) -> boolish
|
1982
|
+
|
1983
|
+
# <!--
|
1984
|
+
# rdoc-file=io.c
|
1985
|
+
# - sysread(maxlen) -> string
|
1986
|
+
# - sysread(maxlen, out_string) -> string
|
1987
|
+
# -->
|
1988
|
+
# Behaves like IO#readpartial, except that it uses low-level system functions.
|
1989
|
+
#
|
1990
|
+
# This method should not be used with other stream-reader methods.
|
1991
|
+
#
|
1992
|
+
def sysread: (Integer maxlen, String outbuf) -> String
|
1993
|
+
|
1994
|
+
# <!--
|
1995
|
+
# rdoc-file=io.c
|
1996
|
+
# - sysseek(offset, whence = IO::SEEK_SET) -> integer
|
1997
|
+
# -->
|
1998
|
+
# Behaves like IO#seek, except that it:
|
1999
|
+
#
|
2000
|
+
# * Uses low-level system functions.
|
2001
|
+
# * Returns the new position.
|
2002
|
+
#
|
2003
|
+
def sysseek: (Integer amount, ?Integer whence) -> Integer
|
2004
|
+
|
2005
|
+
# <!--
|
2006
|
+
# rdoc-file=io.c
|
2007
|
+
# - syswrite(object) -> integer
|
2008
|
+
# -->
|
2009
|
+
# Writes the given `object` to self, which must be opened for writing (see
|
2010
|
+
# Modes); returns the number bytes written. If `object` is not a string is
|
2011
|
+
# converted via method to_s:
|
2012
|
+
#
|
2013
|
+
# f = File.new('t.tmp', 'w')
|
2014
|
+
# f.syswrite('foo') # => 3
|
2015
|
+
# f.syswrite(30) # => 2
|
2016
|
+
# f.syswrite(:foo) # => 3
|
2017
|
+
# f.close
|
2018
|
+
#
|
2019
|
+
# This methods should not be used with other stream-writer methods.
|
2020
|
+
#
|
2021
|
+
def syswrite: (_ToS object) -> Integer
|
2011
2022
|
|
2012
2023
|
# <!--
|
2013
2024
|
# rdoc-file=io.c
|
2014
|
-
# -
|
2025
|
+
# - tell -> integer
|
2015
2026
|
# -->
|
2016
|
-
#
|
2017
|
-
#
|
2018
|
-
# unpredictable results.
|
2019
|
-
#
|
2020
|
-
# If the optional *outbuf* argument is present, it must reference a String,
|
2021
|
-
# which will receive the data. The *outbuf* will contain only the received data
|
2022
|
-
# after the method call even if it is not empty at the beginning.
|
2027
|
+
# Returns the current position (in bytes) in `self` (see
|
2028
|
+
# [Position](rdoc-ref:IO@Position)):
|
2023
2029
|
#
|
2024
|
-
#
|
2030
|
+
# f = File.open('t.txt')
|
2031
|
+
# f.tell # => 0
|
2032
|
+
# f.gets # => "First line\n"
|
2033
|
+
# f.tell # => 12
|
2034
|
+
# f.close
|
2025
2035
|
#
|
2026
|
-
#
|
2027
|
-
# f.sysread(16) #=> "This is line one"
|
2036
|
+
# Related: IO#pos=, IO#seek.
|
2028
2037
|
#
|
2029
|
-
def
|
2038
|
+
def tell: () -> Integer
|
2030
2039
|
|
2031
|
-
# <!--
|
2032
|
-
#
|
2033
|
-
#
|
2034
|
-
# -->
|
2035
|
-
# Seeks to a given *offset* in the stream according to the value of *whence*
|
2036
|
-
# (see IO#seek for values of *whence*). Returns the new offset into the file.
|
2040
|
+
# <!-- rdoc-file=io.c -->
|
2041
|
+
# Returns the current position (in bytes) in `self` (see
|
2042
|
+
# [Position](rdoc-ref:IO@Position)):
|
2037
2043
|
#
|
2038
|
-
# f = File.
|
2039
|
-
# f.
|
2040
|
-
# f.
|
2044
|
+
# f = File.open('t.txt')
|
2045
|
+
# f.tell # => 0
|
2046
|
+
# f.gets # => "First line\n"
|
2047
|
+
# f.tell # => 12
|
2048
|
+
# f.close
|
2041
2049
|
#
|
2042
|
-
|
2050
|
+
# Related: IO#pos=, IO#seek.
|
2051
|
+
#
|
2052
|
+
alias pos tell
|
2043
2053
|
|
2044
2054
|
# <!--
|
2045
2055
|
# rdoc-file=io.c
|
2046
|
-
# -
|
2056
|
+
# - timeout -> duration or nil
|
2047
2057
|
# -->
|
2048
|
-
#
|
2049
|
-
# of bytes written. Do not mix with other methods that write to *ios* or you may
|
2050
|
-
# get unpredictable results. Raises SystemCallError on error.
|
2058
|
+
# Get the internal timeout duration or nil if it was not set.
|
2051
2059
|
#
|
2052
|
-
|
2053
|
-
|
2060
|
+
def timeout: () -> io_timeout
|
2061
|
+
|
2062
|
+
# The type used for timeouts in `IO`.
|
2054
2063
|
#
|
2055
|
-
|
2064
|
+
# Technically, this type should be `Time::_Timeout?`. However, in the vast majority of use-cases,
|
2065
|
+
# people aren't going to pass their own `_Timeout` in, so `Numeric` is returned for ergonomics
|
2066
|
+
# (eg `io.timeout += 10`).
|
2067
|
+
type io_timeout = Numeric?
|
2056
2068
|
|
2057
2069
|
# <!--
|
2058
2070
|
# rdoc-file=io.c
|
2059
|
-
# -
|
2071
|
+
# - timeout = duration -> duration
|
2072
|
+
# - timeout = nil -> nil
|
2060
2073
|
# -->
|
2061
|
-
#
|
2062
|
-
#
|
2074
|
+
# Sets the internal timeout to the specified duration or nil. The timeout
|
2075
|
+
# applies to all blocking operations where possible.
|
2063
2076
|
#
|
2064
|
-
#
|
2065
|
-
#
|
2066
|
-
# f.readline # => "This is line one.\n"
|
2067
|
-
# f.tell # => 19
|
2077
|
+
# When the operation performs longer than the timeout set, IO::TimeoutError is
|
2078
|
+
# raised.
|
2068
2079
|
#
|
2069
|
-
#
|
2080
|
+
# This affects the following methods (but is not limited to): #gets, #puts,
|
2081
|
+
# #read, #write, #wait_readable and #wait_writable. This also affects blocking
|
2082
|
+
# socket operations like Socket#accept and Socket#connect.
|
2070
2083
|
#
|
2071
|
-
# IO#
|
2084
|
+
# Some operations like File#open and IO#close are not affected by the timeout. A
|
2085
|
+
# timeout during a write operation may leave the IO in an inconsistent state,
|
2086
|
+
# e.g. data was partially written. Generally speaking, a timeout is a last ditch
|
2087
|
+
# effort to prevent an application from hanging on slow I/O operations, such as
|
2088
|
+
# those that occur during a slowloris attack.
|
2072
2089
|
#
|
2073
|
-
def
|
2090
|
+
def timeout=: (io_timeout duration) -> void
|
2074
2091
|
|
2075
2092
|
# <!--
|
2076
2093
|
# rdoc-file=io.c
|
@@ -2081,88 +2098,105 @@ class IO < Object
|
|
2081
2098
|
def to_io: () -> self
|
2082
2099
|
|
2083
2100
|
# <!-- rdoc-file=io.c -->
|
2084
|
-
# Returns `true` if
|
2085
|
-
# otherwise
|
2101
|
+
# Returns `true` if the stream is associated with a terminal device (tty),
|
2102
|
+
# `false` otherwise:
|
2086
2103
|
#
|
2087
|
-
# File.new(
|
2088
|
-
#
|
2104
|
+
# f = File.new('t.txt').isatty #=> false
|
2105
|
+
# f.close
|
2106
|
+
# f = File.new('/dev/tty').isatty #=> true
|
2107
|
+
# f.close
|
2089
2108
|
#
|
2090
|
-
|
2109
|
+
alias tty? isatty
|
2091
2110
|
|
2092
2111
|
# <!--
|
2093
2112
|
# rdoc-file=io.c
|
2094
|
-
# -
|
2095
|
-
# -
|
2113
|
+
# - ungetbyte(integer) -> nil
|
2114
|
+
# - ungetbyte(string) -> nil
|
2096
2115
|
# -->
|
2097
|
-
# Pushes back
|
2098
|
-
#
|
2099
|
-
#
|
2100
|
-
# previous read of at least a single byte from *ios*. However, it can support
|
2101
|
-
# additional bytes if there is space in the internal buffer to allow for it.
|
2116
|
+
# Pushes back ("unshifts") the given data onto the stream's buffer, placing the
|
2117
|
+
# data so that it is next to be read; returns `nil`. See [Byte
|
2118
|
+
# IO](rdoc-ref:IO@Byte+IO).
|
2102
2119
|
#
|
2103
|
-
#
|
2104
|
-
# b = f.getbyte #=> 0x38
|
2105
|
-
# f.ungetbyte(b) #=> nil
|
2106
|
-
# f.getbyte #=> 0x38
|
2120
|
+
# Note that:
|
2107
2121
|
#
|
2108
|
-
#
|
2109
|
-
#
|
2122
|
+
# * Calling the method has no effect with unbuffered reads (such as
|
2123
|
+
# IO#sysread).
|
2124
|
+
# * Calling #rewind on the stream discards the pushed-back data.
|
2110
2125
|
#
|
2111
|
-
#
|
2112
|
-
# f.ungetbyte(0x102) #=> nil
|
2113
|
-
# f.getbyte #=> 0x2
|
2126
|
+
# When argument `integer` is given, uses only its low-order byte:
|
2114
2127
|
#
|
2115
|
-
#
|
2116
|
-
#
|
2128
|
+
# File.write('t.tmp', '012')
|
2129
|
+
# f = File.open('t.tmp')
|
2130
|
+
# f.ungetbyte(0x41) # => nil
|
2131
|
+
# f.read # => "A012"
|
2132
|
+
# f.rewind
|
2133
|
+
# f.ungetbyte(0x4243) # => nil
|
2134
|
+
# f.read # => "C012"
|
2135
|
+
# f.close
|
2117
2136
|
#
|
2118
|
-
#
|
2119
|
-
# f.ungetbyte("ab") #=> nil
|
2120
|
-
# f.ungetbyte("cd") #=> nil
|
2121
|
-
# f.read(5) #=> "cdab8"
|
2137
|
+
# When argument `string` is given, uses all bytes:
|
2122
2138
|
#
|
2123
|
-
#
|
2139
|
+
# File.write('t.tmp', '012')
|
2140
|
+
# f = File.open('t.tmp')
|
2141
|
+
# f.ungetbyte('A') # => nil
|
2142
|
+
# f.read # => "A012"
|
2143
|
+
# f.rewind
|
2144
|
+
# f.ungetbyte('BCDE') # => nil
|
2145
|
+
# f.read # => "BCDE012"
|
2146
|
+
# f.close
|
2124
2147
|
#
|
2125
|
-
def ungetbyte: (String | Integer
|
2148
|
+
def ungetbyte: (String | Integer object) -> nil
|
2126
2149
|
|
2127
2150
|
# <!--
|
2128
2151
|
# rdoc-file=io.c
|
2129
|
-
# -
|
2130
|
-
# -
|
2152
|
+
# - ungetc(integer) -> nil
|
2153
|
+
# - ungetc(string) -> nil
|
2131
2154
|
# -->
|
2132
|
-
# Pushes back
|
2133
|
-
#
|
2134
|
-
#
|
2135
|
-
#
|
2136
|
-
#
|
2137
|
-
# allow for it.
|
2155
|
+
# Pushes back ("unshifts") the given data onto the stream's buffer, placing the
|
2156
|
+
# data so that it is next to be read; returns `nil`. See [Character
|
2157
|
+
# IO](rdoc-ref:IO@Character+IO).
|
2158
|
+
#
|
2159
|
+
# Note that:
|
2138
2160
|
#
|
2139
|
-
#
|
2140
|
-
#
|
2141
|
-
#
|
2142
|
-
# f.getc #=> "8"
|
2161
|
+
# * Calling the method has no effect with unbuffered reads (such as
|
2162
|
+
# IO#sysread).
|
2163
|
+
# * Calling #rewind on the stream discards the pushed-back data.
|
2143
2164
|
#
|
2144
|
-
#
|
2145
|
-
# external encoding of *ios*.
|
2165
|
+
# When argument `integer` is given, interprets the integer as a character:
|
2146
2166
|
#
|
2147
|
-
#
|
2148
|
-
#
|
2167
|
+
# File.write('t.tmp', '012')
|
2168
|
+
# f = File.open('t.tmp')
|
2169
|
+
# f.ungetc(0x41) # => nil
|
2170
|
+
# f.read # => "A012"
|
2171
|
+
# f.rewind
|
2172
|
+
# f.ungetc(0x0442) # => nil
|
2173
|
+
# f.getc.ord # => 1090
|
2174
|
+
# f.close
|
2149
2175
|
#
|
2150
|
-
#
|
2151
|
-
# f.ungetc("ab") #=> nil
|
2152
|
-
# f.ungetc("cd") #=> nil
|
2153
|
-
# f.read(5) #=> "cdab8"
|
2176
|
+
# When argument `string` is given, uses all characters:
|
2154
2177
|
#
|
2155
|
-
#
|
2178
|
+
# File.write('t.tmp', '012')
|
2179
|
+
# f = File.open('t.tmp')
|
2180
|
+
# f.ungetc('A') # => nil
|
2181
|
+
# f.read # => "A012"
|
2182
|
+
# f.rewind
|
2183
|
+
# f.ungetc("\u0442\u0435\u0441\u0442") # => nil
|
2184
|
+
# f.getc.ord # => 1090
|
2185
|
+
# f.getc.ord # => 1077
|
2186
|
+
# f.getc.ord # => 1089
|
2187
|
+
# f.getc.ord # => 1090
|
2188
|
+
# f.close
|
2156
2189
|
#
|
2157
|
-
def ungetc: (String
|
2190
|
+
def ungetc: (String object) -> nil
|
2158
2191
|
|
2159
2192
|
# <!--
|
2160
2193
|
# rdoc-file=io.c
|
2161
2194
|
# - write(*objects) -> integer
|
2162
2195
|
# -->
|
2163
2196
|
# Writes each of the given `objects` to `self`, which must be opened for writing
|
2164
|
-
# (see [Modes](
|
2165
|
-
# each of `objects` that is not a string is converted via method
|
2197
|
+
# (see [Access Modes](rdoc-ref:File@Access+Modes)); returns the total number
|
2198
|
+
# bytes written; each of `objects` that is not a string is converted via method
|
2199
|
+
# `to_s`:
|
2166
2200
|
#
|
2167
2201
|
# $stdout.write('Hello', ', ', 'World!', "\n") # => 14
|
2168
2202
|
# $stdout.write('foo', :bar, 2, "\n") # => 8
|
@@ -2172,6 +2206,8 @@ class IO < Object
|
|
2172
2206
|
# Hello, World!
|
2173
2207
|
# foobar2
|
2174
2208
|
#
|
2209
|
+
# Related: IO#read.
|
2210
|
+
#
|
2175
2211
|
def write: (*_ToS string) -> Integer
|
2176
2212
|
|
2177
2213
|
# <!--
|
@@ -2233,145 +2269,229 @@ class IO < Object
|
|
2233
2269
|
|
2234
2270
|
# <!--
|
2235
2271
|
# rdoc-file=io.c
|
2236
|
-
# - IO.binread(
|
2237
|
-
# - File.binread(name, [length [, offset]]) -> string
|
2272
|
+
# - IO.binread(path, length = nil, offset = 0) -> string or nil
|
2238
2273
|
# -->
|
2239
|
-
#
|
2240
|
-
#
|
2241
|
-
# closed before returning. The open mode would be `"rb:ASCII-8BIT"`.
|
2242
|
-
#
|
2243
|
-
# If `name` starts with a pipe character (`"|"`) and the receiver is the IO
|
2244
|
-
# class, a subprocess is created in the same way as Kernel#open, and its output
|
2245
|
-
# is returned. Consider to use File.binread to disable the behavior of
|
2246
|
-
# subprocess invocation.
|
2274
|
+
# Behaves like IO.read, except that the stream is opened in binary mode with
|
2275
|
+
# ASCII-8BIT encoding.
|
2247
2276
|
#
|
2248
|
-
#
|
2249
|
-
#
|
2250
|
-
#
|
2251
|
-
# IO.binread("| cat testfile") #=> "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
|
2252
|
-
#
|
2253
|
-
# See also IO.read for details about `name` and open_args.
|
2277
|
+
# When called from class IO (but not subclasses of IO), this method has
|
2278
|
+
# potential security vulnerabilities if called with untrusted input; see
|
2279
|
+
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
2254
2280
|
#
|
2255
2281
|
def self.binread: (String name, ?Integer length, ?Integer offset) -> String
|
2256
2282
|
|
2257
2283
|
# <!--
|
2258
2284
|
# rdoc-file=io.c
|
2259
|
-
# - IO.binwrite(
|
2260
|
-
# - IO.binwrite(name, string, [offset], open_args) -> integer
|
2261
|
-
# - File.binwrite(name, string, [offset]) -> integer
|
2262
|
-
# - File.binwrite(name, string, [offset], open_args) -> integer
|
2285
|
+
# - IO.binwrite(path, string, offset = 0) -> integer
|
2263
2286
|
# -->
|
2264
|
-
#
|
2265
|
-
#
|
2266
|
-
#
|
2267
|
-
# If `name` starts with a pipe character (`"|"`) and the receiver is the IO
|
2268
|
-
# class, a subprocess is created in the same way as Kernel#open, and its output
|
2269
|
-
# is returned. Consider to use File.binwrite to disable the behavior of
|
2270
|
-
# subprocess invocation.
|
2287
|
+
# Behaves like IO.write, except that the stream is opened in binary mode with
|
2288
|
+
# ASCII-8BIT encoding.
|
2271
2289
|
#
|
2272
|
-
#
|
2290
|
+
# When called from class IO (but not subclasses of IO), this method has
|
2291
|
+
# potential security vulnerabilities if called with untrusted input; see
|
2292
|
+
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
2273
2293
|
#
|
2274
2294
|
def self.binwrite: (String name, _ToS string, ?Integer offset, ?mode: String mode) -> Integer
|
2275
2295
|
|
2276
2296
|
# <!--
|
2277
2297
|
# rdoc-file=io.c
|
2278
|
-
# - IO.copy_stream(src, dst)
|
2279
|
-
# - IO.copy_stream(src, dst, copy_length)
|
2280
|
-
# - IO.copy_stream(src, dst, copy_length, src_offset)
|
2298
|
+
# - IO.copy_stream(src, dst, src_length = nil, src_offset = 0) -> integer
|
2281
2299
|
# -->
|
2282
|
-
#
|
2283
|
-
#
|
2284
|
-
#
|
2285
|
-
#
|
2286
|
-
#
|
2300
|
+
# Copies from the given `src` to the given `dst`, returning the number of bytes
|
2301
|
+
# copied.
|
2302
|
+
#
|
2303
|
+
# * The given `src` must be one of the following:
|
2304
|
+
#
|
2305
|
+
# * The path to a readable file, from which source data is to be read.
|
2306
|
+
# * An IO-like object, opened for reading and capable of responding to
|
2307
|
+
# method `:readpartial` or method `:read`.
|
2287
2308
|
#
|
2288
|
-
#
|
2309
|
+
# * The given `dst` must be one of the following:
|
2289
2310
|
#
|
2290
|
-
#
|
2291
|
-
#
|
2292
|
-
#
|
2311
|
+
# * The path to a writable file, to which data is to be written.
|
2312
|
+
# * An IO-like object, opened for writing and capable of responding to
|
2313
|
+
# method `:write`.
|
2293
2314
|
#
|
2294
|
-
#
|
2315
|
+
# The examples here use file `t.txt` as source:
|
2295
2316
|
#
|
2296
|
-
#
|
2317
|
+
# File.read('t.txt')
|
2318
|
+
# # => "First line\nSecond line\n\nThird line\nFourth line\n"
|
2319
|
+
# File.read('t.txt').size # => 47
|
2297
2320
|
#
|
2298
|
-
#
|
2299
|
-
#
|
2321
|
+
# If only arguments `src` and `dst` are given, the entire source stream is
|
2322
|
+
# copied:
|
2323
|
+
#
|
2324
|
+
# # Paths.
|
2325
|
+
# IO.copy_stream('t.txt', 't.tmp') # => 47
|
2326
|
+
#
|
2327
|
+
# # IOs (recall that a File is also an IO).
|
2328
|
+
# src_io = File.open('t.txt', 'r') # => #<File:t.txt>
|
2329
|
+
# dst_io = File.open('t.tmp', 'w') # => #<File:t.tmp>
|
2330
|
+
# IO.copy_stream(src_io, dst_io) # => 47
|
2331
|
+
# src_io.close
|
2332
|
+
# dst_io.close
|
2333
|
+
#
|
2334
|
+
# With argument `src_length` a non-negative integer, no more than that many
|
2335
|
+
# bytes are copied:
|
2336
|
+
#
|
2337
|
+
# IO.copy_stream('t.txt', 't.tmp', 10) # => 10
|
2338
|
+
# File.read('t.tmp') # => "First line"
|
2339
|
+
#
|
2340
|
+
# With argument `src_offset` also given, the source stream is read beginning at
|
2341
|
+
# that offset:
|
2342
|
+
#
|
2343
|
+
# IO.copy_stream('t.txt', 't.tmp', 11, 11) # => 11
|
2344
|
+
# IO.read('t.tmp') # => "Second line"
|
2300
2345
|
#
|
2301
2346
|
def self.copy_stream: (String | _Reader | _ReaderPartial src, String | _Writer dst, ?Integer copy_length, ?Integer src_offset) -> Integer
|
2302
2347
|
|
2303
2348
|
# <!--
|
2304
2349
|
# rdoc-file=io.c
|
2305
|
-
# - IO.popen(
|
2306
|
-
# - IO.popen(
|
2350
|
+
# - IO.popen(env = {}, cmd, mode = 'r', **opts) -> io
|
2351
|
+
# - IO.popen(env = {}, cmd, mode = 'r', **opts) {|io| ... } -> object
|
2307
2352
|
# -->
|
2308
|
-
#
|
2309
|
-
#
|
2353
|
+
# Executes the given command `cmd` as a subprocess whose $stdin and $stdout are
|
2354
|
+
# connected to a new stream `io`.
|
2310
2355
|
#
|
2311
|
-
#
|
2356
|
+
# This method has potential security vulnerabilities if called with untrusted
|
2357
|
+
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
2312
2358
|
#
|
2313
|
-
#
|
2359
|
+
# If no block is given, returns the new stream, which depending on given `mode`
|
2360
|
+
# may be open for reading, writing, or both. The stream should be explicitly
|
2361
|
+
# closed (eventually) to avoid resource leaks.
|
2314
2362
|
#
|
2315
|
-
#
|
2316
|
-
#
|
2317
|
-
#
|
2318
|
-
# [env, cmdname, arg1, ..., opts] : command name and zero or more arguments (no shell)
|
2319
|
-
# [env, [cmdname, argv0], arg1, ..., opts] : command name, argv[0] and zero or more arguments (no shell)
|
2320
|
-
# (env and opts are optional.)
|
2363
|
+
# If a block is given, the stream is passed to the block (again, open for
|
2364
|
+
# reading, writing, or both); when the block exits, the stream is closed, and
|
2365
|
+
# the block's value is assigned to global variable `$?` and returned.
|
2321
2366
|
#
|
2322
|
-
#
|
2323
|
-
#
|
2367
|
+
# Optional argument `mode` may be any valid IO mode. See [Access
|
2368
|
+
# Modes](rdoc-ref:File@Access+Modes).
|
2324
2369
|
#
|
2325
|
-
#
|
2326
|
-
# `argv` bypassing a shell. The array can contain a hash at first for
|
2327
|
-
# environments and a hash at last for options similar to #spawn.
|
2370
|
+
# Required argument `cmd` determines which of the following occurs:
|
2328
2371
|
#
|
2329
|
-
# The
|
2330
|
-
#
|
2331
|
-
# *
|
2372
|
+
# * The process forks.
|
2373
|
+
# * A specified program runs in a shell.
|
2374
|
+
# * A specified program runs with specified arguments.
|
2375
|
+
# * A specified program runs with specified arguments and a specified `argv0`.
|
2332
2376
|
#
|
2333
|
-
#
|
2334
|
-
# IO.popen("nkf -e filename", :external_encoding=>"EUC-JP") {|nkf_io|
|
2335
|
-
# euc_jp_string = nkf_io.read
|
2336
|
-
# }
|
2377
|
+
# Each of these is detailed below.
|
2337
2378
|
#
|
2338
|
-
#
|
2339
|
-
#
|
2340
|
-
# IO.popen(["ls", "/", :err=>[:child, :out]]) {|ls_io|
|
2341
|
-
# ls_result_with_error = ls_io.read
|
2342
|
-
# }
|
2379
|
+
# The optional hash argument `env` specifies name/value pairs that are to be
|
2380
|
+
# added to the environment variables for the subprocess:
|
2343
2381
|
#
|
2344
|
-
#
|
2345
|
-
#
|
2346
|
-
#
|
2347
|
-
#
|
2382
|
+
# IO.popen({'FOO' => 'bar'}, 'ruby', 'r+') do |pipe|
|
2383
|
+
# pipe.puts 'puts ENV["FOO"]'
|
2384
|
+
# pipe.close_write
|
2385
|
+
# pipe.gets
|
2386
|
+
# end => "bar\n"
|
2348
2387
|
#
|
2349
|
-
#
|
2388
|
+
# Optional keyword arguments `opts` specify:
|
2350
2389
|
#
|
2351
|
-
#
|
2352
|
-
#
|
2353
|
-
#
|
2354
|
-
# IO.popen returns the value of the block.
|
2390
|
+
# * [Open options](rdoc-ref:IO@Open+Options).
|
2391
|
+
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
2392
|
+
# * Options for Kernel#spawn.
|
2355
2393
|
#
|
2356
|
-
#
|
2357
|
-
# separate processes: once in the parent, and once in a child. The parent
|
2358
|
-
# process will be passed the pipe object as a parameter to the block, the child
|
2359
|
-
# version of the block will be passed `nil`, and the child's standard in and
|
2360
|
-
# standard out will be connected to the parent through the pipe. Not available
|
2361
|
-
# on all platforms.
|
2394
|
+
# **Forked \Process**
|
2362
2395
|
#
|
2363
|
-
#
|
2364
|
-
#
|
2365
|
-
#
|
2366
|
-
#
|
2367
|
-
#
|
2368
|
-
#
|
2369
|
-
#
|
2370
|
-
#
|
2371
|
-
#
|
2396
|
+
# When argument `cmd` is the 1-character string `'-'`, causes the process to
|
2397
|
+
# fork:
|
2398
|
+
# IO.popen('-') do |pipe|
|
2399
|
+
# if pipe
|
2400
|
+
# $stderr.puts "In parent, child pid is #{pipe.pid}\n"
|
2401
|
+
# else
|
2402
|
+
# $stderr.puts "In child, pid is #{$$}\n"
|
2403
|
+
# end
|
2404
|
+
# end
|
2405
|
+
#
|
2406
|
+
# Output:
|
2407
|
+
#
|
2408
|
+
# In parent, child pid is 26253
|
2409
|
+
# In child, pid is 26253
|
2410
|
+
#
|
2411
|
+
# Note that this is not supported on all platforms.
|
2412
|
+
#
|
2413
|
+
# **Shell Subprocess**
|
2414
|
+
#
|
2415
|
+
# When argument `cmd` is a single string (but not `'-'`), the program named
|
2416
|
+
# `cmd` is run as a shell command:
|
2417
|
+
#
|
2418
|
+
# IO.popen('uname') do |pipe|
|
2419
|
+
# pipe.readlines
|
2420
|
+
# end
|
2421
|
+
#
|
2422
|
+
# Output:
|
2423
|
+
#
|
2424
|
+
# ["Linux\n"]
|
2425
|
+
#
|
2426
|
+
# Another example:
|
2427
|
+
#
|
2428
|
+
# IO.popen('/bin/sh', 'r+') do |pipe|
|
2429
|
+
# pipe.puts('ls')
|
2430
|
+
# pipe.close_write
|
2431
|
+
# $stderr.puts pipe.readlines.size
|
2432
|
+
# end
|
2433
|
+
#
|
2434
|
+
# Output:
|
2435
|
+
#
|
2436
|
+
# 213
|
2437
|
+
#
|
2438
|
+
# **Program Subprocess**
|
2439
|
+
#
|
2440
|
+
# When argument `cmd` is an array of strings, the program named `cmd[0]` is run
|
2441
|
+
# with all elements of `cmd` as its arguments:
|
2442
|
+
#
|
2443
|
+
# IO.popen(['du', '..', '.']) do |pipe|
|
2444
|
+
# $stderr.puts pipe.readlines.size
|
2445
|
+
# end
|
2446
|
+
#
|
2447
|
+
# Output:
|
2448
|
+
#
|
2449
|
+
# 1111
|
2450
|
+
#
|
2451
|
+
# **Program Subprocess with `argv0`**
|
2452
|
+
#
|
2453
|
+
# When argument `cmd` is an array whose first element is a 2-element string
|
2454
|
+
# array and whose remaining elements (if any) are strings:
|
2455
|
+
#
|
2456
|
+
# * `cmd[0][0]` (the first string in the nested array) is the name of a
|
2457
|
+
# program that is run.
|
2458
|
+
# * `cmd[0][1]` (the second string in the nested array) is set as the
|
2459
|
+
# program's `argv[0]`.
|
2460
|
+
# * `cmd[1..-1]` (the strings in the outer array) are the program's arguments.
|
2461
|
+
#
|
2462
|
+
# Example (sets `$0` to 'foo'):
|
2463
|
+
#
|
2464
|
+
# IO.popen([['/bin/sh', 'foo'], '-c', 'echo $0']).read # => "foo\n"
|
2465
|
+
#
|
2466
|
+
# **Some Special Examples**
|
2467
|
+
#
|
2468
|
+
# # Set IO encoding.
|
2469
|
+
# IO.popen("nkf -e filename", :external_encoding=>"EUC-JP") {|nkf_io|
|
2470
|
+
# euc_jp_string = nkf_io.read
|
2372
2471
|
# }
|
2373
2472
|
#
|
2374
|
-
#
|
2473
|
+
# # Merge standard output and standard error using Kernel#spawn option. See Kernel#spawn.
|
2474
|
+
# IO.popen(["ls", "/", :err=>[:child, :out]]) do |io|
|
2475
|
+
# ls_result_with_error = io.read
|
2476
|
+
# end
|
2477
|
+
#
|
2478
|
+
# # Use mixture of spawn options and IO options.
|
2479
|
+
# IO.popen(["ls", "/"], :err=>[:child, :out]) do |io|
|
2480
|
+
# ls_result_with_error = io.read
|
2481
|
+
# end
|
2482
|
+
#
|
2483
|
+
# f = IO.popen("uname")
|
2484
|
+
# p f.readlines
|
2485
|
+
# f.close
|
2486
|
+
# puts "Parent is #{Process.pid}"
|
2487
|
+
# IO.popen("date") {|f| puts f.gets }
|
2488
|
+
# IO.popen("-") {|f| $stderr.puts "#{Process.pid} is here, f is #{f.inspect}"}
|
2489
|
+
# p $?
|
2490
|
+
# IO.popen(%w"sed -e s|^|<foo>| -e s&$&;zot;&", "r+") {|f|
|
2491
|
+
# f.puts "bar"; f.close_write; puts f.gets
|
2492
|
+
# }
|
2493
|
+
#
|
2494
|
+
# Output (from last section):
|
2375
2495
|
#
|
2376
2496
|
# ["Linux\n"]
|
2377
2497
|
# Parent is 21346
|
@@ -2381,79 +2501,158 @@ class IO < Object
|
|
2381
2501
|
# #<Process::Status: pid 21352 exit 0>
|
2382
2502
|
# <foo>bar;zot;
|
2383
2503
|
#
|
2384
|
-
|
2504
|
+
# Raises exceptions that IO.pipe and Kernel.spawn raise.
|
2505
|
+
#
|
2506
|
+
def self.popen: (string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: boolish, ?chdir: String) -> instance
|
2507
|
+
| (Hash[string, string?] env, string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: boolish, ?chdir: String) -> instance
|
2508
|
+
| [X] (string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: boolish, ?chdir: String) { (instance) -> X } -> X
|
2509
|
+
| [X] (Hash[string, string?] env, string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: boolish, ?chdir: String) { (instance) -> X } -> X
|
2510
|
+
|
2511
|
+
# The command can be given as:
|
2512
|
+
#
|
2513
|
+
# * Array of string `["ruby", "-v"]`, or
|
2514
|
+
# * Array of string with the first element of array `[["ruby", "RUBY"], "-v"]`
|
2515
|
+
#
|
2516
|
+
# But RBS cannot define such a type. So this is simply a union of `string` or `[String, String]`.
|
2517
|
+
#
|
2518
|
+
type cmd_array = array[string | [String, String]]
|
2385
2519
|
|
2386
2520
|
# <!--
|
2387
2521
|
# rdoc-file=io.c
|
2388
|
-
# - IO.foreach(
|
2389
|
-
# - IO.foreach(
|
2390
|
-
# - IO.foreach(
|
2391
|
-
# - IO.foreach(...)
|
2392
|
-
# - File.foreach(name, sep=$/ [, getline_args, open_args]) {|line| block } -> nil
|
2393
|
-
# - File.foreach(name, limit [, getline_args, open_args]) {|line| block } -> nil
|
2394
|
-
# - File.foreach(name, sep, limit [, getline_args, open_args]) {|line| block } -> nil
|
2395
|
-
# - File.foreach(...) -> an_enumerator
|
2522
|
+
# - IO.foreach(path, sep = $/, **opts) {|line| block } -> nil
|
2523
|
+
# - IO.foreach(path, limit, **opts) {|line| block } -> nil
|
2524
|
+
# - IO.foreach(path, sep, limit, **opts) {|line| block } -> nil
|
2525
|
+
# - IO.foreach(...) -> an_enumerator
|
2396
2526
|
# -->
|
2397
|
-
#
|
2398
|
-
# separated by *sep*.
|
2527
|
+
# Calls the block with each successive line read from the stream.
|
2399
2528
|
#
|
2400
|
-
#
|
2529
|
+
# When called from class IO (but not subclasses of IO), this method has
|
2530
|
+
# potential security vulnerabilities if called with untrusted input; see
|
2531
|
+
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
2401
2532
|
#
|
2402
|
-
#
|
2403
|
-
# class, a subprocess is created in the same way as Kernel#open, and its output
|
2404
|
-
# is returned. Consider to use File.foreach to disable the behavior of
|
2405
|
-
# subprocess invocation.
|
2533
|
+
# The first argument must be a string that is the path to a file.
|
2406
2534
|
#
|
2407
|
-
#
|
2408
|
-
#
|
2535
|
+
# With only argument `path` given, parses lines from the file at the given
|
2536
|
+
# `path`, as determined by the default line separator, and calls the block with
|
2537
|
+
# each successive line:
|
2409
2538
|
#
|
2410
|
-
#
|
2539
|
+
# File.foreach('t.txt') {|line| p line }
|
2540
|
+
#
|
2541
|
+
# Output: the same as above.
|
2542
|
+
#
|
2543
|
+
# For both forms, command and path, the remaining arguments are the same.
|
2544
|
+
#
|
2545
|
+
# With argument `sep` given, parses lines as determined by that line separator
|
2546
|
+
# (see [Line Separator](rdoc-ref:IO@Line+Separator)):
|
2547
|
+
#
|
2548
|
+
# File.foreach('t.txt', 'li') {|line| p line }
|
2411
2549
|
#
|
2412
|
-
#
|
2413
|
-
#
|
2414
|
-
#
|
2415
|
-
#
|
2550
|
+
# Output:
|
2551
|
+
#
|
2552
|
+
# "First li"
|
2553
|
+
# "ne\nSecond li"
|
2554
|
+
# "ne\n\nThird li"
|
2555
|
+
# "ne\nFourth li"
|
2556
|
+
# "ne\n"
|
2557
|
+
#
|
2558
|
+
# Each paragraph:
|
2559
|
+
#
|
2560
|
+
# File.foreach('t.txt', '') {|paragraph| p paragraph }
|
2561
|
+
#
|
2562
|
+
# Output:
|
2563
|
+
#
|
2564
|
+
# "First line\nSecond line\n\n"
|
2565
|
+
# "Third line\nFourth line\n"
|
2566
|
+
#
|
2567
|
+
# With argument `limit` given, parses lines as determined by the default line
|
2568
|
+
# separator and the given line-length limit (see [Line
|
2569
|
+
# Separator](rdoc-ref:IO@Line+Separator) and [Line
|
2570
|
+
# Limit](rdoc-ref:IO@Line+Limit)):
|
2416
2571
|
#
|
2417
|
-
#
|
2418
|
-
# IO.readlines for details about getline_args. And see also IO.read for details
|
2419
|
-
# about open_args.
|
2572
|
+
# File.foreach('t.txt', 7) {|line| p line }
|
2420
2573
|
#
|
2421
|
-
|
2422
|
-
|
2574
|
+
# Output:
|
2575
|
+
#
|
2576
|
+
# "First l"
|
2577
|
+
# "ine\n"
|
2578
|
+
# "Second "
|
2579
|
+
# "line\n"
|
2580
|
+
# "\n"
|
2581
|
+
# "Third l"
|
2582
|
+
# "ine\n"
|
2583
|
+
# "Fourth l"
|
2584
|
+
# "line\n"
|
2585
|
+
#
|
2586
|
+
# With arguments `sep` and `limit` given, combines the two behaviors (see [Line
|
2587
|
+
# Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
|
2588
|
+
#
|
2589
|
+
# Optional keyword arguments `opts` specify:
|
2590
|
+
#
|
2591
|
+
# * [Open Options](rdoc-ref:IO@Open+Options).
|
2592
|
+
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
2593
|
+
# * [Line Options](rdoc-ref:IO@Line+IO).
|
2594
|
+
#
|
2595
|
+
# Returns an Enumerator if no block is given.
|
2596
|
+
#
|
2597
|
+
def self.foreach: (string | _ToPath path, ?String sep, ?Integer limit, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) { (String line) -> void } -> nil
|
2598
|
+
| (string | _ToPath path, ?String sep, ?Integer limit, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) -> ::Enumerator[String, nil]
|
2423
2599
|
|
2424
2600
|
# <!--
|
2425
2601
|
# rdoc-file=io.c
|
2426
|
-
# - IO.pipe
|
2427
|
-
# - IO.pipe(
|
2428
|
-
# - IO.pipe(
|
2429
|
-
# - IO.pipe(
|
2430
|
-
# - IO.pipe(
|
2602
|
+
# - IO.pipe(**opts) -> [read_io, write_io]
|
2603
|
+
# - IO.pipe(enc, **opts) -> [read_io, write_io]
|
2604
|
+
# - IO.pipe(ext_enc, int_enc, **opts) -> [read_io, write_io]
|
2605
|
+
# - IO.pipe(**opts) {|read_io, write_io| ...} -> object
|
2606
|
+
# - IO.pipe(enc, **opts) {|read_io, write_io| ...} -> object
|
2607
|
+
# - IO.pipe(ext_enc, int_enc, **opts) {|read_io, write_io| ...} -> object
|
2431
2608
|
# -->
|
2432
|
-
# Creates a pair of pipe endpoints
|
2433
|
-
#
|
2609
|
+
# Creates a pair of pipe endpoints, `read_io` and `write_io`, connected to each
|
2610
|
+
# other.
|
2434
2611
|
#
|
2435
|
-
# If
|
2436
|
-
# *read_io* and *write_io* are sent to the block as arguments. If read_io and
|
2437
|
-
# write_io are not closed when the block exits, they are closed. i.e. closing
|
2438
|
-
# read_io and/or write_io doesn't cause an error.
|
2612
|
+
# If argument `enc_string` is given, it must be a string containing one of:
|
2439
2613
|
#
|
2440
|
-
#
|
2614
|
+
# * The name of the encoding to be used as the external encoding.
|
2615
|
+
# * The colon-separated names of two encodings to be used as the external and
|
2616
|
+
# internal encodings.
|
2441
2617
|
#
|
2442
|
-
# If
|
2443
|
-
#
|
2444
|
-
#
|
2445
|
-
#
|
2446
|
-
#
|
2447
|
-
#
|
2448
|
-
# encoding,
|
2449
|
-
#
|
2450
|
-
#
|
2618
|
+
# If argument `int_enc` is given, it must be an Encoding object or encoding name
|
2619
|
+
# string that specifies the internal encoding to be used; if argument `ext_enc`
|
2620
|
+
# is also given, it must be an Encoding object or encoding name string that
|
2621
|
+
# specifies the external encoding to be used.
|
2622
|
+
#
|
2623
|
+
# The string read from `read_io` is tagged with the external encoding; if an
|
2624
|
+
# internal encoding is also specified, the string is converted to, and tagged
|
2625
|
+
# with, that encoding.
|
2626
|
+
#
|
2627
|
+
# If any encoding is specified, optional hash arguments specify the conversion
|
2628
|
+
# option.
|
2629
|
+
#
|
2630
|
+
# Optional keyword arguments `opts` specify:
|
2631
|
+
#
|
2632
|
+
# * [Open Options](rdoc-ref:IO@Open+Options).
|
2633
|
+
# * [Encoding Options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
2634
|
+
#
|
2635
|
+
# With no block given, returns the two endpoints in an array:
|
2636
|
+
#
|
2637
|
+
# IO.pipe # => [#<IO:fd 4>, #<IO:fd 5>]
|
2638
|
+
#
|
2639
|
+
# With a block given, calls the block with the two endpoints; closes both
|
2640
|
+
# endpoints and returns the value of the block:
|
2641
|
+
#
|
2642
|
+
# IO.pipe {|read_io, write_io| p read_io; p write_io }
|
2643
|
+
#
|
2644
|
+
# Output:
|
2645
|
+
#
|
2646
|
+
# #<IO:fd 6>
|
2647
|
+
# #<IO:fd 7>
|
2648
|
+
#
|
2649
|
+
# Not available on all platforms.
|
2451
2650
|
#
|
2452
2651
|
# In the example below, the two processes close the ends of the pipe that they
|
2453
2652
|
# are not using. This is not just a cosmetic nicety. The read end of a pipe will
|
2454
2653
|
# not generate an end of file condition if there are any writers with the pipe
|
2455
2654
|
# still open. In the case of the parent process, the `rd.read` will never return
|
2456
|
-
# if it does not first issue a `wr.close
|
2655
|
+
# if it does not first issue a `wr.close`:
|
2457
2656
|
#
|
2458
2657
|
# rd, wr = IO.pipe
|
2459
2658
|
#
|
@@ -2464,7 +2663,7 @@ class IO < Object
|
|
2464
2663
|
# Process.wait
|
2465
2664
|
# else
|
2466
2665
|
# rd.close
|
2467
|
-
# puts
|
2666
|
+
# puts 'Sending message to parent'
|
2468
2667
|
# wr.write "Hi Dad"
|
2469
2668
|
# wr.close
|
2470
2669
|
# end
|
@@ -2474,118 +2673,140 @@ class IO < Object
|
|
2474
2673
|
# Sending message to parent
|
2475
2674
|
# Parent got: <Hi Dad>
|
2476
2675
|
#
|
2477
|
-
def self.pipe: (?String | Encoding ext_or_ext_int_enc, ?String | Encoding int_enc, ?external_encoding: String
|
2478
|
-
| [X] (?String | Encoding ext_or_ext_int_enc, ?String | Encoding int_enc, ?external_encoding: String
|
2676
|
+
def self.pipe: (?String | Encoding | nil ext_or_ext_int_enc, ?String | Encoding | nil int_enc, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) -> [IO, IO]
|
2677
|
+
| [X] (?String | Encoding | nil ext_or_ext_int_enc, ?String | Encoding | nil int_enc, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) { (IO read_io, IO write_io) -> X } -> X
|
2479
2678
|
|
2480
2679
|
# <!--
|
2481
2680
|
# rdoc-file=io.c
|
2482
|
-
# - IO.read(
|
2483
|
-
# - File.read(name, [length [, offset]] [, opt]) -> string
|
2681
|
+
# - IO.read(path, length = nil, offset = 0, **opts) -> string or nil
|
2484
2682
|
# -->
|
2485
|
-
# Opens the
|
2486
|
-
#
|
2487
|
-
# before returning.
|
2488
|
-
#
|
2489
|
-
# If `name` starts with a pipe character (`"|"`) and the receiver is the IO
|
2490
|
-
# class, a subprocess is created in the same way as Kernel#open, and its output
|
2491
|
-
# is returned. Consider to use File.read to disable the behavior of subprocess
|
2492
|
-
# invocation.
|
2683
|
+
# Opens the stream, reads and returns some or all of its content, and closes the
|
2684
|
+
# stream; returns `nil` if no bytes were read.
|
2493
2685
|
#
|
2494
|
-
#
|
2686
|
+
# When called from class IO (but not subclasses of IO), this method has
|
2687
|
+
# potential security vulnerabilities if called with untrusted input; see
|
2688
|
+
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
2495
2689
|
#
|
2496
|
-
# The
|
2690
|
+
# The first argument must be a string that is the path to a file.
|
2497
2691
|
#
|
2498
|
-
#
|
2499
|
-
#
|
2692
|
+
# With only argument `path` given, reads in text mode and returns the entire
|
2693
|
+
# content of the file at the given path:
|
2500
2694
|
#
|
2501
|
-
#
|
2502
|
-
#
|
2695
|
+
# IO.read('t.txt')
|
2696
|
+
# # => "First line\nSecond line\n\nThird line\nFourth line\n"
|
2503
2697
|
#
|
2504
|
-
#
|
2505
|
-
#
|
2698
|
+
# On Windows, text mode can terminate reading and leave bytes in the file unread
|
2699
|
+
# when encountering certain special bytes. Consider using IO.binread if all
|
2700
|
+
# bytes in the file should be read.
|
2506
2701
|
#
|
2507
|
-
#
|
2508
|
-
# otherwise it will cause an error. See IO.new for the list of possible
|
2509
|
-
# modes.
|
2702
|
+
# With argument `length`, returns `length` bytes if available:
|
2510
2703
|
#
|
2511
|
-
#
|
2512
|
-
#
|
2704
|
+
# IO.read('t.txt', 7) # => "First l"
|
2705
|
+
# IO.read('t.txt', 700)
|
2706
|
+
# # => "First line\r\nSecond line\r\n\r\nFourth line\r\nFifth line\r\n"
|
2513
2707
|
#
|
2514
|
-
#
|
2515
|
-
#
|
2708
|
+
# With arguments `length` and `offset`, returns `length` bytes if available,
|
2709
|
+
# beginning at the given `offset`:
|
2516
2710
|
#
|
2711
|
+
# IO.read('t.txt', 10, 2) # => "rst line\nS"
|
2712
|
+
# IO.read('t.txt', 10, 200) # => nil
|
2517
2713
|
#
|
2518
|
-
#
|
2714
|
+
# Optional keyword arguments `opts` specify:
|
2519
2715
|
#
|
2520
|
-
#
|
2521
|
-
#
|
2522
|
-
# File.read("testfile", 20, 10) #=> "ne one\nThis is line "
|
2523
|
-
# File.read("binfile", mode: "rb") #=> "\xF7\x00\x00\x0E\x12"
|
2524
|
-
# IO.read("|ls -a") #=> ".\n..\n"...
|
2716
|
+
# * [Open Options](rdoc-ref:IO@Open+Options).
|
2717
|
+
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
2525
2718
|
#
|
2526
|
-
def self.read: (String name, ?Integer length, ?Integer offset, ?external_encoding: String
|
2719
|
+
def self.read: (String name, ?Integer length, ?Integer offset, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> String
|
2527
2720
|
|
2528
2721
|
# <!--
|
2529
2722
|
# rdoc-file=io.c
|
2530
|
-
# - IO.readlines(
|
2531
|
-
# - IO.readlines(
|
2532
|
-
# - IO.readlines(
|
2533
|
-
# - File.readlines(name, sep=$/ [, getline_args, open_args]) -> array
|
2534
|
-
# - File.readlines(name, limit [, getline_args, open_args]) -> array
|
2535
|
-
# - File.readlines(name, sep, limit [, getline_args, open_args]) -> array
|
2723
|
+
# - IO.readlines(path, sep = $/, **opts) -> array
|
2724
|
+
# - IO.readlines(path, limit, **opts) -> array
|
2725
|
+
# - IO.readlines(path, sep, limit, **opts) -> array
|
2536
2726
|
# -->
|
2537
|
-
#
|
2538
|
-
#
|
2727
|
+
# Returns an array of all lines read from the stream.
|
2728
|
+
#
|
2729
|
+
# When called from class IO (but not subclasses of IO), this method has
|
2730
|
+
# potential security vulnerabilities if called with untrusted input; see
|
2731
|
+
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
2539
2732
|
#
|
2540
|
-
#
|
2541
|
-
# class, a subprocess is created in the same way as Kernel#open, and its output
|
2542
|
-
# is returned. Consider to use File.readlines to disable the behavior of
|
2543
|
-
# subprocess invocation.
|
2733
|
+
# The first argument must be a string that is the path to a file.
|
2544
2734
|
#
|
2545
|
-
#
|
2546
|
-
#
|
2735
|
+
# With only argument `path` given, parses lines from the file at the given
|
2736
|
+
# `path`, as determined by the default line separator, and returns those lines
|
2737
|
+
# in an array:
|
2547
2738
|
#
|
2548
|
-
#
|
2549
|
-
#
|
2739
|
+
# IO.readlines('t.txt')
|
2740
|
+
# # => ["First line\n", "Second line\n", "\n", "Third line\n", "Fourth line\n"]
|
2550
2741
|
#
|
2551
|
-
#
|
2742
|
+
# With argument `sep` given, parses lines as determined by that line separator
|
2743
|
+
# (see [Line Separator](rdoc-ref:IO@Line+Separator)):
|
2552
2744
|
#
|
2553
|
-
#
|
2745
|
+
# # Ordinary separator.
|
2746
|
+
# IO.readlines('t.txt', 'li')
|
2747
|
+
# # =>["First li", "ne\nSecond li", "ne\n\nThird li", "ne\nFourth li", "ne\n"]
|
2748
|
+
# # Get-paragraphs separator.
|
2749
|
+
# IO.readlines('t.txt', '')
|
2750
|
+
# # => ["First line\nSecond line\n\n", "Third line\nFourth line\n"]
|
2751
|
+
# # Get-all separator.
|
2752
|
+
# IO.readlines('t.txt', nil)
|
2753
|
+
# # => ["First line\nSecond line\n\nThird line\nFourth line\n"]
|
2554
2754
|
#
|
2555
|
-
#
|
2755
|
+
# With argument `limit` given, parses lines as determined by the default line
|
2756
|
+
# separator and the given line-length limit (see [Line
|
2757
|
+
# Separator](rdoc-ref:IO@Line+Separator) and [Line
|
2758
|
+
# Limit](rdoc-ref:IO@Line+Limit):
|
2556
2759
|
#
|
2557
|
-
#
|
2760
|
+
# IO.readlines('t.txt', 7)
|
2761
|
+
# # => ["First l", "ine\n", "Second ", "line\n", "\n", "Third l", "ine\n", "Fourth ", "line\n"]
|
2558
2762
|
#
|
2559
|
-
#
|
2560
|
-
#
|
2561
|
-
# and `\r\n` will be removed from the end of each line.
|
2763
|
+
# With arguments `sep` and `limit` given, combines the two behaviors (see [Line
|
2764
|
+
# Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
|
2562
2765
|
#
|
2766
|
+
# Optional keyword arguments `opts` specify:
|
2563
2767
|
#
|
2564
|
-
#
|
2768
|
+
# * [Open Options](rdoc-ref:IO@Open+Options).
|
2769
|
+
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
2770
|
+
# * [Line Options](rdoc-ref:IO@Line+IO).
|
2565
2771
|
#
|
2566
|
-
def self.readlines: (String | _ToPath name, ?String sep, ?Integer limit, ?external_encoding: String
|
2772
|
+
def self.readlines: (String | _ToPath name, ?String sep, ?Integer limit, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) -> ::Array[String]
|
2567
2773
|
|
2568
2774
|
# <!--
|
2569
2775
|
# rdoc-file=io.c
|
2570
|
-
# - IO.select(
|
2776
|
+
# - IO.select(read_ios, write_ios = [], error_ios = [], timeout = nil) -> array or nil
|
2571
2777
|
# -->
|
2572
|
-
#
|
2573
|
-
# until one or more of
|
2574
|
-
#
|
2575
|
-
#
|
2576
|
-
#
|
2778
|
+
# Invokes system call [select(2)](https://linux.die.net/man/2/select), which
|
2779
|
+
# monitors multiple file descriptors, waiting until one or more of the file
|
2780
|
+
# descriptors becomes ready for some class of I/O operation.
|
2781
|
+
#
|
2782
|
+
# Not implemented on all platforms.
|
2783
|
+
#
|
2784
|
+
# Each of the arguments `read_ios`, `write_ios`, and `error_ios` is an array of
|
2785
|
+
# IO objects.
|
2786
|
+
#
|
2787
|
+
# Argument `timeout` is a numeric value (such as integer or float) timeout
|
2788
|
+
# interval in seconds.
|
2789
|
+
#
|
2790
|
+
# The method monitors the IO objects given in all three arrays, waiting for some
|
2791
|
+
# to be ready; returns a 3-element array whose elements are:
|
2792
|
+
#
|
2793
|
+
# * An array of the objects in `read_ios` that are ready for reading.
|
2794
|
+
# * An array of the objects in `write_ios` that are ready for writing.
|
2795
|
+
# * An array of the objects in `error_ios` have pending exceptions.
|
2796
|
+
#
|
2797
|
+
# If no object becomes ready within the given `timeout`, `nil` is returned.
|
2577
2798
|
#
|
2578
2799
|
# IO.select peeks the buffer of IO objects for testing readability. If the IO
|
2579
2800
|
# buffer is not empty, IO.select immediately notifies readability. This "peek"
|
2580
2801
|
# only happens for IO objects. It does not happen for IO-like objects such as
|
2581
2802
|
# OpenSSL::SSL::SSLSocket.
|
2582
2803
|
#
|
2583
|
-
# The best way to use IO.select is invoking it after
|
2584
|
-
# #read_nonblock, #write_nonblock, etc. The methods raise an exception which
|
2585
|
-
# extended by IO::WaitReadable or IO::WaitWritable. The modules notify how
|
2586
|
-
# caller should wait with IO.select. If IO::WaitReadable is raised, the
|
2587
|
-
# should wait for reading. If IO::WaitWritable is raised, the caller
|
2588
|
-
# wait for writing.
|
2804
|
+
# The best way to use IO.select is invoking it after non-blocking methods such
|
2805
|
+
# as #read_nonblock, #write_nonblock, etc. The methods raise an exception which
|
2806
|
+
# is extended by IO::WaitReadable or IO::WaitWritable. The modules notify how
|
2807
|
+
# the caller should wait with IO.select. If IO::WaitReadable is raised, the
|
2808
|
+
# caller should wait for reading. If IO::WaitWritable is raised, the caller
|
2809
|
+
# should wait for writing.
|
2589
2810
|
#
|
2590
2811
|
# So, blocking read (#readpartial) can be emulated using #read_nonblock and
|
2591
2812
|
# IO.select as follows:
|
@@ -2600,7 +2821,7 @@ class IO < Object
|
|
2600
2821
|
# retry
|
2601
2822
|
# end
|
2602
2823
|
#
|
2603
|
-
# Especially, the combination of
|
2824
|
+
# Especially, the combination of non-blocking methods and IO.select is preferred
|
2604
2825
|
# for IO like objects such as OpenSSL::SSL::SSLSocket. It has #to_io method to
|
2605
2826
|
# return underlying IO object. IO.select calls #to_io to obtain the file
|
2606
2827
|
# descriptor to wait.
|
@@ -2626,13 +2847,13 @@ class IO < Object
|
|
2626
2847
|
# blocking. So, the caller should wait for ready for writability as above
|
2627
2848
|
# example.
|
2628
2849
|
#
|
2629
|
-
# The combination of
|
2850
|
+
# The combination of non-blocking methods and IO.select is also useful for
|
2630
2851
|
# streams such as tty, pipe socket socket when multiple processes read from a
|
2631
2852
|
# stream.
|
2632
2853
|
#
|
2633
2854
|
# Finally, Linux kernel developers don't guarantee that readability of select(2)
|
2634
|
-
# means readability of following read(2) even for a single process
|
2635
|
-
# select(2)
|
2855
|
+
# means readability of following read(2) even for a single process; see
|
2856
|
+
# [select(2)](https://linux.die.net/man/2/select)
|
2636
2857
|
#
|
2637
2858
|
# Invoking IO.select before IO#readpartial works well as usual. However it is
|
2638
2859
|
# not the best way to use IO.select.
|
@@ -2659,18 +2880,7 @@ class IO < Object
|
|
2659
2880
|
# string = string.byteslice(written..-1)
|
2660
2881
|
# end
|
2661
2882
|
#
|
2662
|
-
#
|
2663
|
-
# read_array
|
2664
|
-
# : an array of IO objects that wait until ready for read
|
2665
|
-
# write_array
|
2666
|
-
# : an array of IO objects that wait until ready for write
|
2667
|
-
# error_array
|
2668
|
-
# : an array of IO objects that wait for exceptions
|
2669
|
-
# timeout
|
2670
|
-
# : a numeric value in second
|
2671
|
-
#
|
2672
|
-
#
|
2673
|
-
# ### Example
|
2883
|
+
# Example:
|
2674
2884
|
#
|
2675
2885
|
# rp, wp = IO.pipe
|
2676
2886
|
# mesg = "ping "
|
@@ -2692,7 +2902,7 @@ class IO < Object
|
|
2692
2902
|
# end
|
2693
2903
|
# }
|
2694
2904
|
#
|
2695
|
-
#
|
2905
|
+
# Output:
|
2696
2906
|
#
|
2697
2907
|
# ping pong
|
2698
2908
|
# ping pong
|
@@ -2701,15 +2911,21 @@ class IO < Object
|
|
2701
2911
|
# ping
|
2702
2912
|
#
|
2703
2913
|
def self.select: [X, Y, Z] (::Array[X & io]? read_array, ?::Array[Y & io]? write_array, ?::Array[Z & io]? error_array) -> [ Array[X], Array[Y], Array[Z] ]
|
2704
|
-
| [X, Y, Z] (::Array[X & io]? read_array, ?::Array[Y & io]? write_array, ?::Array[Z & io]? error_array,
|
2914
|
+
| [X, Y, Z] (::Array[X & io]? read_array, ?::Array[Y & io]? write_array, ?::Array[Z & io]? error_array, Time::_Timeout? timeout) -> [ Array[X], Array[Y], Array[Z] ]?
|
2705
2915
|
|
2706
2916
|
# <!--
|
2707
2917
|
# rdoc-file=io.c
|
2708
|
-
# - IO.sysopen(path,
|
2918
|
+
# - IO.sysopen(path, mode = 'r', perm = 0666) -> integer
|
2709
2919
|
# -->
|
2710
|
-
# Opens the given path
|
2920
|
+
# Opens the file at the given path with the given mode and permissions; returns
|
2921
|
+
# the integer file descriptor.
|
2711
2922
|
#
|
2712
|
-
#
|
2923
|
+
# If the file is to be readable, it must exist; if the file is to be writable
|
2924
|
+
# and does not exist, it is created with the given permissions:
|
2925
|
+
#
|
2926
|
+
# File.write('t.tmp', '') # => 0
|
2927
|
+
# IO.sysopen('t.tmp') # => 8
|
2928
|
+
# IO.sysopen('t.tmp', 'w') # => 9
|
2713
2929
|
#
|
2714
2930
|
def self.sysopen: (String path, ?String mode, ?String perm) -> Integer
|
2715
2931
|
|
@@ -2724,142 +2940,286 @@ class IO < Object
|
|
2724
2940
|
# IO.try_convert(ARGF) # => #<IO:<STDIN>>
|
2725
2941
|
# IO.try_convert('STDOUT') # => nil
|
2726
2942
|
#
|
2727
|
-
def self.try_convert: (
|
2943
|
+
def self.try_convert: (_ToIO obj) -> IO
|
2944
|
+
| (untyped obj) -> IO?
|
2728
2945
|
|
2729
2946
|
# <!--
|
2730
2947
|
# rdoc-file=io.c
|
2731
|
-
# - IO.write(
|
2732
|
-
# - IO.write(name, string [, offset] [, opt]) -> integer
|
2733
|
-
# - File.write(name, string [, offset]) -> integer
|
2734
|
-
# - File.write(name, string [, offset] [, opt]) -> integer
|
2948
|
+
# - IO.write(path, data, offset = 0, **opts) -> integer
|
2735
2949
|
# -->
|
2736
|
-
# Opens the
|
2737
|
-
# returns the
|
2738
|
-
# returning. If *offset* is not given in write mode, the file is truncated.
|
2739
|
-
# Otherwise, it is not truncated.
|
2740
|
-
#
|
2741
|
-
# If `name` starts with a pipe character (`"|"`) and the receiver is the IO
|
2742
|
-
# class, a subprocess is created in the same way as Kernel#open, and its output
|
2743
|
-
# is returned. Consider to use File.write to disable the behavior of subprocess
|
2744
|
-
# invocation.
|
2950
|
+
# Opens the stream, writes the given `data` to it, and closes the stream;
|
2951
|
+
# returns the number of bytes written.
|
2745
2952
|
#
|
2746
|
-
#
|
2747
|
-
#
|
2748
|
-
#
|
2749
|
-
# # File would now read: "0123456789"
|
2750
|
-
# IO.write("|tr a-z A-Z", "abc") #=> 3
|
2751
|
-
# # Prints "ABC" to the standard output
|
2953
|
+
# When called from class IO (but not subclasses of IO), this method has
|
2954
|
+
# potential security vulnerabilities if called with untrusted input; see
|
2955
|
+
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
2752
2956
|
#
|
2753
|
-
#
|
2754
|
-
# It accepts the following keys:
|
2957
|
+
# The first argument must be a string that is the path to a file.
|
2755
2958
|
#
|
2756
|
-
#
|
2757
|
-
# :
|
2959
|
+
# With only argument `path` given, writes the given `data` to the file at that
|
2960
|
+
# path:
|
2758
2961
|
#
|
2759
|
-
#
|
2760
|
-
#
|
2962
|
+
# IO.write('t.tmp', 'abc') # => 3
|
2963
|
+
# File.read('t.tmp') # => "abc"
|
2761
2964
|
#
|
2762
|
-
# :
|
2763
|
-
# : string or integer
|
2965
|
+
# If `offset` is zero (the default), the file is overwritten:
|
2764
2966
|
#
|
2765
|
-
#
|
2766
|
-
#
|
2767
|
-
# possible modes.
|
2967
|
+
# IO.write('t.tmp', 'A') # => 1
|
2968
|
+
# File.read('t.tmp') # => "A"
|
2768
2969
|
#
|
2769
|
-
# :
|
2770
|
-
# : integer
|
2970
|
+
# If `offset` in within the file content, the file is partly overwritten:
|
2771
2971
|
#
|
2772
|
-
#
|
2972
|
+
# IO.write('t.tmp', 'abcdef') # => 3
|
2973
|
+
# File.read('t.tmp') # => "abcdef"
|
2974
|
+
# # Offset within content.
|
2975
|
+
# IO.write('t.tmp', '012', 2) # => 3
|
2976
|
+
# File.read('t.tmp') # => "ab012f"
|
2773
2977
|
#
|
2774
|
-
#
|
2775
|
-
#
|
2978
|
+
# If `offset` is outside the file content, the file is padded with null
|
2979
|
+
# characters `"\u0000"`:
|
2776
2980
|
#
|
2777
|
-
#
|
2778
|
-
#
|
2981
|
+
# IO.write('t.tmp', 'xyz', 10) # => 3
|
2982
|
+
# File.read('t.tmp') # => "ab012f\u0000\u0000\u0000\u0000xyz"
|
2779
2983
|
#
|
2984
|
+
# Optional keyword arguments `opts` specify:
|
2780
2985
|
#
|
2781
|
-
#
|
2986
|
+
# * [Open Options](rdoc-ref:IO@Open+Options).
|
2987
|
+
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
2782
2988
|
#
|
2783
|
-
def self.write: (String
|
2989
|
+
def self.write: (String path, _ToS data, ?Integer offset, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> Integer
|
2784
2990
|
|
2785
2991
|
# <!--
|
2786
2992
|
# rdoc-file=io.c
|
2787
|
-
# - IO.for_fd(fd, mode
|
2993
|
+
# - IO.for_fd(fd, mode = 'r', **opts) -> io
|
2788
2994
|
# -->
|
2789
2995
|
# Synonym for IO.new.
|
2790
2996
|
#
|
2791
|
-
|
2997
|
+
alias self.for_fd self.new
|
2792
2998
|
|
2793
2999
|
# <!--
|
2794
3000
|
# rdoc-file=io.c
|
2795
|
-
# - IO.open(fd, mode=
|
2796
|
-
# - IO.open(fd, mode=
|
3001
|
+
# - IO.open(fd, mode = 'r', **opts) -> io
|
3002
|
+
# - IO.open(fd, mode = 'r', **opts) {|io| ... } -> object
|
2797
3003
|
# -->
|
2798
|
-
#
|
2799
|
-
#
|
2800
|
-
#
|
2801
|
-
#
|
3004
|
+
# Creates a new IO object, via IO.new with the given arguments.
|
3005
|
+
#
|
3006
|
+
# With no block given, returns the IO object.
|
3007
|
+
#
|
3008
|
+
# With a block given, calls the block with the IO object and returns the block's
|
3009
|
+
# value.
|
3010
|
+
#
|
3011
|
+
def self.open: (int fd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> instance
|
3012
|
+
| [X] (int fd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) { (instance) -> X } -> X
|
3013
|
+
|
3014
|
+
# <!-- rdoc-file=io.c -->
|
3015
|
+
# Calls the block with each remaining line read from the stream; returns `self`.
|
3016
|
+
# Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO).
|
3017
|
+
#
|
3018
|
+
# With no arguments given, reads lines as determined by line separator `$/`:
|
3019
|
+
#
|
3020
|
+
# f = File.new('t.txt')
|
3021
|
+
# f.each_line {|line| p line }
|
3022
|
+
# f.each_line {|line| fail 'Cannot happen' }
|
3023
|
+
# f.close
|
3024
|
+
#
|
3025
|
+
# Output:
|
3026
|
+
#
|
3027
|
+
# "First line\n"
|
3028
|
+
# "Second line\n"
|
3029
|
+
# "\n"
|
3030
|
+
# "Fourth line\n"
|
3031
|
+
# "Fifth line\n"
|
3032
|
+
#
|
3033
|
+
# With only string argument `sep` given, reads lines as determined by line
|
3034
|
+
# separator `sep`; see [Line Separator](rdoc-ref:IO@Line+Separator):
|
3035
|
+
#
|
3036
|
+
# f = File.new('t.txt')
|
3037
|
+
# f.each_line('li') {|line| p line }
|
3038
|
+
# f.close
|
3039
|
+
#
|
3040
|
+
# Output:
|
3041
|
+
#
|
3042
|
+
# "First li"
|
3043
|
+
# "ne\nSecond li"
|
3044
|
+
# "ne\n\nFourth li"
|
3045
|
+
# "ne\nFifth li"
|
3046
|
+
# "ne\n"
|
3047
|
+
#
|
3048
|
+
# The two special values for `sep` are honored:
|
3049
|
+
#
|
3050
|
+
# f = File.new('t.txt')
|
3051
|
+
# # Get all into one string.
|
3052
|
+
# f.each_line(nil) {|line| p line }
|
3053
|
+
# f.close
|
3054
|
+
#
|
3055
|
+
# Output:
|
3056
|
+
#
|
3057
|
+
# "First line\nSecond line\n\nFourth line\nFifth line\n"
|
3058
|
+
#
|
3059
|
+
# f.rewind
|
3060
|
+
# # Get paragraphs (up to two line separators).
|
3061
|
+
# f.each_line('') {|line| p line }
|
3062
|
+
#
|
3063
|
+
# Output:
|
3064
|
+
#
|
3065
|
+
# "First line\nSecond line\n\n"
|
3066
|
+
# "Fourth line\nFifth line\n"
|
3067
|
+
#
|
3068
|
+
# With only integer argument `limit` given, limits the number of bytes in each
|
3069
|
+
# line; see [Line Limit](rdoc-ref:IO@Line+Limit):
|
3070
|
+
#
|
3071
|
+
# f = File.new('t.txt')
|
3072
|
+
# f.each_line(8) {|line| p line }
|
3073
|
+
# f.close
|
2802
3074
|
#
|
2803
|
-
#
|
3075
|
+
# Output:
|
3076
|
+
#
|
3077
|
+
# "First li"
|
3078
|
+
# "ne\n"
|
3079
|
+
# "Second l"
|
3080
|
+
# "ine\n"
|
3081
|
+
# "\n"
|
3082
|
+
# "Fourth l"
|
3083
|
+
# "ine\n"
|
3084
|
+
# "Fifth li"
|
3085
|
+
# "ne\n"
|
3086
|
+
#
|
3087
|
+
# With arguments `sep` and `limit` given, combines the two behaviors (see [Line
|
3088
|
+
# Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
|
3089
|
+
#
|
3090
|
+
# Optional keyword argument `chomp` specifies whether line separators are to be
|
3091
|
+
# omitted:
|
3092
|
+
#
|
3093
|
+
# f = File.new('t.txt')
|
3094
|
+
# f.each_line(chomp: true) {|line| p line }
|
3095
|
+
# f.close
|
3096
|
+
#
|
3097
|
+
# Output:
|
3098
|
+
#
|
3099
|
+
# "First line"
|
3100
|
+
# "Second line"
|
3101
|
+
# ""
|
3102
|
+
# "Fourth line"
|
3103
|
+
# "Fifth line"
|
2804
3104
|
#
|
2805
|
-
|
3105
|
+
# Returns an Enumerator if no block is given.
|
3106
|
+
#
|
3107
|
+
def each_line: (?string sep, ?int limit, ?chomp: boolish) { (String line) -> void } -> self
|
3108
|
+
| (?string sep, ?int limit, ?chomp: boolish) -> ::Enumerator[String, self]
|
2806
3109
|
|
2807
3110
|
# <!--
|
2808
3111
|
# rdoc-file=io.c
|
2809
|
-
# -
|
2810
|
-
# -
|
3112
|
+
# - each_line(sep = $/, chomp: false) {|line| ... } -> self
|
3113
|
+
# - each_line(limit, chomp: false) {|line| ... } -> self
|
3114
|
+
# - each_line(sep, limit, chomp: false) {|line| ... } -> self
|
3115
|
+
# - each_line -> enumerator
|
2811
3116
|
# -->
|
2812
|
-
#
|
2813
|
-
#
|
2814
|
-
# will automatically be closed when the block terminates. In this instance,
|
2815
|
-
# IO.open returns the value of the block.
|
3117
|
+
# Calls the block with each remaining line read from the stream; returns `self`.
|
3118
|
+
# Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO).
|
2816
3119
|
#
|
2817
|
-
#
|
3120
|
+
# With no arguments given, reads lines as determined by line separator `$/`:
|
2818
3121
|
#
|
2819
|
-
|
2820
|
-
|
2821
|
-
|
2822
|
-
|
2823
|
-
| () -> ::Enumerator[Integer, self]
|
2824
|
-
|
2825
|
-
def chars: () { (String arg0) -> untyped } -> self
|
2826
|
-
| () -> ::Enumerator[String, self]
|
2827
|
-
|
2828
|
-
def codepoints: () { (Integer arg0) -> untyped } -> self
|
2829
|
-
| () -> ::Enumerator[Integer, self]
|
2830
|
-
|
2831
|
-
# <!-- rdoc-file=io.c -->
|
2832
|
-
# Executes the block for every line in *ios*, where lines are separated by
|
2833
|
-
# *sep*. *ios* must be opened for reading or an IOError will be raised.
|
3122
|
+
# f = File.new('t.txt')
|
3123
|
+
# f.each_line {|line| p line }
|
3124
|
+
# f.each_line {|line| fail 'Cannot happen' }
|
3125
|
+
# f.close
|
2834
3126
|
#
|
2835
|
-
#
|
3127
|
+
# Output:
|
2836
3128
|
#
|
2837
|
-
#
|
2838
|
-
#
|
3129
|
+
# "First line\n"
|
3130
|
+
# "Second line\n"
|
3131
|
+
# "\n"
|
3132
|
+
# "Fourth line\n"
|
3133
|
+
# "Fifth line\n"
|
2839
3134
|
#
|
2840
|
-
#
|
3135
|
+
# With only string argument `sep` given, reads lines as determined by line
|
3136
|
+
# separator `sep`; see [Line Separator](rdoc-ref:IO@Line+Separator):
|
3137
|
+
#
|
3138
|
+
# f = File.new('t.txt')
|
3139
|
+
# f.each_line('li') {|line| p line }
|
3140
|
+
# f.close
|
3141
|
+
#
|
3142
|
+
# Output:
|
3143
|
+
#
|
3144
|
+
# "First li"
|
3145
|
+
# "ne\nSecond li"
|
3146
|
+
# "ne\n\nFourth li"
|
3147
|
+
# "ne\nFifth li"
|
3148
|
+
# "ne\n"
|
3149
|
+
#
|
3150
|
+
# The two special values for `sep` are honored:
|
3151
|
+
#
|
3152
|
+
# f = File.new('t.txt')
|
3153
|
+
# # Get all into one string.
|
3154
|
+
# f.each_line(nil) {|line| p line }
|
3155
|
+
# f.close
|
3156
|
+
#
|
3157
|
+
# Output:
|
3158
|
+
#
|
3159
|
+
# "First line\nSecond line\n\nFourth line\nFifth line\n"
|
3160
|
+
#
|
3161
|
+
# f.rewind
|
3162
|
+
# # Get paragraphs (up to two line separators).
|
3163
|
+
# f.each_line('') {|line| p line }
|
3164
|
+
#
|
3165
|
+
# Output:
|
3166
|
+
#
|
3167
|
+
# "First line\nSecond line\n\n"
|
3168
|
+
# "Fourth line\nFifth line\n"
|
3169
|
+
#
|
3170
|
+
# With only integer argument `limit` given, limits the number of bytes in each
|
3171
|
+
# line; see [Line Limit](rdoc-ref:IO@Line+Limit):
|
3172
|
+
#
|
3173
|
+
# f = File.new('t.txt')
|
3174
|
+
# f.each_line(8) {|line| p line }
|
3175
|
+
# f.close
|
3176
|
+
#
|
3177
|
+
# Output:
|
3178
|
+
#
|
3179
|
+
# "First li"
|
3180
|
+
# "ne\n"
|
3181
|
+
# "Second l"
|
3182
|
+
# "ine\n"
|
3183
|
+
# "\n"
|
3184
|
+
# "Fourth l"
|
3185
|
+
# "ine\n"
|
3186
|
+
# "Fifth li"
|
3187
|
+
# "ne\n"
|
3188
|
+
#
|
3189
|
+
# With arguments `sep` and `limit` given, combines the two behaviors (see [Line
|
3190
|
+
# Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
|
3191
|
+
#
|
3192
|
+
# Optional keyword argument `chomp` specifies whether line separators are to be
|
3193
|
+
# omitted:
|
2841
3194
|
#
|
2842
|
-
#
|
2843
|
-
#
|
2844
|
-
#
|
2845
|
-
#
|
3195
|
+
# f = File.new('t.txt')
|
3196
|
+
# f.each_line(chomp: true) {|line| p line }
|
3197
|
+
# f.close
|
3198
|
+
#
|
3199
|
+
# Output:
|
2846
3200
|
#
|
2847
|
-
#
|
3201
|
+
# "First line"
|
3202
|
+
# "Second line"
|
3203
|
+
# ""
|
3204
|
+
# "Fourth line"
|
3205
|
+
# "Fifth line"
|
2848
3206
|
#
|
2849
|
-
|
2850
|
-
|
3207
|
+
# Returns an Enumerator if no block is given.
|
3208
|
+
#
|
3209
|
+
alias each each_line
|
2851
3210
|
|
2852
3211
|
# <!-- rdoc-file=io.c -->
|
2853
3212
|
# Returns `true` if the stream is positioned at its end, `false` otherwise; see
|
2854
|
-
# [Position](
|
3213
|
+
# [Position](rdoc-ref:IO@Position):
|
2855
3214
|
#
|
2856
3215
|
# f = File.open('t.txt')
|
2857
3216
|
# f.eof # => false
|
2858
3217
|
# f.seek(0, :END) # => 0
|
2859
3218
|
# f.eof # => true
|
3219
|
+
# f.close
|
2860
3220
|
#
|
2861
3221
|
# Raises an exception unless the stream is opened for reading; see
|
2862
|
-
# [Mode](
|
3222
|
+
# [Mode](rdoc-ref:File@Access+Modes).
|
2863
3223
|
#
|
2864
3224
|
# If `self` is a stream such as pipe or socket, this method blocks until the
|
2865
3225
|
# other end sends some data or closes it:
|
@@ -2879,12 +3239,7 @@ class IO < Object
|
|
2879
3239
|
# not behave as you intend with IO#eof?, unless you call IO#rewind first (which
|
2880
3240
|
# is not available for some streams).
|
2881
3241
|
#
|
2882
|
-
|
2883
|
-
#
|
2884
|
-
def eof?: () -> bool
|
2885
|
-
|
2886
|
-
def lines: (?String sep, ?Integer limit) { (String arg0) -> untyped } -> self
|
2887
|
-
| (?String sep, ?Integer limit) -> ::Enumerator[String, self]
|
3242
|
+
alias eof? eof
|
2888
3243
|
|
2889
3244
|
# <!-- rdoc-file=io.c -->
|
2890
3245
|
# Returns the integer file descriptor for the stream:
|
@@ -2893,10 +3248,9 @@ class IO < Object
|
|
2893
3248
|
# $stdout.fileno # => 1
|
2894
3249
|
# $stderr.fileno # => 2
|
2895
3250
|
# File.open('t.txt').fileno # => 10
|
3251
|
+
# f.close
|
2896
3252
|
#
|
2897
|
-
|
2898
|
-
#
|
2899
|
-
def to_i: () -> Integer
|
3253
|
+
alias to_i fileno
|
2900
3254
|
end
|
2901
3255
|
|
2902
3256
|
IO::APPEND: Integer
|
@@ -2984,10 +3338,19 @@ IO::TRUNC: Integer
|
|
2984
3338
|
|
2985
3339
|
IO::WRONLY: Integer
|
2986
3340
|
|
3341
|
+
# <!-- rdoc-file=io.c -->
|
3342
|
+
# Readable event mask for IO#wait.
|
3343
|
+
#
|
2987
3344
|
IO::READABLE: Integer
|
2988
3345
|
|
3346
|
+
# <!-- rdoc-file=io.c -->
|
3347
|
+
# Writable event mask for IO#wait.
|
3348
|
+
#
|
2989
3349
|
IO::WRITABLE: Integer
|
2990
3350
|
|
3351
|
+
# <!-- rdoc-file=io.c -->
|
3352
|
+
# Priority event mask for IO#wait.
|
3353
|
+
#
|
2991
3354
|
IO::PRIORITY: Integer
|
2992
3355
|
|
2993
3356
|
# <!-- rdoc-file=io.c -->
|