rbs 4.1.0.pre.2-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.clang-format +75 -0
- data/.clangd +2 -0
- data/.github/dependabot.yml +24 -0
- data/.github/workflows/bundle-update.yml +63 -0
- data/.github/workflows/c-check.yml +61 -0
- data/.github/workflows/comments.yml +37 -0
- data/.github/workflows/dependabot.yml +30 -0
- data/.github/workflows/jruby.yml +67 -0
- data/.github/workflows/milestone.yml +83 -0
- data/.github/workflows/ruby.yml +158 -0
- data/.github/workflows/rust.yml +184 -0
- data/.github/workflows/truffleruby.yml +54 -0
- data/.github/workflows/typecheck.yml +39 -0
- data/.github/workflows/wasm.yml +53 -0
- data/.github/workflows/windows.yml +49 -0
- data/.gitignore +38 -0
- data/.rubocop.yml +72 -0
- data/BSDL +22 -0
- data/CHANGELOG.md +2292 -0
- data/COPYING +56 -0
- data/README.md +240 -0
- data/Rakefile +869 -0
- data/Steepfile +53 -0
- data/config.yml +913 -0
- data/core/array.rbs +4142 -0
- data/core/basic_object.rbs +376 -0
- data/core/binding.rbs +148 -0
- data/core/builtin.rbs +278 -0
- data/core/class.rbs +223 -0
- data/core/comparable.rbs +192 -0
- data/core/complex.rbs +812 -0
- data/core/constants.rbs +96 -0
- data/core/data.rbs +415 -0
- data/core/dir.rbs +993 -0
- data/core/encoding.rbs +1368 -0
- data/core/enumerable.rbs +2506 -0
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator/product.rbs +92 -0
- data/core/enumerator.rbs +705 -0
- data/core/env.rbs +6 -0
- data/core/errno.rbs +682 -0
- data/core/errors.rbs +789 -0
- data/core/exception.rbs +485 -0
- data/core/false_class.rbs +82 -0
- data/core/fiber.rbs +570 -0
- data/core/fiber_error.rbs +11 -0
- data/core/file.rbs +2045 -0
- data/core/file_constants.rbs +463 -0
- data/core/file_stat.rbs +534 -0
- data/core/file_test.rbs +331 -0
- data/core/float.rbs +1316 -0
- data/core/gc.rbs +788 -0
- data/core/global_variables.rbs +184 -0
- data/core/hash.rbs +2183 -0
- data/core/integer.rbs +1374 -0
- data/core/io/buffer.rbs +995 -0
- data/core/io/wait.rbs +48 -0
- data/core/io.rbs +3472 -0
- data/core/kernel.rbs +3172 -0
- data/core/marshal.rbs +207 -0
- data/core/match_data.rbs +637 -0
- data/core/math.rbs +770 -0
- data/core/method.rbs +422 -0
- data/core/module.rbs +1856 -0
- data/core/nil_class.rbs +210 -0
- data/core/numeric.rbs +832 -0
- data/core/object.rbs +108 -0
- data/core/object_space/weak_key_map.rbs +166 -0
- data/core/object_space.rbs +197 -0
- data/core/pathname.rbs +1322 -0
- data/core/proc.rbs +905 -0
- data/core/process.rbs +2316 -0
- data/core/ractor.rbs +924 -0
- data/core/random.rbs +255 -0
- data/core/range.rbs +1209 -0
- data/core/rational.rbs +502 -0
- data/core/rb_config.rbs +88 -0
- data/core/rbs/ops.rbs +154 -0
- data/core/rbs/unnamed/argf.rbs +1236 -0
- data/core/rbs/unnamed/env_class.rbs +1214 -0
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +186 -0
- data/core/refinement.rbs +59 -0
- data/core/regexp.rbs +1974 -0
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +809 -0
- data/core/rubygems/basic_specification.rbs +6 -0
- data/core/rubygems/config_file.rbs +38 -0
- data/core/rubygems/dependency_installer.rbs +6 -0
- data/core/rubygems/errors.rbs +109 -0
- data/core/rubygems/installer.rbs +15 -0
- data/core/rubygems/path_support.rbs +6 -0
- data/core/rubygems/platform.rbs +7 -0
- data/core/rubygems/request_set.rbs +49 -0
- data/core/rubygems/requirement.rbs +148 -0
- data/core/rubygems/rubygems.rbs +1105 -0
- data/core/rubygems/source_list.rbs +15 -0
- data/core/rubygems/specification.rbs +23 -0
- data/core/rubygems/stream_ui.rbs +5 -0
- data/core/rubygems/uninstaller.rbs +10 -0
- data/core/rubygems/version.rbs +293 -0
- data/core/set.rbs +751 -0
- data/core/signal.rbs +110 -0
- data/core/string.rbs +5532 -0
- data/core/struct.rbs +668 -0
- data/core/symbol.rbs +482 -0
- data/core/thread.rbs +1826 -0
- data/core/thread_group.rbs +79 -0
- data/core/time.rbs +1793 -0
- data/core/trace_point.rbs +483 -0
- data/core/true_class.rbs +98 -0
- data/core/unbound_method.rbs +337 -0
- data/core/warning.rbs +87 -0
- data/docs/CONTRIBUTING.md +107 -0
- data/docs/aliases.md +79 -0
- data/docs/architecture.md +110 -0
- data/docs/collection.md +192 -0
- data/docs/config.md +171 -0
- data/docs/data_and_struct.md +86 -0
- data/docs/encoding.md +56 -0
- data/docs/gem.md +56 -0
- data/docs/inline.md +634 -0
- data/docs/rbs_by_example.md +309 -0
- data/docs/repo.md +125 -0
- data/docs/rust.md +96 -0
- data/docs/sigs.md +167 -0
- data/docs/stdlib.md +147 -0
- data/docs/syntax.md +940 -0
- data/docs/tools.md +17 -0
- data/docs/type_fingerprint.md +21 -0
- data/docs/wasm_serialization.md +80 -0
- data/exe/rbs +7 -0
- data/ext/rbs_extension/ast_translation.c +1855 -0
- data/ext/rbs_extension/ast_translation.h +41 -0
- data/ext/rbs_extension/class_constants.c +187 -0
- data/ext/rbs_extension/class_constants.h +104 -0
- data/ext/rbs_extension/compat.h +10 -0
- data/ext/rbs_extension/extconf.rb +40 -0
- data/ext/rbs_extension/legacy_location.c +294 -0
- data/ext/rbs_extension/legacy_location.h +82 -0
- data/ext/rbs_extension/main.c +613 -0
- data/ext/rbs_extension/rbs_extension.h +16 -0
- data/ext/rbs_extension/rbs_string_bridging.c +9 -0
- data/ext/rbs_extension/rbs_string_bridging.h +24 -0
- data/goodcheck.yml +91 -0
- data/include/rbs/ast.h +1047 -0
- data/include/rbs/defines.h +99 -0
- data/include/rbs/lexer.h +207 -0
- data/include/rbs/location.h +40 -0
- data/include/rbs/parser.h +153 -0
- data/include/rbs/serialize.h +39 -0
- data/include/rbs/string.h +47 -0
- data/include/rbs/util/rbs_allocator.h +59 -0
- data/include/rbs/util/rbs_assert.h +20 -0
- data/include/rbs/util/rbs_buffer.h +83 -0
- data/include/rbs/util/rbs_constant_pool.h +155 -0
- data/include/rbs/util/rbs_encoding.h +282 -0
- data/include/rbs/util/rbs_unescape.h +24 -0
- data/include/rbs.h +14 -0
- data/lib/rbs/ancestor_graph.rb +92 -0
- data/lib/rbs/annotate/annotations.rb +199 -0
- data/lib/rbs/annotate/formatter.rb +82 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
- data/lib/rbs/annotate/rdoc_source.rb +131 -0
- data/lib/rbs/annotate.rb +8 -0
- data/lib/rbs/ast/annotation.rb +29 -0
- data/lib/rbs/ast/comment.rb +29 -0
- data/lib/rbs/ast/declarations.rb +472 -0
- data/lib/rbs/ast/directives.rb +49 -0
- data/lib/rbs/ast/members.rb +451 -0
- data/lib/rbs/ast/ruby/annotations.rb +451 -0
- data/lib/rbs/ast/ruby/comment_block.rb +247 -0
- data/lib/rbs/ast/ruby/declarations.rb +291 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +762 -0
- data/lib/rbs/ast/type_param.rb +235 -0
- data/lib/rbs/ast/visitor.rb +137 -0
- data/lib/rbs/buffer.rb +189 -0
- data/lib/rbs/builtin_names.rb +58 -0
- data/lib/rbs/cli/colored_io.rb +48 -0
- data/lib/rbs/cli/diff.rb +84 -0
- data/lib/rbs/cli/validate.rb +294 -0
- data/lib/rbs/cli.rb +1253 -0
- data/lib/rbs/collection/cleaner.rb +38 -0
- data/lib/rbs/collection/config/lockfile.rb +92 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +269 -0
- data/lib/rbs/collection/config.rb +81 -0
- data/lib/rbs/collection/installer.rb +32 -0
- data/lib/rbs/collection/sources/base.rb +14 -0
- data/lib/rbs/collection/sources/git.rb +265 -0
- data/lib/rbs/collection/sources/local.rb +81 -0
- data/lib/rbs/collection/sources/rubygems.rb +48 -0
- data/lib/rbs/collection/sources/stdlib.rb +50 -0
- data/lib/rbs/collection/sources.rb +38 -0
- data/lib/rbs/collection.rb +16 -0
- data/lib/rbs/constant.rb +28 -0
- data/lib/rbs/definition.rb +415 -0
- data/lib/rbs/definition_builder/ancestor_builder.rb +678 -0
- data/lib/rbs/definition_builder/method_builder.rb +295 -0
- data/lib/rbs/definition_builder.rb +1054 -0
- data/lib/rbs/diff.rb +131 -0
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +1028 -0
- data/lib/rbs/environment_loader.rb +167 -0
- data/lib/rbs/environment_walker.rb +155 -0
- data/lib/rbs/errors.rb +634 -0
- data/lib/rbs/factory.rb +18 -0
- data/lib/rbs/file_finder.rb +28 -0
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +568 -0
- data/lib/rbs/location_aux.rb +170 -0
- data/lib/rbs/locator.rb +247 -0
- data/lib/rbs/method_type.rb +145 -0
- data/lib/rbs/namespace.rb +154 -0
- data/lib/rbs/parser/lex_result.rb +15 -0
- data/lib/rbs/parser/token.rb +23 -0
- data/lib/rbs/parser_aux.rb +142 -0
- data/lib/rbs/prototype/helpers.rb +197 -0
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +816 -0
- data/lib/rbs/prototype/rbi.rb +625 -0
- data/lib/rbs/prototype/runtime/helpers.rb +59 -0
- data/lib/rbs/prototype/runtime/reflection.rb +19 -0
- data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
- data/lib/rbs/prototype/runtime.rb +680 -0
- data/lib/rbs/repository.rb +127 -0
- data/lib/rbs/resolver/constant_resolver.rb +219 -0
- data/lib/rbs/resolver/type_name_resolver.rb +167 -0
- data/lib/rbs/rewriter.rb +70 -0
- data/lib/rbs/sorter.rb +198 -0
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/substitution.rb +83 -0
- data/lib/rbs/subtractor.rb +204 -0
- data/lib/rbs/test/errors.rb +80 -0
- data/lib/rbs/test/guaranteed.rb +30 -0
- data/lib/rbs/test/hook.rb +212 -0
- data/lib/rbs/test/observer.rb +19 -0
- data/lib/rbs/test/setup.rb +84 -0
- data/lib/rbs/test/setup_helper.rb +50 -0
- data/lib/rbs/test/tester.rb +167 -0
- data/lib/rbs/test/type_check.rb +457 -0
- data/lib/rbs/test.rb +112 -0
- data/lib/rbs/type_alias_dependency.rb +100 -0
- data/lib/rbs/type_alias_regularity.rb +126 -0
- data/lib/rbs/type_name.rb +122 -0
- data/lib/rbs/types.rb +1604 -0
- data/lib/rbs/unit_test/convertibles.rb +177 -0
- data/lib/rbs/unit_test/spy.rb +138 -0
- data/lib/rbs/unit_test/type_assertions.rb +383 -0
- data/lib/rbs/unit_test/with_aliases.rb +145 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/validator.rb +186 -0
- data/lib/rbs/variance_calculator.rb +189 -0
- data/lib/rbs/vendorer.rb +71 -0
- data/lib/rbs/version.rb +5 -0
- data/lib/rbs/wasm/deserializer.rb +213 -0
- data/lib/rbs/wasm/jars/asm-analysis.jar +0 -0
- data/lib/rbs/wasm/jars/asm-commons.jar +0 -0
- data/lib/rbs/wasm/jars/asm-tree.jar +0 -0
- data/lib/rbs/wasm/jars/asm-util.jar +0 -0
- data/lib/rbs/wasm/jars/asm.jar +0 -0
- data/lib/rbs/wasm/jars/compiler.jar +0 -0
- data/lib/rbs/wasm/jars/log.jar +0 -0
- data/lib/rbs/wasm/jars/runtime.jar +0 -0
- data/lib/rbs/wasm/jars/wasi.jar +0 -0
- data/lib/rbs/wasm/jars/wasm.jar +0 -0
- data/lib/rbs/wasm/location.rb +61 -0
- data/lib/rbs/wasm/parser.rb +137 -0
- data/lib/rbs/wasm/rbs_parser.wasm +0 -0
- data/lib/rbs/wasm/runtime.rb +217 -0
- data/lib/rbs/wasm/serialization_schema.rb +110 -0
- data/lib/rbs/writer.rb +424 -0
- data/lib/rbs.rb +117 -0
- data/lib/rdoc/discover.rb +20 -0
- data/lib/rdoc_plugin/parser.rb +163 -0
- data/rbs.gemspec +68 -0
- data/schema/annotation.json +14 -0
- data/schema/comment.json +26 -0
- data/schema/decls.json +326 -0
- data/schema/function.json +87 -0
- data/schema/location.json +56 -0
- data/schema/members.json +266 -0
- data/schema/methodType.json +50 -0
- data/schema/typeParam.json +52 -0
- data/schema/types.json +317 -0
- data/sig/ancestor_builder.rbs +163 -0
- data/sig/ancestor_graph.rbs +60 -0
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +85 -0
- data/sig/annotate/rdoc_source.rbs +32 -0
- data/sig/annotation.rbs +27 -0
- data/sig/ast/ruby/annotations.rbs +470 -0
- data/sig/ast/ruby/comment_block.rbs +127 -0
- data/sig/ast/ruby/declarations.rbs +158 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +198 -0
- data/sig/buffer.rbs +108 -0
- data/sig/builtin_names.rbs +44 -0
- data/sig/cli/colored_io.rbs +15 -0
- data/sig/cli/diff.rbs +15 -0
- data/sig/cli/validate.rbs +47 -0
- data/sig/cli.rbs +89 -0
- data/sig/collection/cleaner.rbs +13 -0
- data/sig/collection/config/lockfile.rbs +74 -0
- data/sig/collection/config/lockfile_generator.rbs +68 -0
- data/sig/collection/config.rbs +46 -0
- data/sig/collection/installer.rbs +17 -0
- data/sig/collection/sources.rbs +214 -0
- data/sig/collection.rbs +4 -0
- data/sig/comment.rbs +26 -0
- data/sig/constant.rbs +21 -0
- data/sig/declarations.rbs +274 -0
- data/sig/definition.rbs +232 -0
- data/sig/definition_builder.rbs +181 -0
- data/sig/diff.rbs +28 -0
- data/sig/directives.rbs +77 -0
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +286 -0
- data/sig/environment_loader.rbs +111 -0
- data/sig/environment_walker.rbs +65 -0
- data/sig/errors.rbs +408 -0
- data/sig/factory.rbs +5 -0
- data/sig/file_finder.rbs +28 -0
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +126 -0
- data/sig/location.rbs +135 -0
- data/sig/locator.rbs +56 -0
- data/sig/manifest.yaml +5 -0
- data/sig/members.rbs +258 -0
- data/sig/method_builder.rbs +89 -0
- data/sig/method_types.rbs +58 -0
- data/sig/namespace.rbs +161 -0
- data/sig/parser.rbs +164 -0
- data/sig/prototype/helpers.rbs +29 -0
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/prototype/rb.rbs +96 -0
- data/sig/prototype/rbi.rbs +75 -0
- data/sig/prototype/runtime.rbs +182 -0
- data/sig/rbs.rbs +21 -0
- data/sig/rdoc/rbs.rbs +67 -0
- data/sig/repository.rbs +85 -0
- data/sig/resolver/constant_resolver.rbs +92 -0
- data/sig/resolver/context.rbs +34 -0
- data/sig/resolver/type_name_resolver.rbs +61 -0
- data/sig/rewriter.rbs +45 -0
- data/sig/shims/bundler.rbs +38 -0
- data/sig/shims/enumerable.rbs +5 -0
- data/sig/shims/rubygems.rbs +19 -0
- data/sig/sorter.rbs +41 -0
- data/sig/source.rbs +48 -0
- data/sig/substitution.rbs +48 -0
- data/sig/subtractor.rbs +37 -0
- data/sig/test/errors.rbs +52 -0
- data/sig/test/guranteed.rbs +9 -0
- data/sig/test/type_check.rbs +19 -0
- data/sig/test.rbs +82 -0
- data/sig/type_alias_dependency.rbs +53 -0
- data/sig/type_alias_regularity.rbs +98 -0
- data/sig/type_param.rbs +115 -0
- data/sig/typename.rbs +89 -0
- data/sig/types.rbs +578 -0
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +22 -0
- data/sig/unit_test/type_assertions.rbs +211 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/sig/use_map.rbs +35 -0
- data/sig/util.rbs +9 -0
- data/sig/validator.rbs +63 -0
- data/sig/variance_calculator.rbs +87 -0
- data/sig/vendorer.rbs +51 -0
- data/sig/version.rbs +3 -0
- data/sig/visitor.rbs +47 -0
- data/sig/wasm/deserializer.rbs +66 -0
- data/sig/wasm/serialization_schema.rbs +13 -0
- data/sig/writer.rbs +127 -0
- data/src/ast.c +1628 -0
- data/src/lexer.c +3217 -0
- data/src/lexer.re +155 -0
- data/src/lexstate.c +217 -0
- data/src/location.c +31 -0
- data/src/parser.c +4255 -0
- data/src/serialize.c +958 -0
- data/src/string.c +41 -0
- data/src/util/rbs_allocator.c +162 -0
- data/src/util/rbs_assert.c +19 -0
- data/src/util/rbs_buffer.c +54 -0
- data/src/util/rbs_constant_pool.c +268 -0
- data/src/util/rbs_encoding.c +21308 -0
- data/src/util/rbs_unescape.c +167 -0
- data/stdlib/abbrev/0/abbrev.rbs +66 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +355 -0
- data/stdlib/benchmark/0/benchmark.rbs +452 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +1647 -0
- data/stdlib/bigdecimal-math/0/big_math.rbs +280 -0
- data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
- data/stdlib/cgi/0/core.rbs +911 -0
- data/stdlib/cgi/0/manifest.yaml +4 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +266 -0
- data/stdlib/csv/0/csv.rbs +3776 -0
- data/stdlib/csv/0/manifest.yaml +3 -0
- data/stdlib/date/0/date.rbs +1598 -0
- data/stdlib/date/0/date_time.rbs +617 -0
- data/stdlib/date/0/time.rbs +26 -0
- data/stdlib/dbm/0/dbm.rbs +421 -0
- data/stdlib/delegate/0/delegator.rbs +187 -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 +344 -0
- data/stdlib/digest/0/digest.rbs +687 -0
- data/stdlib/erb/0/erb.rbs +933 -0
- data/stdlib/etc/0/etc.rbs +884 -0
- data/stdlib/fileutils/0/fileutils.rbs +1753 -0
- data/stdlib/find/0/find.rbs +49 -0
- data/stdlib/forwardable/0/forwardable.rbs +271 -0
- data/stdlib/io-console/0/io-console.rbs +414 -0
- data/stdlib/ipaddr/0/ipaddr.rbs +436 -0
- data/stdlib/json/0/json.rbs +1963 -0
- data/stdlib/kconv/0/kconv.rbs +166 -0
- data/stdlib/logger/0/formatter.rbs +45 -0
- data/stdlib/logger/0/log_device.rbs +100 -0
- data/stdlib/logger/0/logger.rbs +796 -0
- data/stdlib/logger/0/manifest.yaml +2 -0
- data/stdlib/logger/0/period.rbs +17 -0
- data/stdlib/logger/0/severity.rbs +34 -0
- data/stdlib/minitest/0/kernel.rbs +42 -0
- data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
- data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
- data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
- data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
- data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
- data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
- data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
- data/stdlib/minitest/0/minitest/compress.rbs +13 -0
- data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
- data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
- data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
- data/stdlib/minitest/0/minitest/guard.rbs +64 -0
- data/stdlib/minitest/0/minitest/mock.rbs +64 -0
- data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
- data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
- data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
- data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
- data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
- data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
- data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
- data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
- data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
- data/stdlib/minitest/0/minitest/result.rbs +28 -0
- data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
- data/stdlib/minitest/0/minitest/skip.rbs +6 -0
- data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
- data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
- data/stdlib/minitest/0/minitest/spec.rbs +11 -0
- data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
- data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
- data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
- data/stdlib/minitest/0/minitest/test.rbs +69 -0
- data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
- data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
- data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
- data/stdlib/minitest/0/minitest/unit.rbs +4 -0
- data/stdlib/minitest/0/minitest.rbs +115 -0
- data/stdlib/monitor/0/monitor.rbs +363 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
- data/stdlib/net-http/0/manifest.yaml +3 -0
- data/stdlib/net-http/0/net-http.rbs +5580 -0
- data/stdlib/net-protocol/0/manifest.yaml +2 -0
- data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
- data/stdlib/net-smtp/0/manifest.yaml +2 -0
- data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
- data/stdlib/nkf/0/nkf.rbs +402 -0
- data/stdlib/objspace/0/objspace.rbs +470 -0
- data/stdlib/observable/0/observable.rbs +217 -0
- data/stdlib/open-uri/0/manifest.yaml +4 -0
- data/stdlib/open-uri/0/open-uri.rbs +433 -0
- data/stdlib/open3/0/open3.rbs +606 -0
- data/stdlib/openssl/0/manifest.yaml +3 -0
- data/stdlib/openssl/0/openssl.rbs +12231 -0
- data/stdlib/optparse/0/optparse.rbs +1734 -0
- data/stdlib/pathname/0/pathname.rbs +36 -0
- data/stdlib/pp/0/manifest.yaml +2 -0
- data/stdlib/pp/0/pp.rbs +301 -0
- data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
- data/stdlib/pstore/0/pstore.rbs +608 -0
- data/stdlib/psych/0/core_ext.rbs +12 -0
- data/stdlib/psych/0/dbm.rbs +237 -0
- data/stdlib/psych/0/manifest.yaml +3 -0
- data/stdlib/psych/0/psych.rbs +455 -0
- data/stdlib/psych/0/store.rbs +57 -0
- data/stdlib/pty/0/pty.rbs +240 -0
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +52 -0
- data/stdlib/rdoc/0/comment.rbs +61 -0
- data/stdlib/rdoc/0/context.rbs +153 -0
- data/stdlib/rdoc/0/markup.rbs +117 -0
- data/stdlib/rdoc/0/options.rbs +76 -0
- data/stdlib/rdoc/0/parser.rbs +56 -0
- data/stdlib/rdoc/0/rdoc.rbs +393 -0
- data/stdlib/rdoc/0/ri.rbs +17 -0
- data/stdlib/rdoc/0/store.rbs +48 -0
- data/stdlib/rdoc/0/top_level.rbs +97 -0
- data/stdlib/resolv/0/manifest.yaml +3 -0
- data/stdlib/resolv/0/resolv.rbs +1787 -0
- data/stdlib/ripper/0/ripper.rbs +1654 -0
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +49 -0
- data/stdlib/shellwords/0/shellwords.rbs +229 -0
- data/stdlib/singleton/0/singleton.rbs +134 -0
- data/stdlib/socket/0/addrinfo.rbs +666 -0
- data/stdlib/socket/0/basic_socket.rbs +590 -0
- data/stdlib/socket/0/constants.rbs +2295 -0
- data/stdlib/socket/0/ip_socket.rbs +94 -0
- data/stdlib/socket/0/socket.rbs +4170 -0
- data/stdlib/socket/0/socket_error.rbs +5 -0
- data/stdlib/socket/0/tcp_server.rbs +192 -0
- data/stdlib/socket/0/tcp_socket.rbs +87 -0
- data/stdlib/socket/0/udp_socket.rbs +133 -0
- data/stdlib/socket/0/unix_server.rbs +169 -0
- data/stdlib/socket/0/unix_socket.rbs +172 -0
- data/stdlib/stringio/0/stringio.rbs +1681 -0
- data/stdlib/strscan/0/string_scanner.rbs +1648 -0
- data/stdlib/tempfile/0/tempfile.rbs +483 -0
- data/stdlib/time/0/time.rbs +434 -0
- data/stdlib/timeout/0/timeout.rbs +137 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
- data/stdlib/tsort/0/cyclic.rbs +8 -0
- data/stdlib/tsort/0/interfaces.rbs +20 -0
- data/stdlib/tsort/0/tsort.rbs +410 -0
- data/stdlib/uri/0/common.rbs +621 -0
- data/stdlib/uri/0/file.rbs +118 -0
- data/stdlib/uri/0/ftp.rbs +13 -0
- data/stdlib/uri/0/generic.rbs +1116 -0
- data/stdlib/uri/0/http.rbs +104 -0
- data/stdlib/uri/0/https.rbs +14 -0
- data/stdlib/uri/0/ldap.rbs +230 -0
- data/stdlib/uri/0/ldaps.rbs +14 -0
- data/stdlib/uri/0/mailto.rbs +92 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
- data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
- data/stdlib/uri/0/ws.rbs +13 -0
- data/stdlib/uri/0/wss.rbs +9 -0
- data/stdlib/yaml/0/manifest.yaml +2 -0
- data/stdlib/yaml/0/yaml.rbs +1 -0
- data/stdlib/zlib/0/buf_error.rbs +10 -0
- data/stdlib/zlib/0/data_error.rbs +10 -0
- data/stdlib/zlib/0/deflate.rbs +211 -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 +168 -0
- data/stdlib/zlib/0/inflate.rbs +180 -0
- data/stdlib/zlib/0/mem_error.rbs +10 -0
- data/stdlib/zlib/0/need_dict.rbs +13 -0
- data/stdlib/zlib/0/stream_end.rbs +11 -0
- data/stdlib/zlib/0/stream_error.rbs +11 -0
- data/stdlib/zlib/0/version_error.rbs +11 -0
- data/stdlib/zlib/0/zlib.rbs +449 -0
- data/stdlib/zlib/0/zstream.rbs +201 -0
- data/wasm/README.md +59 -0
- data/wasm/rbs_wasm.c +411 -0
- metadata +660 -0
data/core/file.rbs
ADDED
|
@@ -0,0 +1,2045 @@
|
|
|
1
|
+
# <!-- rdoc-file=file.c -->
|
|
2
|
+
# A File object is a representation of a file in the underlying platform.
|
|
3
|
+
#
|
|
4
|
+
# Class File extends module FileTest, supporting such singleton methods as
|
|
5
|
+
# <code>File.exist?</code>.
|
|
6
|
+
#
|
|
7
|
+
# ## About the Examples
|
|
8
|
+
#
|
|
9
|
+
# Many examples here use these variables:
|
|
10
|
+
#
|
|
11
|
+
# # English text with newlines.
|
|
12
|
+
# text = <<~EOT
|
|
13
|
+
# First line
|
|
14
|
+
# Second line
|
|
15
|
+
#
|
|
16
|
+
# Fourth line
|
|
17
|
+
# Fifth line
|
|
18
|
+
# EOT
|
|
19
|
+
#
|
|
20
|
+
# # Russian text.
|
|
21
|
+
# russian = "\u{442 435 441 442}" # => "тест"
|
|
22
|
+
#
|
|
23
|
+
# # Binary data.
|
|
24
|
+
# data = "\u9990\u9991\u9992\u9993\u9994"
|
|
25
|
+
#
|
|
26
|
+
# # Text file.
|
|
27
|
+
# File.write('t.txt', text)
|
|
28
|
+
#
|
|
29
|
+
# # File with Russian text.
|
|
30
|
+
# File.write('t.rus', russian)
|
|
31
|
+
#
|
|
32
|
+
# # File with binary data.
|
|
33
|
+
# f = File.new('t.dat', 'wb:UTF-16')
|
|
34
|
+
# f.write(data)
|
|
35
|
+
# f.close
|
|
36
|
+
#
|
|
37
|
+
# ## Access Modes
|
|
38
|
+
#
|
|
39
|
+
# Methods File.new and File.open each create a File object for a given file
|
|
40
|
+
# path.
|
|
41
|
+
#
|
|
42
|
+
# ### String Access Modes
|
|
43
|
+
#
|
|
44
|
+
# Methods File.new and File.open each may take string argument `mode`, which:
|
|
45
|
+
#
|
|
46
|
+
# * Begins with a 1- or 2-character [read/write
|
|
47
|
+
# mode](rdoc-ref:File@Read-2FWrite+Mode).
|
|
48
|
+
# * May also contain a 1-character [data mode](rdoc-ref:File@Data+Mode).
|
|
49
|
+
# * May also contain a 1-character [file-create
|
|
50
|
+
# mode](rdoc-ref:File@File-Create+Mode).
|
|
51
|
+
#
|
|
52
|
+
# #### Read/Write Mode
|
|
53
|
+
#
|
|
54
|
+
# The read/write `mode` determines:
|
|
55
|
+
#
|
|
56
|
+
# * Whether the file is to be initially truncated.
|
|
57
|
+
#
|
|
58
|
+
# * Whether reading is allowed, and if so:
|
|
59
|
+
#
|
|
60
|
+
# * The initial read position in the file.
|
|
61
|
+
# * Where in the file reading can occur.
|
|
62
|
+
#
|
|
63
|
+
# * Whether writing is allowed, and if so:
|
|
64
|
+
#
|
|
65
|
+
# * The initial write position in the file.
|
|
66
|
+
# * Where in the file writing can occur.
|
|
67
|
+
#
|
|
68
|
+
# These tables summarize:
|
|
69
|
+
#
|
|
70
|
+
# Read/Write Modes for Existing File
|
|
71
|
+
#
|
|
72
|
+
# |------|-----------|----------|----------|----------|-----------|
|
|
73
|
+
# | R/W | Initial | | Initial | | Initial |
|
|
74
|
+
# | Mode | Truncate? | Read | Read Pos | Write | Write Pos |
|
|
75
|
+
# |------|-----------|----------|----------|----------|-----------|
|
|
76
|
+
# | 'r' | No | Anywhere | 0 | Error | - |
|
|
77
|
+
# | 'w' | Yes | Error | - | Anywhere | 0 |
|
|
78
|
+
# | 'a' | No | Error | - | End only | End |
|
|
79
|
+
# | 'r+' | No | Anywhere | 0 | Anywhere | 0 |
|
|
80
|
+
# | 'w+' | Yes | Anywhere | 0 | Anywhere | 0 |
|
|
81
|
+
# | 'a+' | No | Anywhere | End | End only | End |
|
|
82
|
+
# |------|-----------|----------|----------|----------|-----------|
|
|
83
|
+
#
|
|
84
|
+
# Read/Write Modes for \File To Be Created
|
|
85
|
+
#
|
|
86
|
+
# |------|----------|----------|----------|-----------|
|
|
87
|
+
# | R/W | | Initial | | Initial |
|
|
88
|
+
# | Mode | Read | Read Pos | Write | Write Pos |
|
|
89
|
+
# |------|----------|----------|----------|-----------|
|
|
90
|
+
# | 'w' | Error | - | Anywhere | 0 |
|
|
91
|
+
# | 'a' | Error | - | End only | 0 |
|
|
92
|
+
# | 'w+' | Anywhere | 0 | Anywhere | 0 |
|
|
93
|
+
# | 'a+' | Anywhere | 0 | End only | End |
|
|
94
|
+
# |------|----------|----------|----------|-----------|
|
|
95
|
+
#
|
|
96
|
+
# Note that modes <code>'r'</code> and <code>'r+'</code> are not allowed for a
|
|
97
|
+
# non-existent file (exception raised).
|
|
98
|
+
#
|
|
99
|
+
# In the tables:
|
|
100
|
+
#
|
|
101
|
+
# * `Anywhere` means that methods IO#rewind, IO#pos=, and IO#seek may be used
|
|
102
|
+
# to change the file's position, so that allowed reading or writing may
|
|
103
|
+
# occur anywhere in the file.
|
|
104
|
+
# * `End only` means that writing can occur only at end-of-file, and that
|
|
105
|
+
# methods IO#rewind, IO#pos=, and IO#seek do not affect writing.
|
|
106
|
+
# * `Error` means that an exception is raised if disallowed reading or writing
|
|
107
|
+
# is attempted.
|
|
108
|
+
#
|
|
109
|
+
# ##### Read/Write Modes for Existing File
|
|
110
|
+
#
|
|
111
|
+
# * <code>'r'</code>:
|
|
112
|
+
#
|
|
113
|
+
# * File is not initially truncated:
|
|
114
|
+
#
|
|
115
|
+
# f = File.new('t.txt') # => #<File:t.txt>
|
|
116
|
+
# f.size == 0 # => false
|
|
117
|
+
#
|
|
118
|
+
# * File's initial read position is 0:
|
|
119
|
+
#
|
|
120
|
+
# f.pos # => 0
|
|
121
|
+
#
|
|
122
|
+
# * File may be read anywhere; see IO#rewind, IO#pos=, IO#seek:
|
|
123
|
+
#
|
|
124
|
+
# f.readline # => "First line\n"
|
|
125
|
+
# f.readline # => "Second line\n"
|
|
126
|
+
#
|
|
127
|
+
# f.rewind
|
|
128
|
+
# f.readline # => "First line\n"
|
|
129
|
+
#
|
|
130
|
+
# f.pos = 1
|
|
131
|
+
# f.readline # => "irst line\n"
|
|
132
|
+
#
|
|
133
|
+
# f.seek(1, :CUR)
|
|
134
|
+
# f.readline # => "econd line\n"
|
|
135
|
+
#
|
|
136
|
+
# * Writing is not allowed:
|
|
137
|
+
#
|
|
138
|
+
# f.write('foo') # Raises IOError.
|
|
139
|
+
#
|
|
140
|
+
# * <code>'w'</code>:
|
|
141
|
+
#
|
|
142
|
+
# * File is initially truncated:
|
|
143
|
+
#
|
|
144
|
+
# path = 't.tmp'
|
|
145
|
+
# File.write(path, text)
|
|
146
|
+
# f = File.new(path, 'w')
|
|
147
|
+
# f.size == 0 # => true
|
|
148
|
+
#
|
|
149
|
+
# * File's initial write position is 0:
|
|
150
|
+
#
|
|
151
|
+
# f.pos # => 0
|
|
152
|
+
#
|
|
153
|
+
# * File may be written anywhere (even past end-of-file); see IO#rewind,
|
|
154
|
+
# IO#pos=, IO#seek:
|
|
155
|
+
#
|
|
156
|
+
# f.write('foo')
|
|
157
|
+
# f.flush
|
|
158
|
+
# File.read(path) # => "foo"
|
|
159
|
+
# f.pos # => 3
|
|
160
|
+
#
|
|
161
|
+
# f.write('bar')
|
|
162
|
+
# f.flush
|
|
163
|
+
# File.read(path) # => "foobar"
|
|
164
|
+
# f.pos # => 6
|
|
165
|
+
#
|
|
166
|
+
# f.rewind
|
|
167
|
+
# f.write('baz')
|
|
168
|
+
# f.flush
|
|
169
|
+
# File.read(path) # => "bazbar"
|
|
170
|
+
# f.pos # => 3
|
|
171
|
+
#
|
|
172
|
+
# f.pos = 3
|
|
173
|
+
# f.write('foo')
|
|
174
|
+
# f.flush
|
|
175
|
+
# File.read(path) # => "bazfoo"
|
|
176
|
+
# f.pos # => 6
|
|
177
|
+
#
|
|
178
|
+
# f.seek(-3, :END)
|
|
179
|
+
# f.write('bam')
|
|
180
|
+
# f.flush
|
|
181
|
+
# File.read(path) # => "bazbam"
|
|
182
|
+
# f.pos # => 6
|
|
183
|
+
#
|
|
184
|
+
# f.pos = 8
|
|
185
|
+
# f.write('bah') # Zero padding as needed.
|
|
186
|
+
# f.flush
|
|
187
|
+
# File.read(path) # => "bazbam\u0000\u0000bah"
|
|
188
|
+
# f.pos # => 11
|
|
189
|
+
#
|
|
190
|
+
# * Reading is not allowed:
|
|
191
|
+
#
|
|
192
|
+
# f.read # Raises IOError.
|
|
193
|
+
#
|
|
194
|
+
# * <code>'a'</code>:
|
|
195
|
+
#
|
|
196
|
+
# * File is not initially truncated:
|
|
197
|
+
#
|
|
198
|
+
# path = 't.tmp'
|
|
199
|
+
# File.write(path, 'foo')
|
|
200
|
+
# f = File.new(path, 'a')
|
|
201
|
+
# f.size == 0 # => false
|
|
202
|
+
#
|
|
203
|
+
# * File's initial position is 0 (but is ignored):
|
|
204
|
+
#
|
|
205
|
+
# f.pos # => 0
|
|
206
|
+
#
|
|
207
|
+
# * File may be written only at end-of-file; IO#rewind, IO#pos=, IO#seek
|
|
208
|
+
# do not affect writing:
|
|
209
|
+
#
|
|
210
|
+
# f.write('bar')
|
|
211
|
+
# f.flush
|
|
212
|
+
# File.read(path) # => "foobar"
|
|
213
|
+
# f.write('baz')
|
|
214
|
+
# f.flush
|
|
215
|
+
# File.read(path) # => "foobarbaz"
|
|
216
|
+
#
|
|
217
|
+
# f.rewind
|
|
218
|
+
# f.write('bat')
|
|
219
|
+
# f.flush
|
|
220
|
+
# File.read(path) # => "foobarbazbat"
|
|
221
|
+
#
|
|
222
|
+
# * Reading is not allowed:
|
|
223
|
+
#
|
|
224
|
+
# f.read # Raises IOError.
|
|
225
|
+
#
|
|
226
|
+
# * <code>'r+'</code>:
|
|
227
|
+
#
|
|
228
|
+
# * File is not initially truncated:
|
|
229
|
+
#
|
|
230
|
+
# path = 't.tmp'
|
|
231
|
+
# File.write(path, text)
|
|
232
|
+
# f = File.new(path, 'r+')
|
|
233
|
+
# f.size == 0 # => false
|
|
234
|
+
#
|
|
235
|
+
# * File's initial read position is 0:
|
|
236
|
+
#
|
|
237
|
+
# f.pos # => 0
|
|
238
|
+
#
|
|
239
|
+
# * File may be read or written anywhere (even past end-of-file); see
|
|
240
|
+
# IO#rewind, IO#pos=, IO#seek:
|
|
241
|
+
#
|
|
242
|
+
# f.readline # => "First line\n"
|
|
243
|
+
# f.readline # => "Second line\n"
|
|
244
|
+
#
|
|
245
|
+
# f.rewind
|
|
246
|
+
# f.readline # => "First line\n"
|
|
247
|
+
#
|
|
248
|
+
# f.pos = 1
|
|
249
|
+
# f.readline # => "irst line\n"
|
|
250
|
+
#
|
|
251
|
+
# f.seek(1, :CUR)
|
|
252
|
+
# f.readline # => "econd line\n"
|
|
253
|
+
#
|
|
254
|
+
# f.rewind
|
|
255
|
+
# f.write('WWW')
|
|
256
|
+
# f.flush
|
|
257
|
+
# File.read(path)
|
|
258
|
+
# # => "WWWst line\nSecond line\nFourth line\nFifth line\n"
|
|
259
|
+
#
|
|
260
|
+
# f.pos = 10
|
|
261
|
+
# f.write('XXX')
|
|
262
|
+
# f.flush
|
|
263
|
+
# File.read(path)
|
|
264
|
+
# # => "WWWst lineXXXecond line\nFourth line\nFifth line\n"
|
|
265
|
+
#
|
|
266
|
+
# f.seek(-6, :END)
|
|
267
|
+
# # => 0
|
|
268
|
+
# f.write('YYY')
|
|
269
|
+
# # => 3
|
|
270
|
+
# f.flush
|
|
271
|
+
# # => #<File:t.tmp>
|
|
272
|
+
# File.read(path)
|
|
273
|
+
# # => "WWWst lineXXXecond line\nFourth line\nFifth YYYe\n"
|
|
274
|
+
#
|
|
275
|
+
# f.seek(2, :END)
|
|
276
|
+
# f.write('ZZZ') # Zero padding as needed.
|
|
277
|
+
# f.flush
|
|
278
|
+
# File.read(path)
|
|
279
|
+
# # => "WWWst lineXXXecond line\nFourth line\nFifth YYYe\n\u0000\u0000ZZZ"
|
|
280
|
+
#
|
|
281
|
+
# * <code>'a+'</code>:
|
|
282
|
+
#
|
|
283
|
+
# * File is not initially truncated:
|
|
284
|
+
#
|
|
285
|
+
# path = 't.tmp'
|
|
286
|
+
# File.write(path, 'foo')
|
|
287
|
+
# f = File.new(path, 'a+')
|
|
288
|
+
# f.size == 0 # => false
|
|
289
|
+
#
|
|
290
|
+
# * File's initial read position is 0:
|
|
291
|
+
#
|
|
292
|
+
# f.pos # => 0
|
|
293
|
+
#
|
|
294
|
+
# * File may be written only at end-of-file; IO#rewind, IO#pos=, IO#seek
|
|
295
|
+
# do not affect writing:
|
|
296
|
+
#
|
|
297
|
+
# f.write('bar')
|
|
298
|
+
# f.flush
|
|
299
|
+
# File.read(path) # => "foobar"
|
|
300
|
+
# f.write('baz')
|
|
301
|
+
# f.flush
|
|
302
|
+
# File.read(path) # => "foobarbaz"
|
|
303
|
+
#
|
|
304
|
+
# f.rewind
|
|
305
|
+
# f.write('bat')
|
|
306
|
+
# f.flush
|
|
307
|
+
# File.read(path) # => "foobarbazbat"
|
|
308
|
+
#
|
|
309
|
+
# * File may be read anywhere; see IO#rewind, IO#pos=, IO#seek:
|
|
310
|
+
#
|
|
311
|
+
# f.rewind
|
|
312
|
+
# f.read # => "foobarbazbat"
|
|
313
|
+
#
|
|
314
|
+
# f.pos = 3
|
|
315
|
+
# f.read # => "barbazbat"
|
|
316
|
+
#
|
|
317
|
+
# f.seek(-3, :END)
|
|
318
|
+
# f.read # => "bat"
|
|
319
|
+
#
|
|
320
|
+
# ##### Read/Write Modes for File To Be Created
|
|
321
|
+
#
|
|
322
|
+
# Note that modes <code>'r'</code> and <code>'r+'</code> are not allowed for a
|
|
323
|
+
# non-existent file (exception raised).
|
|
324
|
+
#
|
|
325
|
+
# * <code>'w'</code>:
|
|
326
|
+
#
|
|
327
|
+
# * File's initial write position is 0:
|
|
328
|
+
#
|
|
329
|
+
# path = 't.tmp'
|
|
330
|
+
# FileUtils.rm_f(path)
|
|
331
|
+
# f = File.new(path, 'w')
|
|
332
|
+
# f.pos # => 0
|
|
333
|
+
#
|
|
334
|
+
# * File may be written anywhere (even past end-of-file); see IO#rewind,
|
|
335
|
+
# IO#pos=, IO#seek:
|
|
336
|
+
#
|
|
337
|
+
# f.write('foo')
|
|
338
|
+
# f.flush
|
|
339
|
+
# File.read(path) # => "foo"
|
|
340
|
+
# f.pos # => 3
|
|
341
|
+
#
|
|
342
|
+
# f.write('bar')
|
|
343
|
+
# f.flush
|
|
344
|
+
# File.read(path) # => "foobar"
|
|
345
|
+
# f.pos # => 6
|
|
346
|
+
#
|
|
347
|
+
# f.rewind
|
|
348
|
+
# f.write('baz')
|
|
349
|
+
# f.flush
|
|
350
|
+
# File.read(path) # => "bazbar"
|
|
351
|
+
# f.pos # => 3
|
|
352
|
+
#
|
|
353
|
+
# f.pos = 3
|
|
354
|
+
# f.write('foo')
|
|
355
|
+
# f.flush
|
|
356
|
+
# File.read(path) # => "bazfoo"
|
|
357
|
+
# f.pos # => 6
|
|
358
|
+
#
|
|
359
|
+
# f.seek(-3, :END)
|
|
360
|
+
# f.write('bam')
|
|
361
|
+
# f.flush
|
|
362
|
+
# File.read(path) # => "bazbam"
|
|
363
|
+
# f.pos # => 6
|
|
364
|
+
#
|
|
365
|
+
# f.pos = 8
|
|
366
|
+
# f.write('bah') # Zero padding as needed.
|
|
367
|
+
# f.flush
|
|
368
|
+
# File.read(path) # => "bazbam\u0000\u0000bah"
|
|
369
|
+
# f.pos # => 11
|
|
370
|
+
#
|
|
371
|
+
# * Reading is not allowed:
|
|
372
|
+
#
|
|
373
|
+
# f.read # Raises IOError.
|
|
374
|
+
#
|
|
375
|
+
# * <code>'a'</code>:
|
|
376
|
+
#
|
|
377
|
+
# * File's initial write position is 0:
|
|
378
|
+
#
|
|
379
|
+
# path = 't.tmp'
|
|
380
|
+
# FileUtils.rm_f(path)
|
|
381
|
+
# f = File.new(path, 'a')
|
|
382
|
+
# f.pos # => 0
|
|
383
|
+
#
|
|
384
|
+
# * Writing occurs only at end-of-file:
|
|
385
|
+
#
|
|
386
|
+
# f.write('foo')
|
|
387
|
+
# f.pos # => 3
|
|
388
|
+
# f.write('bar')
|
|
389
|
+
# f.pos # => 6
|
|
390
|
+
# f.flush
|
|
391
|
+
# File.read(path) # => "foobar"
|
|
392
|
+
#
|
|
393
|
+
# f.rewind
|
|
394
|
+
# f.write('baz')
|
|
395
|
+
# f.flush
|
|
396
|
+
# File.read(path) # => "foobarbaz"
|
|
397
|
+
#
|
|
398
|
+
# * Reading is not allowed:
|
|
399
|
+
#
|
|
400
|
+
# f.read # Raises IOError.
|
|
401
|
+
#
|
|
402
|
+
# * <code>'w+'</code>:
|
|
403
|
+
#
|
|
404
|
+
# * File's initial position is 0:
|
|
405
|
+
#
|
|
406
|
+
# path = 't.tmp'
|
|
407
|
+
# FileUtils.rm_f(path)
|
|
408
|
+
# f = File.new(path, 'w+')
|
|
409
|
+
# f.pos # => 0
|
|
410
|
+
#
|
|
411
|
+
# * File may be written anywhere (even past end-of-file); see IO#rewind,
|
|
412
|
+
# IO#pos=, IO#seek:
|
|
413
|
+
#
|
|
414
|
+
# f.write('foo')
|
|
415
|
+
# f.flush
|
|
416
|
+
# File.read(path) # => "foo"
|
|
417
|
+
# f.pos # => 3
|
|
418
|
+
#
|
|
419
|
+
# f.write('bar')
|
|
420
|
+
# f.flush
|
|
421
|
+
# File.read(path) # => "foobar"
|
|
422
|
+
# f.pos # => 6
|
|
423
|
+
#
|
|
424
|
+
# f.rewind
|
|
425
|
+
# f.write('baz')
|
|
426
|
+
# f.flush
|
|
427
|
+
# File.read(path) # => "bazbar"
|
|
428
|
+
# f.pos # => 3
|
|
429
|
+
#
|
|
430
|
+
# f.pos = 3
|
|
431
|
+
# f.write('foo')
|
|
432
|
+
# f.flush
|
|
433
|
+
# File.read(path) # => "bazfoo"
|
|
434
|
+
# f.pos # => 6
|
|
435
|
+
#
|
|
436
|
+
# f.seek(-3, :END)
|
|
437
|
+
# f.write('bam')
|
|
438
|
+
# f.flush
|
|
439
|
+
# File.read(path) # => "bazbam"
|
|
440
|
+
# f.pos # => 6
|
|
441
|
+
#
|
|
442
|
+
# f.pos = 8
|
|
443
|
+
# f.write('bah') # Zero padding as needed.
|
|
444
|
+
# f.flush
|
|
445
|
+
# File.read(path) # => "bazbam\u0000\u0000bah"
|
|
446
|
+
# f.pos # => 11
|
|
447
|
+
#
|
|
448
|
+
# * File may be read anywhere (even past end-of-file); see IO#rewind,
|
|
449
|
+
# IO#pos=, IO#seek:
|
|
450
|
+
#
|
|
451
|
+
# f.rewind
|
|
452
|
+
# # => 0
|
|
453
|
+
# f.read
|
|
454
|
+
# # => "bazbam\u0000\u0000bah"
|
|
455
|
+
#
|
|
456
|
+
# f.pos = 3
|
|
457
|
+
# # => 3
|
|
458
|
+
# f.read
|
|
459
|
+
# # => "bam\u0000\u0000bah"
|
|
460
|
+
#
|
|
461
|
+
# f.seek(-3, :END)
|
|
462
|
+
# # => 0
|
|
463
|
+
# f.read
|
|
464
|
+
# # => "bah"
|
|
465
|
+
#
|
|
466
|
+
# * <code>'a+'</code>:
|
|
467
|
+
#
|
|
468
|
+
# * File's initial write position is 0:
|
|
469
|
+
#
|
|
470
|
+
# path = 't.tmp'
|
|
471
|
+
# FileUtils.rm_f(path)
|
|
472
|
+
# f = File.new(path, 'a+')
|
|
473
|
+
# f.pos # => 0
|
|
474
|
+
#
|
|
475
|
+
# * Writing occurs only at end-of-file:
|
|
476
|
+
#
|
|
477
|
+
# f.write('foo')
|
|
478
|
+
# f.pos # => 3
|
|
479
|
+
# f.write('bar')
|
|
480
|
+
# f.pos # => 6
|
|
481
|
+
# f.flush
|
|
482
|
+
# File.read(path) # => "foobar"
|
|
483
|
+
#
|
|
484
|
+
# f.rewind
|
|
485
|
+
# f.write('baz')
|
|
486
|
+
# f.flush
|
|
487
|
+
# File.read(path) # => "foobarbaz"
|
|
488
|
+
#
|
|
489
|
+
# * File may be read anywhere (even past end-of-file); see IO#rewind,
|
|
490
|
+
# IO#pos=, IO#seek:
|
|
491
|
+
#
|
|
492
|
+
# f.rewind
|
|
493
|
+
# f.read # => "foobarbaz"
|
|
494
|
+
#
|
|
495
|
+
# f.pos = 3
|
|
496
|
+
# f.read # => "barbaz"
|
|
497
|
+
#
|
|
498
|
+
# f.seek(-3, :END)
|
|
499
|
+
# f.read # => "baz"
|
|
500
|
+
#
|
|
501
|
+
# f.pos = 800
|
|
502
|
+
# f.read # => ""
|
|
503
|
+
#
|
|
504
|
+
# #### Data Mode
|
|
505
|
+
#
|
|
506
|
+
# To specify whether data is to be treated as text or as binary data, either of
|
|
507
|
+
# the following may be suffixed to any of the string read/write modes above:
|
|
508
|
+
#
|
|
509
|
+
# * <code>'t'</code>: Text data; sets the default external encoding to
|
|
510
|
+
# <code>Encoding::UTF_8</code>; on Windows, enables conversion between EOL
|
|
511
|
+
# and CRLF and enables interpreting `0x1A` as an end-of-file marker.
|
|
512
|
+
# * <code>'b'</code>: Binary data; sets the default external encoding to
|
|
513
|
+
# <code>Encoding::ASCII_8BIT</code>; on Windows, suppresses conversion
|
|
514
|
+
# between EOL and CRLF and disables interpreting `0x1A` as an end-of-file
|
|
515
|
+
# marker.
|
|
516
|
+
#
|
|
517
|
+
# If neither is given, the stream defaults to text data.
|
|
518
|
+
#
|
|
519
|
+
# Examples:
|
|
520
|
+
#
|
|
521
|
+
# File.new('t.txt', 'rt')
|
|
522
|
+
# File.new('t.dat', 'rb')
|
|
523
|
+
#
|
|
524
|
+
# When the data mode is specified, the read/write mode may not be omitted, and
|
|
525
|
+
# the data mode must precede the file-create mode, if given:
|
|
526
|
+
#
|
|
527
|
+
# File.new('t.dat', 'b') # Raises an exception.
|
|
528
|
+
# File.new('t.dat', 'rxb') # Raises an exception.
|
|
529
|
+
#
|
|
530
|
+
# #### File-Create Mode
|
|
531
|
+
#
|
|
532
|
+
# The following may be suffixed to any writable string mode above:
|
|
533
|
+
#
|
|
534
|
+
# * <code>'x'</code>: Creates the file if it does not exist; raises an
|
|
535
|
+
# exception if the file exists.
|
|
536
|
+
#
|
|
537
|
+
# Example:
|
|
538
|
+
#
|
|
539
|
+
# File.new('t.tmp', 'wx')
|
|
540
|
+
#
|
|
541
|
+
# When the file-create mode is specified, the read/write mode may not be
|
|
542
|
+
# omitted, and the file-create mode must follow the data mode:
|
|
543
|
+
#
|
|
544
|
+
# File.new('t.dat', 'x') # Raises an exception.
|
|
545
|
+
# File.new('t.dat', 'rxb') # Raises an exception.
|
|
546
|
+
#
|
|
547
|
+
# ### Integer Access Modes
|
|
548
|
+
#
|
|
549
|
+
# When mode is an integer it must be one or more of the following constants,
|
|
550
|
+
# which may be combined by the bitwise OR operator <code>|</code>:
|
|
551
|
+
#
|
|
552
|
+
# * <code>File::RDONLY</code>: Open for reading only.
|
|
553
|
+
# * <code>File::WRONLY</code>: Open for writing only.
|
|
554
|
+
# * <code>File::RDWR</code>: Open for reading and writing.
|
|
555
|
+
# * <code>File::APPEND</code>: Open for appending only.
|
|
556
|
+
#
|
|
557
|
+
# Examples:
|
|
558
|
+
#
|
|
559
|
+
# File.new('t.txt', File::RDONLY)
|
|
560
|
+
# File.new('t.tmp', File::RDWR | File::CREAT | File::EXCL)
|
|
561
|
+
#
|
|
562
|
+
# Note: Method IO#set_encoding does not allow the mode to be specified as an
|
|
563
|
+
# integer.
|
|
564
|
+
#
|
|
565
|
+
# ### File-Create Mode Specified as an Integer
|
|
566
|
+
#
|
|
567
|
+
# These constants may also be ORed into the integer mode:
|
|
568
|
+
#
|
|
569
|
+
# * <code>File::CREAT</code>: Create file if it does not exist.
|
|
570
|
+
# * <code>File::EXCL</code>: Raise an exception if <code>File::CREAT</code> is
|
|
571
|
+
# given and the file exists.
|
|
572
|
+
#
|
|
573
|
+
# ### Data Mode Specified as an Integer
|
|
574
|
+
#
|
|
575
|
+
# Data mode cannot be specified as an integer. When the stream access mode is
|
|
576
|
+
# given as an integer, the data mode is always text, never binary.
|
|
577
|
+
#
|
|
578
|
+
# Note that although there is a constant <code>File::BINARY</code>, setting its
|
|
579
|
+
# value in an integer stream mode has no effect; this is because, as documented
|
|
580
|
+
# in File::Constants, the <code>File::BINARY</code> value disables line code
|
|
581
|
+
# conversion, but does not change the external encoding.
|
|
582
|
+
#
|
|
583
|
+
# ### Encodings
|
|
584
|
+
#
|
|
585
|
+
# Any of the string modes above may specify encodings - either external encoding
|
|
586
|
+
# only or both external and internal encodings - by appending one or both
|
|
587
|
+
# encoding names, separated by colons:
|
|
588
|
+
#
|
|
589
|
+
# f = File.new('t.dat', 'rb')
|
|
590
|
+
# f.external_encoding # => #<Encoding:ASCII-8BIT>
|
|
591
|
+
# f.internal_encoding # => nil
|
|
592
|
+
# f = File.new('t.dat', 'rb:UTF-16')
|
|
593
|
+
# f.external_encoding # => #<Encoding:UTF-16 (dummy)>
|
|
594
|
+
# f.internal_encoding # => nil
|
|
595
|
+
# f = File.new('t.dat', 'rb:UTF-16:UTF-16')
|
|
596
|
+
# f.external_encoding # => #<Encoding:UTF-16 (dummy)>
|
|
597
|
+
# f.internal_encoding # => #<Encoding:UTF-16>
|
|
598
|
+
# f.close
|
|
599
|
+
#
|
|
600
|
+
# The numerous encoding names are available in array Encoding.name_list:
|
|
601
|
+
#
|
|
602
|
+
# Encoding.name_list.take(3) # => ["ASCII-8BIT", "UTF-8", "US-ASCII"]
|
|
603
|
+
#
|
|
604
|
+
# When the external encoding is set, strings read are tagged by that encoding
|
|
605
|
+
# when reading, and strings written are converted to that encoding when writing.
|
|
606
|
+
#
|
|
607
|
+
# When both external and internal encodings are set, strings read are converted
|
|
608
|
+
# from external to internal encoding, and strings written are converted from
|
|
609
|
+
# internal to external encoding. For further details about transcoding input and
|
|
610
|
+
# output, see [Encodings](rdoc-ref:encodings.rdoc@Encodings).
|
|
611
|
+
#
|
|
612
|
+
# If the external encoding is <code>'BOM|UTF-8'</code>,
|
|
613
|
+
# <code>'BOM|UTF-16LE'</code> or <code>'BOM|UTF16-BE'</code>, Ruby checks for a
|
|
614
|
+
# Unicode BOM in the input document to help determine the encoding. For UTF-16
|
|
615
|
+
# encodings the file open mode must be binary. If the BOM is found, it is
|
|
616
|
+
# stripped and the external encoding from the BOM is used.
|
|
617
|
+
#
|
|
618
|
+
# Note that the BOM-style encoding option is case insensitive, so
|
|
619
|
+
# <code>'bom|utf-8'</code> is also valid.
|
|
620
|
+
#
|
|
621
|
+
# ## File Permissions
|
|
622
|
+
#
|
|
623
|
+
# A File object has *permissions*, an octal integer representing the permissions
|
|
624
|
+
# of an actual file in the underlying platform.
|
|
625
|
+
#
|
|
626
|
+
# Note that file permissions are quite different from the *mode* of a file
|
|
627
|
+
# stream (File object).
|
|
628
|
+
#
|
|
629
|
+
# In a File object, the permissions are available thus, where method `mode`,
|
|
630
|
+
# despite its name, returns permissions:
|
|
631
|
+
#
|
|
632
|
+
# f = File.new('t.txt')
|
|
633
|
+
# f.lstat.mode.to_s(8) # => "100644"
|
|
634
|
+
#
|
|
635
|
+
# On a Unix-based operating system, the three low-order octal digits represent
|
|
636
|
+
# the permissions for owner (6), group (4), and world (4). The triplet of bits
|
|
637
|
+
# in each octal digit represent, respectively, read, write, and execute
|
|
638
|
+
# permissions.
|
|
639
|
+
#
|
|
640
|
+
# Permissions `0644` thus represent read-write access for owner and read-only
|
|
641
|
+
# access for group and world. See man pages
|
|
642
|
+
# [open(2)](https://www.unix.com/man-page/bsd/2/open) and
|
|
643
|
+
# [chmod(2)](https://www.unix.com/man-page/bsd/2/chmod).
|
|
644
|
+
#
|
|
645
|
+
# For a directory, the meaning of the execute bit changes: when set, the
|
|
646
|
+
# directory can be searched.
|
|
647
|
+
#
|
|
648
|
+
# Higher-order bits in permissions may indicate the type of file (plain,
|
|
649
|
+
# directory, pipe, socket, etc.) and various other special features.
|
|
650
|
+
#
|
|
651
|
+
# On non-Posix operating systems, permissions may include only read-only or
|
|
652
|
+
# read-write, in which case, the remaining permission will resemble typical
|
|
653
|
+
# values. On Windows, for instance, the default permissions are `0644`; The only
|
|
654
|
+
# change that can be made is to make the file read-only, which is reported as
|
|
655
|
+
# `0444`.
|
|
656
|
+
#
|
|
657
|
+
# For a method that actually creates a file in the underlying platform (as
|
|
658
|
+
# opposed to merely creating a File object), permissions may be specified:
|
|
659
|
+
#
|
|
660
|
+
# File.new('t.tmp', File::CREAT, 0644)
|
|
661
|
+
# File.new('t.tmp', File::CREAT, 0444)
|
|
662
|
+
#
|
|
663
|
+
# Permissions may also be changed:
|
|
664
|
+
#
|
|
665
|
+
# f = File.new('t.tmp', File::CREAT, 0444)
|
|
666
|
+
# f.chmod(0644)
|
|
667
|
+
# f.chmod(0444)
|
|
668
|
+
#
|
|
669
|
+
# ## File Constants
|
|
670
|
+
#
|
|
671
|
+
# Various constants for use in File and IO methods may be found in module
|
|
672
|
+
# File::Constants; an array of their names is returned by
|
|
673
|
+
# <code>File::Constants.constants</code>.
|
|
674
|
+
#
|
|
675
|
+
# ## What's Here
|
|
676
|
+
#
|
|
677
|
+
# First, what's elsewhere. Class File:
|
|
678
|
+
#
|
|
679
|
+
# * Inherits from [class IO](rdoc-ref:IO@What-27s+Here), in particular,
|
|
680
|
+
# methods for creating, reading, and writing files
|
|
681
|
+
# * Includes module FileTest, which provides dozens of additional methods.
|
|
682
|
+
#
|
|
683
|
+
# Here, class File provides methods that are useful for:
|
|
684
|
+
#
|
|
685
|
+
# * [Creating](rdoc-ref:File@Creating)
|
|
686
|
+
# * [Querying](rdoc-ref:File@Querying)
|
|
687
|
+
# * [Settings](rdoc-ref:File@Settings)
|
|
688
|
+
# * [Other](rdoc-ref:File@Other)
|
|
689
|
+
#
|
|
690
|
+
# ### Creating
|
|
691
|
+
#
|
|
692
|
+
# * ::new: Opens the file at the given path; returns the file.
|
|
693
|
+
# * ::open: Same as ::new, but when given a block will yield the file to the
|
|
694
|
+
# block, and close the file upon exiting the block.
|
|
695
|
+
# * ::link: Creates a new name for an existing file using a hard link.
|
|
696
|
+
# * ::mkfifo: Returns the FIFO file created at the given path.
|
|
697
|
+
# * ::symlink: Creates a symbolic link for the given file path.
|
|
698
|
+
#
|
|
699
|
+
# ### Querying
|
|
700
|
+
#
|
|
701
|
+
# *Paths*
|
|
702
|
+
#
|
|
703
|
+
# * ::absolute_path: Returns the absolute file path for the given path.
|
|
704
|
+
# * ::absolute_path?: Returns whether the given path is the absolute file
|
|
705
|
+
# path.
|
|
706
|
+
# * ::basename: Returns the last component of the given file path.
|
|
707
|
+
# * ::dirname: Returns all but the last component of the given file path.
|
|
708
|
+
# * ::expand_path: Returns the absolute file path for the given path,
|
|
709
|
+
# expanding <code>~</code> for a home directory.
|
|
710
|
+
# * ::extname: Returns the file extension for the given file path.
|
|
711
|
+
# * ::fnmatch? (aliased as ::fnmatch): Returns whether the given file path
|
|
712
|
+
# matches the given pattern.
|
|
713
|
+
# * ::join: Joins path components into a single path string.
|
|
714
|
+
# * ::path: Returns the string representation of the given path.
|
|
715
|
+
# * ::readlink: Returns the path to the file at the given symbolic link.
|
|
716
|
+
# * ::realdirpath: Returns the real path for the given file path, where the
|
|
717
|
+
# last component need not exist.
|
|
718
|
+
# * ::realpath: Returns the real path for the given file path, where all
|
|
719
|
+
# components must exist.
|
|
720
|
+
# * ::split: Returns an array of two strings: the directory name and basename
|
|
721
|
+
# of the file at the given path.
|
|
722
|
+
# * #path (aliased as #to_path): Returns the string representation of the
|
|
723
|
+
# given path.
|
|
724
|
+
#
|
|
725
|
+
# *Times*
|
|
726
|
+
#
|
|
727
|
+
# * ::atime: Returns a Time for the most recent access to the given file.
|
|
728
|
+
# * ::birthtime: Returns a Time for the creation of the given file.
|
|
729
|
+
# * ::ctime: Returns a Time for the metadata change of the given file.
|
|
730
|
+
# * ::mtime: Returns a Time for the most recent data modification to the
|
|
731
|
+
# content of the given file.
|
|
732
|
+
# * #atime: Returns a Time for the most recent access to `self`.
|
|
733
|
+
# * #birthtime: Returns a Time the creation for `self`.
|
|
734
|
+
# * #ctime: Returns a Time for the metadata change of `self`.
|
|
735
|
+
# * #mtime: Returns a Time for the most recent data modification to the
|
|
736
|
+
# content of `self`.
|
|
737
|
+
#
|
|
738
|
+
# *Types*
|
|
739
|
+
#
|
|
740
|
+
# * ::blockdev?: Returns whether the file at the given path is a block device.
|
|
741
|
+
# * ::chardev?: Returns whether the file at the given path is a character
|
|
742
|
+
# device.
|
|
743
|
+
# * ::directory?: Returns whether the file at the given path is a directory.
|
|
744
|
+
# * ::executable?: Returns whether the file at the given path is executable by
|
|
745
|
+
# the effective user and group of the current process.
|
|
746
|
+
# * ::executable_real?: Returns whether the file at the given path is
|
|
747
|
+
# executable by the real user and group of the current process.
|
|
748
|
+
# * ::exist?: Returns whether the file at the given path exists.
|
|
749
|
+
# * ::file?: Returns whether the file at the given path is a regular file.
|
|
750
|
+
# * ::ftype: Returns a string giving the type of the file at the given path.
|
|
751
|
+
# * ::grpowned?: Returns whether the effective group of the current process
|
|
752
|
+
# owns the file at the given path.
|
|
753
|
+
# * ::identical?: Returns whether the files at two given paths are identical.
|
|
754
|
+
# * ::lstat: Returns the File::Stat object for the last symbolic link in the
|
|
755
|
+
# given path.
|
|
756
|
+
# * ::owned?: Returns whether the effective user of the current process owns
|
|
757
|
+
# the file at the given path.
|
|
758
|
+
# * ::pipe?: Returns whether the file at the given path is a pipe.
|
|
759
|
+
# * ::readable?: Returns whether the file at the given path is readable by the
|
|
760
|
+
# effective user and group of the current process.
|
|
761
|
+
# * ::readable_real?: Returns whether the file at the given path is readable
|
|
762
|
+
# by the real user and group of the current process.
|
|
763
|
+
# * ::setgid?: Returns whether the setgid bit is set for the file at the given
|
|
764
|
+
# path.
|
|
765
|
+
# * ::setuid?: Returns whether the setuid bit is set for the file at the given
|
|
766
|
+
# path.
|
|
767
|
+
# * ::socket?: Returns whether the file at the given path is a socket.
|
|
768
|
+
# * ::stat: Returns the File::Stat object for the file at the given path.
|
|
769
|
+
# * ::sticky?: Returns whether the file at the given path has its sticky bit
|
|
770
|
+
# set.
|
|
771
|
+
# * ::symlink?: Returns whether the file at the given path is a symbolic link.
|
|
772
|
+
# * ::umask: Returns the umask value for the current process.
|
|
773
|
+
# * ::world_readable?: Returns whether the file at the given path is readable
|
|
774
|
+
# by others.
|
|
775
|
+
# * ::world_writable?: Returns whether the file at the given path is writable
|
|
776
|
+
# by others.
|
|
777
|
+
# * ::writable?: Returns whether the file at the given path is writable by the
|
|
778
|
+
# effective user and group of the current process.
|
|
779
|
+
# * ::writable_real?: Returns whether the file at the given path is writable
|
|
780
|
+
# by the real user and group of the current process.
|
|
781
|
+
# * #lstat: Returns the File::Stat object for the last symbolic link in the
|
|
782
|
+
# path for `self`.
|
|
783
|
+
#
|
|
784
|
+
# *Contents*
|
|
785
|
+
#
|
|
786
|
+
# * ::empty? (aliased as ::zero?): Returns whether the file at the given path
|
|
787
|
+
# exists and is empty.
|
|
788
|
+
# * ::size: Returns the size (bytes) of the file at the given path.
|
|
789
|
+
# * ::size?: Returns `nil` if there is no file at the given path, or if that
|
|
790
|
+
# file is empty; otherwise returns the file size (bytes).
|
|
791
|
+
# * #size: Returns the size (bytes) of `self`.
|
|
792
|
+
#
|
|
793
|
+
# ### Settings
|
|
794
|
+
#
|
|
795
|
+
# * ::chmod: Changes permissions of the file at the given path.
|
|
796
|
+
# * ::chown: Change ownership of the file at the given path.
|
|
797
|
+
# * ::lchmod: Changes permissions of the last symbolic link in the given path.
|
|
798
|
+
# * ::lchown: Change ownership of the last symbolic in the given path.
|
|
799
|
+
# * ::lutime: For each given file path, sets the access time and modification
|
|
800
|
+
# time of the last symbolic link in the path.
|
|
801
|
+
# * ::rename: Moves the file at one given path to another given path.
|
|
802
|
+
# * ::utime: Sets the access time and modification time of each file at the
|
|
803
|
+
# given paths.
|
|
804
|
+
# * #flock: Locks or unlocks `self`.
|
|
805
|
+
#
|
|
806
|
+
# ### Other
|
|
807
|
+
#
|
|
808
|
+
# * ::truncate: Truncates the file at the given file path to the given size.
|
|
809
|
+
# * ::unlink (aliased as ::delete): Deletes the file for each given file path.
|
|
810
|
+
# * #truncate: Truncates `self` to the given size.
|
|
811
|
+
#
|
|
812
|
+
class File < IO
|
|
813
|
+
# The string that `File.ftype` and `File::Stat#ftype` return
|
|
814
|
+
type ftype = 'file' | 'directory' | 'characterSpecial' | 'blockSpecial'
|
|
815
|
+
| 'fifo' | 'link' | 'socket' | 'unknown'
|
|
816
|
+
|
|
817
|
+
# <!-- rdoc-file=file.c -->
|
|
818
|
+
# platform specific alternative separator
|
|
819
|
+
#
|
|
820
|
+
ALT_SEPARATOR: String?
|
|
821
|
+
|
|
822
|
+
# <!-- rdoc-file=file.c -->
|
|
823
|
+
# path list separator
|
|
824
|
+
#
|
|
825
|
+
PATH_SEPARATOR: String
|
|
826
|
+
|
|
827
|
+
# <!-- rdoc-file=file.c -->
|
|
828
|
+
# separates directory parts in path
|
|
829
|
+
#
|
|
830
|
+
SEPARATOR: String
|
|
831
|
+
|
|
832
|
+
# <!-- rdoc-file=file.c -->
|
|
833
|
+
# separates directory parts in path
|
|
834
|
+
#
|
|
835
|
+
Separator: String
|
|
836
|
+
|
|
837
|
+
# <!--
|
|
838
|
+
# rdoc-file=io.c
|
|
839
|
+
# - File.new(path, mode = 'r', perm = 0666, **opts) -> file
|
|
840
|
+
# -->
|
|
841
|
+
# Opens the file at the given `path` according to the given `mode`; creates and
|
|
842
|
+
# returns a new File object for that file.
|
|
843
|
+
#
|
|
844
|
+
# The new File object is buffered mode (or non-sync mode), unless `filename` is
|
|
845
|
+
# a tty. See IO#flush, IO#fsync, IO#fdatasync, and IO#sync=.
|
|
846
|
+
#
|
|
847
|
+
# Argument `path` must be a valid file path:
|
|
848
|
+
#
|
|
849
|
+
# f = File.new('/etc/fstab')
|
|
850
|
+
# f.close
|
|
851
|
+
# f = File.new('t.txt')
|
|
852
|
+
# f.close
|
|
853
|
+
#
|
|
854
|
+
# Optional argument `mode` (defaults to 'r') must specify a valid mode; see
|
|
855
|
+
# [Access Modes](rdoc-ref:File@Access+Modes):
|
|
856
|
+
#
|
|
857
|
+
# f = File.new('t.tmp', 'w')
|
|
858
|
+
# f.close
|
|
859
|
+
# f = File.new('t.tmp', File::RDONLY)
|
|
860
|
+
# f.close
|
|
861
|
+
#
|
|
862
|
+
# Optional argument `perm` (defaults to 0666) must specify valid permissions see
|
|
863
|
+
# [File Permissions](rdoc-ref:File@File+Permissions):
|
|
864
|
+
#
|
|
865
|
+
# f = File.new('t.tmp', File::CREAT, 0644)
|
|
866
|
+
# f.close
|
|
867
|
+
# f = File.new('t.tmp', File::CREAT, 0444)
|
|
868
|
+
# f.close
|
|
869
|
+
#
|
|
870
|
+
# Optional keyword arguments `opts` specify:
|
|
871
|
+
#
|
|
872
|
+
# * [Open Options](rdoc-ref:IO@Open+Options).
|
|
873
|
+
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
|
874
|
+
#
|
|
875
|
+
def initialize: (
|
|
876
|
+
path | int file_name,
|
|
877
|
+
?string | int mode,
|
|
878
|
+
?int perm,
|
|
879
|
+
# open options
|
|
880
|
+
?mode: Integer | String,
|
|
881
|
+
?flags: Integer,
|
|
882
|
+
?external_encoding: encoding,
|
|
883
|
+
?internal_encoding: encoding,
|
|
884
|
+
?encoding: encoding,
|
|
885
|
+
?textmode: boolish,
|
|
886
|
+
?binmode: boolish,
|
|
887
|
+
?autoclose: boolish,
|
|
888
|
+
?path: path,
|
|
889
|
+
# encoding options
|
|
890
|
+
?invalid: :replace | nil,
|
|
891
|
+
?undef: :replace | nil,
|
|
892
|
+
?replace: String | nil,
|
|
893
|
+
?fallback: Hash[string, string] | ^(String) -> string | Method | nil,
|
|
894
|
+
?xml: :text | :attr | nil,
|
|
895
|
+
?cr_newline: bool,
|
|
896
|
+
?crlf_newline: bool,
|
|
897
|
+
?universal_newline: bool
|
|
898
|
+
) -> void
|
|
899
|
+
|
|
900
|
+
# <!--
|
|
901
|
+
# rdoc-file=file.c
|
|
902
|
+
# - File.absolute_path(file_name [, dir_string] ) -> abs_file_name
|
|
903
|
+
# -->
|
|
904
|
+
# Converts a pathname to an absolute pathname. Relative paths are referenced
|
|
905
|
+
# from the current working directory of the process unless *dir_string* is
|
|
906
|
+
# given, in which case it will be used as the starting point. If the given
|
|
907
|
+
# pathname starts with a ``<code>~</code>'' it is NOT expanded, it is treated as
|
|
908
|
+
# a normal directory name.
|
|
909
|
+
#
|
|
910
|
+
# File.absolute_path("~oracle/bin") #=> "<relative_path>/~oracle/bin"
|
|
911
|
+
#
|
|
912
|
+
def self.absolute_path: (path file_name, ?path dir_string) -> String
|
|
913
|
+
|
|
914
|
+
# <!--
|
|
915
|
+
# rdoc-file=file.c
|
|
916
|
+
# - File.absolute_path?(file_name) -> true or false
|
|
917
|
+
# -->
|
|
918
|
+
# Returns `true` if `file_name` is an absolute path, and `false` otherwise.
|
|
919
|
+
#
|
|
920
|
+
# File.absolute_path?("c:/foo") #=> false (on Linux), true (on Windows)
|
|
921
|
+
#
|
|
922
|
+
def self.absolute_path?: (path file_name) -> bool
|
|
923
|
+
|
|
924
|
+
# <!--
|
|
925
|
+
# rdoc-file=file.c
|
|
926
|
+
# - File.atime(file_name) -> time
|
|
927
|
+
# -->
|
|
928
|
+
# Returns the last access time for the named file as a Time object.
|
|
929
|
+
#
|
|
930
|
+
# *file_name* can be an IO object.
|
|
931
|
+
#
|
|
932
|
+
# File.atime("testfile") #=> Wed Apr 09 08:51:48 CDT 2003
|
|
933
|
+
#
|
|
934
|
+
def self.atime: (path | IO file_name) -> Time
|
|
935
|
+
|
|
936
|
+
# <!--
|
|
937
|
+
# rdoc-file=file.c
|
|
938
|
+
# - File.basename(file_name [, suffix] ) -> base_name
|
|
939
|
+
# -->
|
|
940
|
+
# Returns the last component of the filename given in *file_name* (after first
|
|
941
|
+
# stripping trailing separators), which can be formed using both File::SEPARATOR
|
|
942
|
+
# and File::ALT_SEPARATOR as the separator when File::ALT_SEPARATOR is not
|
|
943
|
+
# `nil`. If *suffix* is given and present at the end of *file_name*, it is
|
|
944
|
+
# removed. If *suffix* is ".*", any extension will be removed.
|
|
945
|
+
#
|
|
946
|
+
# File.basename("/home/gumby/work/ruby.rb") #=> "ruby.rb"
|
|
947
|
+
# File.basename("/home/gumby/work/ruby.rb", ".rb") #=> "ruby"
|
|
948
|
+
# File.basename("/home/gumby/work/ruby.rb", ".*") #=> "ruby"
|
|
949
|
+
#
|
|
950
|
+
def self.basename: (path file_name, ?string suffix) -> String
|
|
951
|
+
|
|
952
|
+
# <!--
|
|
953
|
+
# rdoc-file=file.c
|
|
954
|
+
# - File.birthtime(file_name) -> time
|
|
955
|
+
# -->
|
|
956
|
+
# Returns the birth time for the named file.
|
|
957
|
+
#
|
|
958
|
+
# *file_name* can be an IO object.
|
|
959
|
+
#
|
|
960
|
+
# File.birthtime("testfile") #=> Wed Apr 09 08:53:13 CDT 2003
|
|
961
|
+
#
|
|
962
|
+
# If the platform doesn't have birthtime, raises NotImplementedError.
|
|
963
|
+
#
|
|
964
|
+
def self.birthtime: (path | IO file_name) -> Time
|
|
965
|
+
|
|
966
|
+
# <!--
|
|
967
|
+
# rdoc-file=file.c
|
|
968
|
+
# - File.blockdev?(filepath) -> true or false
|
|
969
|
+
# -->
|
|
970
|
+
# Returns `true` if `filepath` points to a block device, `false` otherwise:
|
|
971
|
+
#
|
|
972
|
+
# File.blockdev?('/dev/sda1') # => true
|
|
973
|
+
# File.blockdev?(File.new('t.tmp')) # => false
|
|
974
|
+
#
|
|
975
|
+
def self.blockdev?: (path | IO file_name) -> bool
|
|
976
|
+
|
|
977
|
+
# <!--
|
|
978
|
+
# rdoc-file=file.c
|
|
979
|
+
# - File.chardev?(filepath) -> true or false
|
|
980
|
+
# -->
|
|
981
|
+
# Returns `true` if `filepath` points to a character device, `false` otherwise.
|
|
982
|
+
#
|
|
983
|
+
# File.chardev?($stdin) # => true
|
|
984
|
+
# File.chardev?('t.txt') # => false
|
|
985
|
+
#
|
|
986
|
+
def self.chardev?: (path | IO file_name) -> bool
|
|
987
|
+
|
|
988
|
+
# <!--
|
|
989
|
+
# rdoc-file=file.c
|
|
990
|
+
# - File.chmod(mode_int, file_name, ... ) -> integer
|
|
991
|
+
# -->
|
|
992
|
+
# Changes permission bits on the named file(s) to the bit pattern represented by
|
|
993
|
+
# *mode_int*. Actual effects are operating system dependent (see the beginning
|
|
994
|
+
# of this section). On Unix systems, see <code>chmod(2)</code> for details.
|
|
995
|
+
# Returns the number of files processed.
|
|
996
|
+
#
|
|
997
|
+
# File.chmod(0644, "testfile", "out") #=> 2
|
|
998
|
+
#
|
|
999
|
+
def self.chmod: (int mode, *path file_name) -> Integer
|
|
1000
|
+
|
|
1001
|
+
# <!--
|
|
1002
|
+
# rdoc-file=file.c
|
|
1003
|
+
# - File.chown(owner_int, group_int, file_name, ...) -> integer
|
|
1004
|
+
# -->
|
|
1005
|
+
# Changes the owner and group of the named file(s) to the given numeric owner
|
|
1006
|
+
# and group id's. Only a process with superuser privileges may change the owner
|
|
1007
|
+
# of a file. The current owner of a file may change the file's group to any
|
|
1008
|
+
# group to which the owner belongs. A `nil` or -1 owner or group id is ignored.
|
|
1009
|
+
# Returns the number of files processed.
|
|
1010
|
+
#
|
|
1011
|
+
# File.chown(nil, 100, "testfile")
|
|
1012
|
+
#
|
|
1013
|
+
def self.chown: (int? owner, int? group, *path file_name) -> Integer
|
|
1014
|
+
|
|
1015
|
+
# <!--
|
|
1016
|
+
# rdoc-file=file.c
|
|
1017
|
+
# - File.ctime(file_name) -> time
|
|
1018
|
+
# -->
|
|
1019
|
+
# Returns the change time for the named file (the time at which directory
|
|
1020
|
+
# information about the file was changed, not the file itself).
|
|
1021
|
+
#
|
|
1022
|
+
# *file_name* can be an IO object.
|
|
1023
|
+
#
|
|
1024
|
+
# Note that on Windows (NTFS), returns creation time (birth time).
|
|
1025
|
+
#
|
|
1026
|
+
# File.ctime("testfile") #=> Wed Apr 09 08:53:13 CDT 2003
|
|
1027
|
+
#
|
|
1028
|
+
def self.ctime: (path | IO file_name) -> Time
|
|
1029
|
+
|
|
1030
|
+
# <!--
|
|
1031
|
+
# rdoc-file=file.c
|
|
1032
|
+
# - File.delete(file_name, ...) -> integer
|
|
1033
|
+
# - File.unlink(file_name, ...) -> integer
|
|
1034
|
+
# -->
|
|
1035
|
+
# Deletes the named files, returning the number of names passed as arguments.
|
|
1036
|
+
# Raises an exception on any error. Since the underlying implementation relies
|
|
1037
|
+
# on the <code>unlink(2)</code> system call, the type of exception raised
|
|
1038
|
+
# depends on its error type (see https://linux.die.net/man/2/unlink) and has the
|
|
1039
|
+
# form of e.g. Errno::ENOENT.
|
|
1040
|
+
#
|
|
1041
|
+
# See also Dir::rmdir.
|
|
1042
|
+
#
|
|
1043
|
+
alias self.delete self.unlink
|
|
1044
|
+
|
|
1045
|
+
# <!--
|
|
1046
|
+
# rdoc-file=file.c
|
|
1047
|
+
# - File.directory?(path) -> true or false
|
|
1048
|
+
# -->
|
|
1049
|
+
# With string `object` given, returns `true` if `path` is a string path leading
|
|
1050
|
+
# to a directory, or to a symbolic link to a directory; `false` otherwise:
|
|
1051
|
+
#
|
|
1052
|
+
# File.directory?('.') # => true
|
|
1053
|
+
# File.directory?('foo') # => false
|
|
1054
|
+
# File.symlink('.', 'dirlink') # => 0
|
|
1055
|
+
# File.directory?('dirlink') # => true
|
|
1056
|
+
# File.symlink('t,txt', 'filelink') # => 0
|
|
1057
|
+
# File.directory?('filelink') # => false
|
|
1058
|
+
#
|
|
1059
|
+
# Argument `path` can be an IO object.
|
|
1060
|
+
#
|
|
1061
|
+
def self.directory?: (path | IO path) -> bool
|
|
1062
|
+
|
|
1063
|
+
# <!--
|
|
1064
|
+
# rdoc-file=file.c
|
|
1065
|
+
# - File.dirname(file_name, level = 1) -> dir_name
|
|
1066
|
+
# -->
|
|
1067
|
+
# Returns all components of the filename given in *file_name* except the last
|
|
1068
|
+
# one (after first stripping trailing separators). The filename can be formed
|
|
1069
|
+
# using both File::SEPARATOR and File::ALT_SEPARATOR as the separator when
|
|
1070
|
+
# File::ALT_SEPARATOR is not `nil`.
|
|
1071
|
+
#
|
|
1072
|
+
# File.dirname("/home/gumby/work/ruby.rb") #=> "/home/gumby/work"
|
|
1073
|
+
#
|
|
1074
|
+
# If `level` is given, removes the last `level` components, not only one.
|
|
1075
|
+
#
|
|
1076
|
+
# File.dirname("/home/gumby/work/ruby.rb", 2) #=> "/home/gumby"
|
|
1077
|
+
# File.dirname("/home/gumby/work/ruby.rb", 4) #=> "/"
|
|
1078
|
+
#
|
|
1079
|
+
def self.dirname: (path file_name, ?Integer level) -> String
|
|
1080
|
+
|
|
1081
|
+
# <!--
|
|
1082
|
+
# rdoc-file=file.c
|
|
1083
|
+
# - File.zero?(file_name) -> true or false
|
|
1084
|
+
# -->
|
|
1085
|
+
# Returns `true` if the named file exists and has a zero size.
|
|
1086
|
+
#
|
|
1087
|
+
# *file_name* can be an IO object.
|
|
1088
|
+
#
|
|
1089
|
+
alias self.empty? self.zero?
|
|
1090
|
+
|
|
1091
|
+
# <!--
|
|
1092
|
+
# rdoc-file=file.c
|
|
1093
|
+
# - File.executable?(file_name) -> true or false
|
|
1094
|
+
# -->
|
|
1095
|
+
# Returns `true` if the named file is executable by the effective user and group
|
|
1096
|
+
# id of this process. See eaccess(3).
|
|
1097
|
+
#
|
|
1098
|
+
# Windows does not support execute permissions separately from read permissions.
|
|
1099
|
+
# On Windows, a file is only considered executable if it ends in .bat, .cmd,
|
|
1100
|
+
# .com, or .exe.
|
|
1101
|
+
#
|
|
1102
|
+
# Note that some OS-level security features may cause this to return true even
|
|
1103
|
+
# though the file is not executable by the effective user/group.
|
|
1104
|
+
#
|
|
1105
|
+
def self.executable?: (path file_name) -> bool
|
|
1106
|
+
|
|
1107
|
+
# <!--
|
|
1108
|
+
# rdoc-file=file.c
|
|
1109
|
+
# - File.executable_real?(file_name) -> true or false
|
|
1110
|
+
# -->
|
|
1111
|
+
# Returns `true` if the named file is executable by the real user and group id
|
|
1112
|
+
# of this process. See access(3).
|
|
1113
|
+
#
|
|
1114
|
+
# Windows does not support execute permissions separately from read permissions.
|
|
1115
|
+
# On Windows, a file is only considered executable if it ends in .bat, .cmd,
|
|
1116
|
+
# .com, or .exe.
|
|
1117
|
+
#
|
|
1118
|
+
# Note that some OS-level security features may cause this to return true even
|
|
1119
|
+
# though the file is not executable by the real user/group.
|
|
1120
|
+
#
|
|
1121
|
+
def self.executable_real?: (path file_name) -> bool
|
|
1122
|
+
|
|
1123
|
+
# <!--
|
|
1124
|
+
# rdoc-file=file.c
|
|
1125
|
+
# - File.exist?(file_name) -> true or false
|
|
1126
|
+
# -->
|
|
1127
|
+
# Return `true` if the named file exists.
|
|
1128
|
+
#
|
|
1129
|
+
# *file_name* can be an IO object.
|
|
1130
|
+
#
|
|
1131
|
+
# "file exists" means that stat() or fstat() system call is successful.
|
|
1132
|
+
#
|
|
1133
|
+
def self.exist?: (path | IO file_name) -> bool
|
|
1134
|
+
|
|
1135
|
+
# <!--
|
|
1136
|
+
# rdoc-file=file.c
|
|
1137
|
+
# - File.expand_path(file_name [, dir_string] ) -> abs_file_name
|
|
1138
|
+
# -->
|
|
1139
|
+
# Converts a pathname to an absolute pathname. Relative paths are referenced
|
|
1140
|
+
# from the current working directory of the process unless `dir_string` is
|
|
1141
|
+
# given, in which case it will be used as the starting point. The given pathname
|
|
1142
|
+
# may start with a ``<code>~</code>'', which expands to the process owner's home
|
|
1143
|
+
# directory (the environment variable `HOME` must be set correctly).
|
|
1144
|
+
# ``<code>~</code>*user*'' expands to the named user's home directory.
|
|
1145
|
+
#
|
|
1146
|
+
# File.expand_path("~oracle/bin") #=> "/home/oracle/bin"
|
|
1147
|
+
#
|
|
1148
|
+
# A simple example of using `dir_string` is as follows.
|
|
1149
|
+
# File.expand_path("ruby", "/usr/bin") #=> "/usr/bin/ruby"
|
|
1150
|
+
#
|
|
1151
|
+
# A more complex example which also resolves parent directory is as follows.
|
|
1152
|
+
# Suppose we are in bin/mygem and want the absolute path of lib/mygem.rb.
|
|
1153
|
+
#
|
|
1154
|
+
# File.expand_path("../../lib/mygem.rb", __FILE__)
|
|
1155
|
+
# #=> ".../path/to/project/lib/mygem.rb"
|
|
1156
|
+
#
|
|
1157
|
+
# So first it resolves the parent of __FILE__, that is bin/, then go to the
|
|
1158
|
+
# parent, the root of the project and appends <code>lib/mygem.rb</code>.
|
|
1159
|
+
#
|
|
1160
|
+
def self.expand_path: (path file_name, ?path dir_string) -> String
|
|
1161
|
+
|
|
1162
|
+
# <!--
|
|
1163
|
+
# rdoc-file=file.c
|
|
1164
|
+
# - File.extname(path) -> string
|
|
1165
|
+
# -->
|
|
1166
|
+
# Returns the extension (the portion of file name in `path` starting from the
|
|
1167
|
+
# last period).
|
|
1168
|
+
#
|
|
1169
|
+
# If `path` is a dotfile, or starts with a period, then the starting dot is not
|
|
1170
|
+
# dealt with the start of the extension.
|
|
1171
|
+
#
|
|
1172
|
+
# An empty string will also be returned when the period is the last character in
|
|
1173
|
+
# `path`.
|
|
1174
|
+
#
|
|
1175
|
+
# On Windows, trailing dots are truncated.
|
|
1176
|
+
#
|
|
1177
|
+
# File.extname("test.rb") #=> ".rb"
|
|
1178
|
+
# File.extname("a/b/d/test.rb") #=> ".rb"
|
|
1179
|
+
# File.extname(".a/b/d/test.rb") #=> ".rb"
|
|
1180
|
+
# File.extname("foo.") #=> "" on Windows
|
|
1181
|
+
# File.extname("foo.") #=> "." on non-Windows
|
|
1182
|
+
# File.extname("test") #=> ""
|
|
1183
|
+
# File.extname(".profile") #=> ""
|
|
1184
|
+
# File.extname(".profile.sh") #=> ".sh"
|
|
1185
|
+
#
|
|
1186
|
+
def self.extname: (path path) -> String
|
|
1187
|
+
|
|
1188
|
+
# <!--
|
|
1189
|
+
# rdoc-file=file.c
|
|
1190
|
+
# - File.file?(file) -> true or false
|
|
1191
|
+
# -->
|
|
1192
|
+
# Returns `true` if the named `file` exists and is a regular file.
|
|
1193
|
+
#
|
|
1194
|
+
# `file` can be an IO object.
|
|
1195
|
+
#
|
|
1196
|
+
# If the `file` argument is a symbolic link, it will resolve the symbolic link
|
|
1197
|
+
# and use the file referenced by the link.
|
|
1198
|
+
#
|
|
1199
|
+
def self.file?: (path | IO file) -> bool
|
|
1200
|
+
|
|
1201
|
+
# <!--
|
|
1202
|
+
# rdoc-file=dir.rb
|
|
1203
|
+
# - File.fnmatch( pattern, path, [flags] ) -> (true or false)
|
|
1204
|
+
# - File.fnmatch?( pattern, path, [flags] ) -> (true or false)
|
|
1205
|
+
# -->
|
|
1206
|
+
# Returns true if `path` matches against `pattern`. The pattern is not a
|
|
1207
|
+
# regular expression; instead it follows rules similar to shell filename
|
|
1208
|
+
# globbing. It may contain the following metacharacters:
|
|
1209
|
+
#
|
|
1210
|
+
# <code>*</code>
|
|
1211
|
+
# : Matches any file. Can be restricted by other values in the glob.
|
|
1212
|
+
# Equivalent to <code>/.*/x</code> in regexp.
|
|
1213
|
+
#
|
|
1214
|
+
# <code>*</code>
|
|
1215
|
+
# : Matches all regular files
|
|
1216
|
+
#
|
|
1217
|
+
# <code>c*</code>
|
|
1218
|
+
# : Matches all files beginning with `c`
|
|
1219
|
+
#
|
|
1220
|
+
# <code>*c</code>
|
|
1221
|
+
# : Matches all files ending with `c`
|
|
1222
|
+
#
|
|
1223
|
+
# <code>*c*</code>
|
|
1224
|
+
# : Matches all files that have `c` in them (including at the beginning or
|
|
1225
|
+
# end).
|
|
1226
|
+
#
|
|
1227
|
+
#
|
|
1228
|
+
# To match hidden files (that start with a <code>.</code>) set the
|
|
1229
|
+
# File::FNM_DOTMATCH flag.
|
|
1230
|
+
#
|
|
1231
|
+
#
|
|
1232
|
+
# <code>**</code>
|
|
1233
|
+
# : Matches directories recursively or files expansively.
|
|
1234
|
+
#
|
|
1235
|
+
#
|
|
1236
|
+
# <code>?</code>
|
|
1237
|
+
# : Matches any one character. Equivalent to <code>/.{1}/</code> in regexp.
|
|
1238
|
+
#
|
|
1239
|
+
#
|
|
1240
|
+
# <code>[set]</code>
|
|
1241
|
+
# : Matches any one character in `set`. Behaves exactly like character sets
|
|
1242
|
+
# in Regexp, including set negation (<code>[^a-z]</code>).
|
|
1243
|
+
#
|
|
1244
|
+
#
|
|
1245
|
+
# <code>\</code>
|
|
1246
|
+
# : Escapes the next metacharacter.
|
|
1247
|
+
#
|
|
1248
|
+
#
|
|
1249
|
+
# <code>{a,b}</code>
|
|
1250
|
+
# : Matches pattern a and pattern b if File::FNM_EXTGLOB flag is enabled.
|
|
1251
|
+
# Behaves like a Regexp union (<code>(?:a|b)</code>).
|
|
1252
|
+
#
|
|
1253
|
+
#
|
|
1254
|
+
# `flags` is a bitwise OR of the `FNM_XXX` constants. The same glob pattern and
|
|
1255
|
+
# flags are used by Dir::glob.
|
|
1256
|
+
#
|
|
1257
|
+
# Examples:
|
|
1258
|
+
#
|
|
1259
|
+
# File.fnmatch('cat', 'cat') #=> true # match entire string
|
|
1260
|
+
# File.fnmatch('cat', 'category') #=> false # only match partial string
|
|
1261
|
+
#
|
|
1262
|
+
# File.fnmatch('c{at,ub}s', 'cats') #=> false # { } isn't supported by default
|
|
1263
|
+
# File.fnmatch('c{at,ub}s', 'cats', File::FNM_EXTGLOB) #=> true # { } is supported on FNM_EXTGLOB
|
|
1264
|
+
#
|
|
1265
|
+
# File.fnmatch('c?t', 'cat') #=> true # '?' match only 1 character
|
|
1266
|
+
# File.fnmatch('c??t', 'cat') #=> false # ditto
|
|
1267
|
+
# File.fnmatch('c*', 'cats') #=> true # '*' match 0 or more characters
|
|
1268
|
+
# File.fnmatch('c*t', 'c/a/b/t') #=> true # ditto
|
|
1269
|
+
# File.fnmatch('ca[a-z]', 'cat') #=> true # inclusive bracket expression
|
|
1270
|
+
# File.fnmatch('ca[^t]', 'cat') #=> false # exclusive bracket expression ('^' or '!')
|
|
1271
|
+
#
|
|
1272
|
+
# File.fnmatch('cat', 'CAT') #=> false # case sensitive
|
|
1273
|
+
# File.fnmatch('cat', 'CAT', File::FNM_CASEFOLD) #=> true # case insensitive
|
|
1274
|
+
# File.fnmatch('cat', 'CAT', File::FNM_SYSCASE) #=> true or false # depends on the system default
|
|
1275
|
+
#
|
|
1276
|
+
# File.fnmatch('?', '/', File::FNM_PATHNAME) #=> false # wildcard doesn't match '/' on FNM_PATHNAME
|
|
1277
|
+
# File.fnmatch('*', '/', File::FNM_PATHNAME) #=> false # ditto
|
|
1278
|
+
# File.fnmatch('[/]', '/', File::FNM_PATHNAME) #=> false # ditto
|
|
1279
|
+
#
|
|
1280
|
+
# File.fnmatch('\?', '?') #=> true # escaped wildcard becomes ordinary
|
|
1281
|
+
# File.fnmatch('\a', 'a') #=> true # escaped ordinary remains ordinary
|
|
1282
|
+
# File.fnmatch('\a', '\a', File::FNM_NOESCAPE) #=> true # FNM_NOESCAPE makes '\' ordinary
|
|
1283
|
+
# File.fnmatch('[\?]', '?') #=> true # can escape inside bracket expression
|
|
1284
|
+
#
|
|
1285
|
+
# File.fnmatch('*', '.profile') #=> false # wildcard doesn't match leading
|
|
1286
|
+
# File.fnmatch('*', '.profile', File::FNM_DOTMATCH) #=> true # period by default.
|
|
1287
|
+
# File.fnmatch('.*', '.profile') #=> true
|
|
1288
|
+
#
|
|
1289
|
+
# File.fnmatch('**/*.rb', 'main.rb') #=> false
|
|
1290
|
+
# File.fnmatch('**/*.rb', './main.rb') #=> false
|
|
1291
|
+
# File.fnmatch('**/*.rb', 'lib/song.rb') #=> true
|
|
1292
|
+
# File.fnmatch('**.rb', 'main.rb') #=> true
|
|
1293
|
+
# File.fnmatch('**.rb', './main.rb') #=> false
|
|
1294
|
+
# File.fnmatch('**.rb', 'lib/song.rb') #=> true
|
|
1295
|
+
# File.fnmatch('*', 'dave/.profile') #=> true
|
|
1296
|
+
#
|
|
1297
|
+
# File.fnmatch('**/foo', 'a/b/c/foo', File::FNM_PATHNAME) #=> true
|
|
1298
|
+
# File.fnmatch('**/foo', '/a/b/c/foo', File::FNM_PATHNAME) #=> true
|
|
1299
|
+
# File.fnmatch('**/foo', 'c:/a/b/c/foo', File::FNM_PATHNAME) #=> true
|
|
1300
|
+
# File.fnmatch('**/foo', 'a/.b/c/foo', File::FNM_PATHNAME) #=> false
|
|
1301
|
+
# File.fnmatch('**/foo', 'a/.b/c/foo', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true
|
|
1302
|
+
#
|
|
1303
|
+
def self.fnmatch: (string pattern, path path, ?int flags) -> bool
|
|
1304
|
+
|
|
1305
|
+
# <!--
|
|
1306
|
+
# rdoc-file=dir.rb
|
|
1307
|
+
# - fnmatch?(pattern, path, flags = 0)
|
|
1308
|
+
# -->
|
|
1309
|
+
#
|
|
1310
|
+
alias self.fnmatch? self.fnmatch
|
|
1311
|
+
|
|
1312
|
+
# <!--
|
|
1313
|
+
# rdoc-file=file.c
|
|
1314
|
+
# - File.ftype(file_name) -> string
|
|
1315
|
+
# -->
|
|
1316
|
+
# Identifies the type of the named file; the return string is one of ```file`'',
|
|
1317
|
+
# ```directory`'', ```characterSpecial`'', ```blockSpecial`'', ```fifo`'',
|
|
1318
|
+
# ```link`'', ```socket`'', or ```unknown`''.
|
|
1319
|
+
#
|
|
1320
|
+
# File.ftype("testfile") #=> "file"
|
|
1321
|
+
# File.ftype("/dev/tty") #=> "characterSpecial"
|
|
1322
|
+
# File.ftype("/tmp/.X11-unix/X0") #=> "socket"
|
|
1323
|
+
#
|
|
1324
|
+
def self.ftype: (path file_name) -> String
|
|
1325
|
+
|
|
1326
|
+
# <!--
|
|
1327
|
+
# rdoc-file=file.c
|
|
1328
|
+
# - File.grpowned?(file_name) -> true or false
|
|
1329
|
+
# -->
|
|
1330
|
+
# Returns `true` if the named file exists and the effective group id of the
|
|
1331
|
+
# calling process is the owner of the file. Returns `false` on Windows.
|
|
1332
|
+
#
|
|
1333
|
+
# *file_name* can be an IO object.
|
|
1334
|
+
#
|
|
1335
|
+
def self.grpowned?: (path | IO file_name) -> bool
|
|
1336
|
+
|
|
1337
|
+
# <!--
|
|
1338
|
+
# rdoc-file=file.c
|
|
1339
|
+
# - File.identical?(file_1, file_2) -> true or false
|
|
1340
|
+
# -->
|
|
1341
|
+
# Returns `true` if the named files are identical.
|
|
1342
|
+
#
|
|
1343
|
+
# *file_1* and *file_2* can be an IO object.
|
|
1344
|
+
#
|
|
1345
|
+
# open("a", "w") {}
|
|
1346
|
+
# p File.identical?("a", "a") #=> true
|
|
1347
|
+
# p File.identical?("a", "./a") #=> true
|
|
1348
|
+
# File.link("a", "b")
|
|
1349
|
+
# p File.identical?("a", "b") #=> true
|
|
1350
|
+
# File.symlink("a", "c")
|
|
1351
|
+
# p File.identical?("a", "c") #=> true
|
|
1352
|
+
# open("d", "w") {}
|
|
1353
|
+
# p File.identical?("a", "d") #=> false
|
|
1354
|
+
#
|
|
1355
|
+
def self.identical?: (path | IO file_1, path | IO file_2) -> bool
|
|
1356
|
+
|
|
1357
|
+
# <!--
|
|
1358
|
+
# rdoc-file=file.c
|
|
1359
|
+
# - File.join(string, ...) -> string
|
|
1360
|
+
# -->
|
|
1361
|
+
# Returns a new string formed by joining the strings using <code>"/"</code>.
|
|
1362
|
+
#
|
|
1363
|
+
# File.join("usr", "mail", "gumby") #=> "usr/mail/gumby"
|
|
1364
|
+
#
|
|
1365
|
+
def self.join: (*path) -> String
|
|
1366
|
+
|
|
1367
|
+
# <!--
|
|
1368
|
+
# rdoc-file=file.c
|
|
1369
|
+
# - File.lchmod(mode_int, file_name, ...) -> integer
|
|
1370
|
+
# -->
|
|
1371
|
+
# Equivalent to File::chmod, but does not follow symbolic links (so it will
|
|
1372
|
+
# change the permissions associated with the link, not the file referenced by
|
|
1373
|
+
# the link). Often not available.
|
|
1374
|
+
#
|
|
1375
|
+
def self.lchmod: (int mode, *path file_name) -> Integer
|
|
1376
|
+
|
|
1377
|
+
# <!--
|
|
1378
|
+
# rdoc-file=file.c
|
|
1379
|
+
# - File.lchown(owner_int, group_int, file_name,..) -> integer
|
|
1380
|
+
# -->
|
|
1381
|
+
# Equivalent to File::chown, but does not follow symbolic links (so it will
|
|
1382
|
+
# change the owner associated with the link, not the file referenced by the
|
|
1383
|
+
# link). Often not available. Returns number of files in the argument list.
|
|
1384
|
+
#
|
|
1385
|
+
def self.lchown: (int? owner, int? group, *path file_name) -> Integer
|
|
1386
|
+
|
|
1387
|
+
# <!--
|
|
1388
|
+
# rdoc-file=file.c
|
|
1389
|
+
# - File.link(old_name, new_name) -> 0
|
|
1390
|
+
# -->
|
|
1391
|
+
# Creates a new name for an existing file using a hard link. Will not overwrite
|
|
1392
|
+
# *new_name* if it already exists (raising a subclass of SystemCallError). Not
|
|
1393
|
+
# available on all platforms.
|
|
1394
|
+
#
|
|
1395
|
+
# File.link("testfile", ".testfile") #=> 0
|
|
1396
|
+
# IO.readlines(".testfile")[0] #=> "This is line one\n"
|
|
1397
|
+
#
|
|
1398
|
+
def self.link: (path old_name, path new_name) -> 0
|
|
1399
|
+
|
|
1400
|
+
# <!--
|
|
1401
|
+
# rdoc-file=file.c
|
|
1402
|
+
# - File.lstat(filepath) -> stat
|
|
1403
|
+
# -->
|
|
1404
|
+
# Like File::stat, but does not follow the last symbolic link; instead, returns
|
|
1405
|
+
# a File::Stat object for the link itself.
|
|
1406
|
+
#
|
|
1407
|
+
# File.symlink('t.txt', 'symlink')
|
|
1408
|
+
# File.stat('symlink').size # => 47
|
|
1409
|
+
# File.lstat('symlink').size # => 5
|
|
1410
|
+
#
|
|
1411
|
+
def self.lstat: (path file_name) -> File::Stat
|
|
1412
|
+
|
|
1413
|
+
# <!--
|
|
1414
|
+
# rdoc-file=file.c
|
|
1415
|
+
# - File.lutime(atime, mtime, file_name, ...) -> integer
|
|
1416
|
+
# -->
|
|
1417
|
+
# Sets the access and modification times of each named file to the first two
|
|
1418
|
+
# arguments. If a file is a symlink, this method acts upon the link itself as
|
|
1419
|
+
# opposed to its referent; for the inverse behavior, see File.utime. Returns the
|
|
1420
|
+
# number of file names in the argument list.
|
|
1421
|
+
#
|
|
1422
|
+
def self.lutime: (Time | Numeric atime, Time | Numeric mtime, *path file_name) -> Integer
|
|
1423
|
+
|
|
1424
|
+
# <!--
|
|
1425
|
+
# rdoc-file=file.c
|
|
1426
|
+
# - File.mkfifo(file_name, mode=0666) => 0
|
|
1427
|
+
# -->
|
|
1428
|
+
# Creates a FIFO special file with name *file_name*. *mode* specifies the
|
|
1429
|
+
# FIFO's permissions. It is modified by the process's umask in the usual way:
|
|
1430
|
+
# the permissions of the created file are (mode & ~umask).
|
|
1431
|
+
#
|
|
1432
|
+
def self.mkfifo: (path file_name, ?int mode) -> 0
|
|
1433
|
+
|
|
1434
|
+
# <!--
|
|
1435
|
+
# rdoc-file=file.c
|
|
1436
|
+
# - File.mtime(file_name) -> time
|
|
1437
|
+
# -->
|
|
1438
|
+
# Returns the modification time for the named file as a Time object.
|
|
1439
|
+
#
|
|
1440
|
+
# *file_name* can be an IO object.
|
|
1441
|
+
#
|
|
1442
|
+
# File.mtime("testfile") #=> Tue Apr 08 12:58:04 CDT 2003
|
|
1443
|
+
#
|
|
1444
|
+
def self.mtime: (path | IO file_name) -> Time
|
|
1445
|
+
|
|
1446
|
+
# <!--
|
|
1447
|
+
# rdoc-file=io.c
|
|
1448
|
+
# - File.open(path, mode = 'r', perm = 0666, **opts) -> file
|
|
1449
|
+
# - File.open(path, mode = 'r', perm = 0666, **opts) {|f| ... } -> object
|
|
1450
|
+
# -->
|
|
1451
|
+
# Creates a new File object, via File.new with the given arguments.
|
|
1452
|
+
#
|
|
1453
|
+
# With no block given, returns the File object.
|
|
1454
|
+
#
|
|
1455
|
+
# With a block given, calls the block with the File object and returns the
|
|
1456
|
+
# block's value.
|
|
1457
|
+
#
|
|
1458
|
+
def self.open: (
|
|
1459
|
+
path | int file_name,
|
|
1460
|
+
?string | int mode,
|
|
1461
|
+
?int perm,
|
|
1462
|
+
# open options
|
|
1463
|
+
?mode: Integer | String,
|
|
1464
|
+
?flags: Integer,
|
|
1465
|
+
?external_encoding: encoding,
|
|
1466
|
+
?internal_encoding: encoding,
|
|
1467
|
+
?encoding: encoding,
|
|
1468
|
+
?textmode: boolish,
|
|
1469
|
+
?binmode: boolish,
|
|
1470
|
+
?autoclose: boolish,
|
|
1471
|
+
?path: path,
|
|
1472
|
+
# encoding options
|
|
1473
|
+
?invalid: :replace | nil,
|
|
1474
|
+
?undef: :replace | nil,
|
|
1475
|
+
?replace: String | nil,
|
|
1476
|
+
?fallback: Hash[string, string] | ^(String) -> string | Method | nil,
|
|
1477
|
+
?xml: :text | :attr | nil,
|
|
1478
|
+
?cr_newline: bool,
|
|
1479
|
+
?crlf_newline: bool,
|
|
1480
|
+
?universal_newline: bool
|
|
1481
|
+
) -> instance
|
|
1482
|
+
| [T] (
|
|
1483
|
+
path | int file_name,
|
|
1484
|
+
?string | int mode,
|
|
1485
|
+
?int perm,
|
|
1486
|
+
# open options
|
|
1487
|
+
?mode: Integer | String,
|
|
1488
|
+
?flags: Integer,
|
|
1489
|
+
?external_encoding: encoding,
|
|
1490
|
+
?internal_encoding: encoding,
|
|
1491
|
+
?encoding: encoding,
|
|
1492
|
+
?textmode: boolish,
|
|
1493
|
+
?binmode: boolish,
|
|
1494
|
+
?autoclose: boolish,
|
|
1495
|
+
?path: path,
|
|
1496
|
+
# encoding options
|
|
1497
|
+
?invalid: :replace | nil,
|
|
1498
|
+
?undef: :replace | nil,
|
|
1499
|
+
?replace: String | nil,
|
|
1500
|
+
?fallback: Hash[string, string] | ^(String) -> string | Method | nil,
|
|
1501
|
+
?xml: :text | :attr | nil,
|
|
1502
|
+
?cr_newline: bool,
|
|
1503
|
+
?crlf_newline: bool,
|
|
1504
|
+
?universal_newline: bool
|
|
1505
|
+
) { (File) -> T } -> T
|
|
1506
|
+
|
|
1507
|
+
# <!--
|
|
1508
|
+
# rdoc-file=file.c
|
|
1509
|
+
# - File.owned?(file_name) -> true or false
|
|
1510
|
+
# -->
|
|
1511
|
+
# Returns `true` if the named file exists and the effective user id of the
|
|
1512
|
+
# calling process is the owner of the file.
|
|
1513
|
+
#
|
|
1514
|
+
# *file_name* can be an IO object.
|
|
1515
|
+
#
|
|
1516
|
+
def self.owned?: (path | IO file_name) -> bool
|
|
1517
|
+
|
|
1518
|
+
# <!--
|
|
1519
|
+
# rdoc-file=file.c
|
|
1520
|
+
# - File.path(path) -> string
|
|
1521
|
+
# -->
|
|
1522
|
+
# Returns the string representation of the path
|
|
1523
|
+
#
|
|
1524
|
+
# File.path(File::NULL) #=> "/dev/null"
|
|
1525
|
+
# File.path(Pathname.new("/tmp")) #=> "/tmp"
|
|
1526
|
+
#
|
|
1527
|
+
# If `path` is not a String:
|
|
1528
|
+
#
|
|
1529
|
+
# 1. If it has the `to_path` method, that method will be called to coerce to a
|
|
1530
|
+
# String.
|
|
1531
|
+
#
|
|
1532
|
+
# 2. Otherwise, or if the coerced result is not a String too, the standard
|
|
1533
|
+
# coersion using `to_str` method will take place on that object. (See also
|
|
1534
|
+
# String.try_convert)
|
|
1535
|
+
#
|
|
1536
|
+
# The coerced string must satisfy the following conditions:
|
|
1537
|
+
#
|
|
1538
|
+
# 1. It must be in an ASCII-compatible encoding; otherwise, an
|
|
1539
|
+
# Encoding::CompatibilityError is raised.
|
|
1540
|
+
#
|
|
1541
|
+
# 2. It must not contain the NUL character (<code>\0</code>); otherwise, an
|
|
1542
|
+
# ArgumentError is raised.
|
|
1543
|
+
#
|
|
1544
|
+
def self.path: (path path) -> String
|
|
1545
|
+
|
|
1546
|
+
# <!--
|
|
1547
|
+
# rdoc-file=file.c
|
|
1548
|
+
# - File.pipe?(filepath) -> true or false
|
|
1549
|
+
# -->
|
|
1550
|
+
# Returns `true` if `filepath` points to a pipe, `false` otherwise:
|
|
1551
|
+
#
|
|
1552
|
+
# File.mkfifo('tmp/fifo')
|
|
1553
|
+
# File.pipe?('tmp/fifo') # => true
|
|
1554
|
+
# File.pipe?('t.txt') # => false
|
|
1555
|
+
#
|
|
1556
|
+
def self.pipe?: (path | IO file_name) -> bool
|
|
1557
|
+
|
|
1558
|
+
# <!--
|
|
1559
|
+
# rdoc-file=file.c
|
|
1560
|
+
# - File.readable?(file_name) -> true or false
|
|
1561
|
+
# -->
|
|
1562
|
+
# Returns `true` if the named file is readable by the effective user and group
|
|
1563
|
+
# id of this process. See eaccess(3).
|
|
1564
|
+
#
|
|
1565
|
+
# Note that some OS-level security features may cause this to return true even
|
|
1566
|
+
# though the file is not readable by the effective user/group.
|
|
1567
|
+
#
|
|
1568
|
+
def self.readable?: (path file_name) -> bool
|
|
1569
|
+
|
|
1570
|
+
# <!--
|
|
1571
|
+
# rdoc-file=file.c
|
|
1572
|
+
# - File.readable_real?(file_name) -> true or false
|
|
1573
|
+
# -->
|
|
1574
|
+
# Returns `true` if the named file is readable by the real user and group id of
|
|
1575
|
+
# this process. See access(3).
|
|
1576
|
+
#
|
|
1577
|
+
# Note that some OS-level security features may cause this to return true even
|
|
1578
|
+
# though the file is not readable by the real user/group.
|
|
1579
|
+
#
|
|
1580
|
+
def self.readable_real?: (path file_name) -> bool
|
|
1581
|
+
|
|
1582
|
+
# <!--
|
|
1583
|
+
# rdoc-file=file.c
|
|
1584
|
+
# - File.readlink(link_name) -> file_name
|
|
1585
|
+
# -->
|
|
1586
|
+
# Returns the name of the file referenced by the given link. Not available on
|
|
1587
|
+
# all platforms.
|
|
1588
|
+
#
|
|
1589
|
+
# File.symlink("testfile", "link2test") #=> 0
|
|
1590
|
+
# File.readlink("link2test") #=> "testfile"
|
|
1591
|
+
#
|
|
1592
|
+
def self.readlink: (path link_name) -> String
|
|
1593
|
+
|
|
1594
|
+
# <!--
|
|
1595
|
+
# rdoc-file=file.c
|
|
1596
|
+
# - File.realdirpath(pathname [, dir_string]) -> real_pathname
|
|
1597
|
+
# -->
|
|
1598
|
+
# Returns the real (absolute) pathname of *pathname* in the actual filesystem.
|
|
1599
|
+
# The real pathname doesn't contain symlinks or useless dots.
|
|
1600
|
+
#
|
|
1601
|
+
# If *dir_string* is given, it is used as a base directory for interpreting
|
|
1602
|
+
# relative pathname instead of the current directory.
|
|
1603
|
+
#
|
|
1604
|
+
# The last component of the real pathname can be nonexistent.
|
|
1605
|
+
#
|
|
1606
|
+
def self.realdirpath: (path pathname, ?path dir_string) -> String
|
|
1607
|
+
|
|
1608
|
+
# <!--
|
|
1609
|
+
# rdoc-file=file.c
|
|
1610
|
+
# - File.realpath(pathname [, dir_string]) -> real_pathname
|
|
1611
|
+
# -->
|
|
1612
|
+
# Returns the real (absolute) pathname of *pathname* in the actual filesystem
|
|
1613
|
+
# not containing symlinks or useless dots.
|
|
1614
|
+
#
|
|
1615
|
+
# If *dir_string* is given, it is used as a base directory for interpreting
|
|
1616
|
+
# relative pathname instead of the current directory.
|
|
1617
|
+
#
|
|
1618
|
+
# All components of the pathname must exist when this method is called.
|
|
1619
|
+
#
|
|
1620
|
+
def self.realpath: (path pathname, ?path dir_string) -> String
|
|
1621
|
+
|
|
1622
|
+
# <!--
|
|
1623
|
+
# rdoc-file=file.c
|
|
1624
|
+
# - File.rename(old_name, new_name) -> 0
|
|
1625
|
+
# -->
|
|
1626
|
+
# Renames the given file to the new name. Raises a SystemCallError if the file
|
|
1627
|
+
# cannot be renamed.
|
|
1628
|
+
#
|
|
1629
|
+
# File.rename("afile", "afile.bak") #=> 0
|
|
1630
|
+
#
|
|
1631
|
+
def self.rename: (path old_name, path new_name) -> 0
|
|
1632
|
+
|
|
1633
|
+
# <!--
|
|
1634
|
+
# rdoc-file=file.c
|
|
1635
|
+
# - File.setgid?(file_name) -> true or false
|
|
1636
|
+
# -->
|
|
1637
|
+
# Returns `true` if the named file has the setgid bit set.
|
|
1638
|
+
#
|
|
1639
|
+
# *file_name* can be an IO object.
|
|
1640
|
+
#
|
|
1641
|
+
def self.setgid?: (path | IO file_name) -> bool
|
|
1642
|
+
|
|
1643
|
+
# <!--
|
|
1644
|
+
# rdoc-file=file.c
|
|
1645
|
+
# - File.setuid?(file_name) -> true or false
|
|
1646
|
+
# -->
|
|
1647
|
+
# Returns `true` if the named file has the setuid bit set.
|
|
1648
|
+
#
|
|
1649
|
+
# *file_name* can be an IO object.
|
|
1650
|
+
#
|
|
1651
|
+
def self.setuid?: (path | IO file_name) -> bool
|
|
1652
|
+
|
|
1653
|
+
# <!--
|
|
1654
|
+
# rdoc-file=file.c
|
|
1655
|
+
# - File.size(file_name) -> integer
|
|
1656
|
+
# -->
|
|
1657
|
+
# Returns the size of `file_name`.
|
|
1658
|
+
#
|
|
1659
|
+
# *file_name* can be an IO object.
|
|
1660
|
+
#
|
|
1661
|
+
def self.size: (path | IO file_name) -> Integer
|
|
1662
|
+
|
|
1663
|
+
# <!--
|
|
1664
|
+
# rdoc-file=file.c
|
|
1665
|
+
# - File.size?(file_name) -> Integer or nil
|
|
1666
|
+
# -->
|
|
1667
|
+
# Returns `nil` if `file_name` doesn't exist or has zero size, the size of the
|
|
1668
|
+
# file otherwise.
|
|
1669
|
+
#
|
|
1670
|
+
# *file_name* can be an IO object.
|
|
1671
|
+
#
|
|
1672
|
+
def self.size?: (path | IO file_name) -> Integer?
|
|
1673
|
+
|
|
1674
|
+
# <!--
|
|
1675
|
+
# rdoc-file=file.c
|
|
1676
|
+
# - File.socket?(filepath) -> true or false
|
|
1677
|
+
# -->
|
|
1678
|
+
# Returns `true` if `filepath` points to a socket, `false` otherwise:
|
|
1679
|
+
#
|
|
1680
|
+
# require 'socket'
|
|
1681
|
+
# File.socket?(Socket.new(:INET, :STREAM)) # => true
|
|
1682
|
+
# File.socket?(File.new('t.txt')) # => false
|
|
1683
|
+
#
|
|
1684
|
+
def self.socket?: (path | IO file_name) -> bool
|
|
1685
|
+
|
|
1686
|
+
# <!--
|
|
1687
|
+
# rdoc-file=file.c
|
|
1688
|
+
# - File.split(file_name) -> array
|
|
1689
|
+
# -->
|
|
1690
|
+
# Splits the given string into a directory and a file component and returns them
|
|
1691
|
+
# in a two-element array. See also File::dirname and File::basename.
|
|
1692
|
+
#
|
|
1693
|
+
# File.split("/home/gumby/.profile") #=> ["/home/gumby", ".profile"]
|
|
1694
|
+
#
|
|
1695
|
+
def self.split: (path file_name) -> [ String, String ]
|
|
1696
|
+
|
|
1697
|
+
# <!--
|
|
1698
|
+
# rdoc-file=file.c
|
|
1699
|
+
# - File.stat(filepath) -> stat
|
|
1700
|
+
# -->
|
|
1701
|
+
# Returns a File::Stat object for the file at `filepath` (see File::Stat):
|
|
1702
|
+
#
|
|
1703
|
+
# File.stat('t.txt').class # => File::Stat
|
|
1704
|
+
#
|
|
1705
|
+
def self.stat: (path file_name) -> File::Stat
|
|
1706
|
+
|
|
1707
|
+
# <!--
|
|
1708
|
+
# rdoc-file=file.c
|
|
1709
|
+
# - File.sticky?(file_name) -> true or false
|
|
1710
|
+
# -->
|
|
1711
|
+
# Returns `true` if the named file has the sticky bit set.
|
|
1712
|
+
#
|
|
1713
|
+
# *file_name* can be an IO object.
|
|
1714
|
+
#
|
|
1715
|
+
def self.sticky?: (path | IO file_name) -> bool
|
|
1716
|
+
|
|
1717
|
+
# <!--
|
|
1718
|
+
# rdoc-file=file.c
|
|
1719
|
+
# - File.symlink(old_name, new_name) -> 0
|
|
1720
|
+
# -->
|
|
1721
|
+
# Creates a symbolic link called *new_name* for the existing file *old_name*.
|
|
1722
|
+
# Raises a NotImplemented exception on platforms that do not support symbolic
|
|
1723
|
+
# links.
|
|
1724
|
+
#
|
|
1725
|
+
# File.symlink("testfile", "link2test") #=> 0
|
|
1726
|
+
#
|
|
1727
|
+
def self.symlink: (path old_name, path new_name) -> 0
|
|
1728
|
+
|
|
1729
|
+
# <!--
|
|
1730
|
+
# rdoc-file=file.c
|
|
1731
|
+
# - File.symlink?(filepath) -> true or false
|
|
1732
|
+
# -->
|
|
1733
|
+
# Returns `true` if `filepath` points to a symbolic link, `false` otherwise:
|
|
1734
|
+
#
|
|
1735
|
+
# symlink = File.symlink('t.txt', 'symlink')
|
|
1736
|
+
# File.symlink?('symlink') # => true
|
|
1737
|
+
# File.symlink?('t.txt') # => false
|
|
1738
|
+
#
|
|
1739
|
+
def self.symlink?: (path file_name) -> bool
|
|
1740
|
+
|
|
1741
|
+
# <!--
|
|
1742
|
+
# rdoc-file=file.c
|
|
1743
|
+
# - File.truncate(file_name, integer) -> 0
|
|
1744
|
+
# -->
|
|
1745
|
+
# Truncates the file *file_name* to be at most *integer* bytes long. Not
|
|
1746
|
+
# available on all platforms.
|
|
1747
|
+
#
|
|
1748
|
+
# f = File.new("out", "w")
|
|
1749
|
+
# f.write("1234567890") #=> 10
|
|
1750
|
+
# f.close #=> nil
|
|
1751
|
+
# File.truncate("out", 5) #=> 0
|
|
1752
|
+
# File.size("out") #=> 5
|
|
1753
|
+
#
|
|
1754
|
+
def self.truncate: (path file_name, int length) -> 0
|
|
1755
|
+
|
|
1756
|
+
# <!--
|
|
1757
|
+
# rdoc-file=file.c
|
|
1758
|
+
# - File.umask() -> integer
|
|
1759
|
+
# - File.umask(integer) -> integer
|
|
1760
|
+
# -->
|
|
1761
|
+
# Returns the current umask value for this process. If the optional argument is
|
|
1762
|
+
# given, set the umask to that value and return the previous value. Umask values
|
|
1763
|
+
# are *subtracted* from the default permissions, so a umask of `0222` would make
|
|
1764
|
+
# a file read-only for everyone.
|
|
1765
|
+
#
|
|
1766
|
+
# File.umask(0006) #=> 18
|
|
1767
|
+
# File.umask #=> 6
|
|
1768
|
+
#
|
|
1769
|
+
def self.umask: (?int umask) -> Integer
|
|
1770
|
+
|
|
1771
|
+
# <!--
|
|
1772
|
+
# rdoc-file=file.c
|
|
1773
|
+
# - File.delete(file_name, ...) -> integer
|
|
1774
|
+
# - File.unlink(file_name, ...) -> integer
|
|
1775
|
+
# -->
|
|
1776
|
+
# Deletes the named files, returning the number of names passed as arguments.
|
|
1777
|
+
# Raises an exception on any error. Since the underlying implementation relies
|
|
1778
|
+
# on the <code>unlink(2)</code> system call, the type of exception raised
|
|
1779
|
+
# depends on its error type (see https://linux.die.net/man/2/unlink) and has the
|
|
1780
|
+
# form of e.g. Errno::ENOENT.
|
|
1781
|
+
#
|
|
1782
|
+
# See also Dir::rmdir.
|
|
1783
|
+
#
|
|
1784
|
+
def self.unlink: (*path file_name) -> Integer
|
|
1785
|
+
|
|
1786
|
+
# <!--
|
|
1787
|
+
# rdoc-file=file.c
|
|
1788
|
+
# - File.utime(atime, mtime, file_name, ...) -> integer
|
|
1789
|
+
# -->
|
|
1790
|
+
# Sets the access and modification times of each named file to the first two
|
|
1791
|
+
# arguments. If a file is a symlink, this method acts upon its referent rather
|
|
1792
|
+
# than the link itself; for the inverse behavior see File.lutime. Returns the
|
|
1793
|
+
# number of file names in the argument list.
|
|
1794
|
+
#
|
|
1795
|
+
def self.utime: (Time | Numeric atime, Time | Numeric mtime, *path file_name) -> Integer
|
|
1796
|
+
|
|
1797
|
+
# <!--
|
|
1798
|
+
# rdoc-file=file.c
|
|
1799
|
+
# - File.world_readable?(file_name) -> integer or nil
|
|
1800
|
+
# -->
|
|
1801
|
+
# If *file_name* is readable by others, returns an integer representing the file
|
|
1802
|
+
# permission bits of *file_name*. Returns `nil` otherwise. The meaning of the
|
|
1803
|
+
# bits is platform dependent; on Unix systems, see <code>stat(2)</code>.
|
|
1804
|
+
#
|
|
1805
|
+
# *file_name* can be an IO object.
|
|
1806
|
+
#
|
|
1807
|
+
# File.world_readable?("/etc/passwd") #=> 420
|
|
1808
|
+
# m = File.world_readable?("/etc/passwd")
|
|
1809
|
+
# sprintf("%o", m) #=> "644"
|
|
1810
|
+
#
|
|
1811
|
+
def self.world_readable?: (path | IO file_name) -> Integer?
|
|
1812
|
+
|
|
1813
|
+
# <!--
|
|
1814
|
+
# rdoc-file=file.c
|
|
1815
|
+
# - File.world_writable?(file_name) -> integer or nil
|
|
1816
|
+
# -->
|
|
1817
|
+
# If *file_name* is writable by others, returns an integer representing the file
|
|
1818
|
+
# permission bits of *file_name*. Returns `nil` otherwise. The meaning of the
|
|
1819
|
+
# bits is platform dependent; on Unix systems, see <code>stat(2)</code>.
|
|
1820
|
+
#
|
|
1821
|
+
# *file_name* can be an IO object.
|
|
1822
|
+
#
|
|
1823
|
+
# File.world_writable?("/tmp") #=> 511
|
|
1824
|
+
# m = File.world_writable?("/tmp")
|
|
1825
|
+
# sprintf("%o", m) #=> "777"
|
|
1826
|
+
#
|
|
1827
|
+
def self.world_writable?: (path | IO file_name) -> Integer?
|
|
1828
|
+
|
|
1829
|
+
# <!--
|
|
1830
|
+
# rdoc-file=file.c
|
|
1831
|
+
# - File.writable?(file_name) -> true or false
|
|
1832
|
+
# -->
|
|
1833
|
+
# Returns `true` if the named file is writable by the effective user and group
|
|
1834
|
+
# id of this process. See eaccess(3).
|
|
1835
|
+
#
|
|
1836
|
+
# Note that some OS-level security features may cause this to return true even
|
|
1837
|
+
# though the file is not writable by the effective user/group.
|
|
1838
|
+
#
|
|
1839
|
+
def self.writable?: (path file_name) -> bool
|
|
1840
|
+
|
|
1841
|
+
# <!--
|
|
1842
|
+
# rdoc-file=file.c
|
|
1843
|
+
# - File.writable_real?(file_name) -> true or false
|
|
1844
|
+
# -->
|
|
1845
|
+
# Returns `true` if the named file is writable by the real user and group id of
|
|
1846
|
+
# this process. See access(3).
|
|
1847
|
+
#
|
|
1848
|
+
# Note that some OS-level security features may cause this to return true even
|
|
1849
|
+
# though the file is not writable by the real user/group.
|
|
1850
|
+
#
|
|
1851
|
+
def self.writable_real?: (path file_name) -> bool
|
|
1852
|
+
|
|
1853
|
+
# <!--
|
|
1854
|
+
# rdoc-file=file.c
|
|
1855
|
+
# - File.zero?(file_name) -> true or false
|
|
1856
|
+
# -->
|
|
1857
|
+
# Returns `true` if the named file exists and has a zero size.
|
|
1858
|
+
#
|
|
1859
|
+
# *file_name* can be an IO object.
|
|
1860
|
+
#
|
|
1861
|
+
def self.zero?: (path | IO file_name) -> bool
|
|
1862
|
+
|
|
1863
|
+
# <!--
|
|
1864
|
+
# rdoc-file=file.c
|
|
1865
|
+
# - file.atime -> time
|
|
1866
|
+
# -->
|
|
1867
|
+
# Returns the last access time (a Time object) for *file*, or epoch if *file*
|
|
1868
|
+
# has not been accessed.
|
|
1869
|
+
#
|
|
1870
|
+
# File.new("testfile").atime #=> Wed Dec 31 18:00:00 CST 1969
|
|
1871
|
+
#
|
|
1872
|
+
def atime: () -> Time
|
|
1873
|
+
|
|
1874
|
+
# <!--
|
|
1875
|
+
# rdoc-file=file.c
|
|
1876
|
+
# - file.birthtime -> time
|
|
1877
|
+
# -->
|
|
1878
|
+
# Returns the birth time for *file*.
|
|
1879
|
+
#
|
|
1880
|
+
# File.new("testfile").birthtime #=> Wed Apr 09 08:53:14 CDT 2003
|
|
1881
|
+
#
|
|
1882
|
+
# If the platform doesn't have birthtime, raises NotImplementedError.
|
|
1883
|
+
#
|
|
1884
|
+
def birthtime: () -> Time
|
|
1885
|
+
|
|
1886
|
+
# <!--
|
|
1887
|
+
# rdoc-file=file.c
|
|
1888
|
+
# - file.chmod(mode_int) -> 0
|
|
1889
|
+
# -->
|
|
1890
|
+
# Changes permission bits on *file* to the bit pattern represented by
|
|
1891
|
+
# *mode_int*. Actual effects are platform dependent; on Unix systems, see
|
|
1892
|
+
# <code>chmod(2)</code> for details. Follows symbolic links. Also see
|
|
1893
|
+
# File#lchmod.
|
|
1894
|
+
#
|
|
1895
|
+
# f = File.new("out", "w");
|
|
1896
|
+
# f.chmod(0644) #=> 0
|
|
1897
|
+
#
|
|
1898
|
+
def chmod: (int mode) -> (0 | nil)
|
|
1899
|
+
|
|
1900
|
+
# <!--
|
|
1901
|
+
# rdoc-file=file.c
|
|
1902
|
+
# - file.chown(owner_int, group_int ) -> 0
|
|
1903
|
+
# -->
|
|
1904
|
+
# Changes the owner and group of *file* to the given numeric owner and group
|
|
1905
|
+
# id's. Only a process with superuser privileges may change the owner of a file.
|
|
1906
|
+
# The current owner of a file may change the file's group to any group to which
|
|
1907
|
+
# the owner belongs. A `nil` or -1 owner or group id is ignored. Follows
|
|
1908
|
+
# symbolic links. See also File#lchown.
|
|
1909
|
+
#
|
|
1910
|
+
# File.new("testfile").chown(502, 1000)
|
|
1911
|
+
#
|
|
1912
|
+
def chown: (int? owner, int? group) -> (0 | nil)
|
|
1913
|
+
|
|
1914
|
+
# <!--
|
|
1915
|
+
# rdoc-file=file.c
|
|
1916
|
+
# - file.ctime -> time
|
|
1917
|
+
# -->
|
|
1918
|
+
# Returns the change time for *file* (that is, the time directory information
|
|
1919
|
+
# about the file was changed, not the file itself).
|
|
1920
|
+
#
|
|
1921
|
+
# Note that on Windows (NTFS), returns creation time (birth time).
|
|
1922
|
+
#
|
|
1923
|
+
# File.new("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
|
|
1924
|
+
#
|
|
1925
|
+
def ctime: () -> Time
|
|
1926
|
+
|
|
1927
|
+
# <!--
|
|
1928
|
+
# rdoc-file=file.c
|
|
1929
|
+
# - flock(locking_constant) -> 0 or false
|
|
1930
|
+
# -->
|
|
1931
|
+
# Locks or unlocks file +self+ according to the given `locking_constant`,
|
|
1932
|
+
# a bitwise OR of the values in the table below.
|
|
1933
|
+
# Not available on all platforms.
|
|
1934
|
+
# Returns `false` if <code>File::LOCK_NB</code> is specified and the operation
|
|
1935
|
+
# would have blocked;
|
|
1936
|
+
# otherwise returns `0`.
|
|
1937
|
+
# Constant | Lock | Effect
|
|
1938
|
+
# ---------------|------------|------------------------------------------------------------------------------------------------------------------
|
|
1939
|
+
# +File::LOCK_EX+| Exclusive | Only one process may hold an exclusive lock for +self+ at a time.
|
|
1940
|
+
# +File::LOCK_NB+|Non-blocking|No blocking; may be combined with +File::LOCK_SH+ or +File::LOCK_EX+ using the bitwise OR operator <code>|</code>.
|
|
1941
|
+
# +File::LOCK_SH+| Shared | Multiple processes may each hold a shared lock for +self+ at the same time.
|
|
1942
|
+
# +File::LOCK_UN+| Unlock | Remove an existing lock held by this process.
|
|
1943
|
+
# Example:
|
|
1944
|
+
# # Update a counter using an exclusive lock.
|
|
1945
|
+
# # Don't use File::WRONLY because it truncates the file.
|
|
1946
|
+
# File.open('counter', File::RDWR | File::CREAT, 0644) do |f|
|
|
1947
|
+
# f.flock(File::LOCK_EX)
|
|
1948
|
+
# value = f.read.to_i + 1
|
|
1949
|
+
# f.rewind
|
|
1950
|
+
# f.write("#{value}\n")
|
|
1951
|
+
# f.flush
|
|
1952
|
+
# f.truncate(f.pos)
|
|
1953
|
+
# end
|
|
1954
|
+
#
|
|
1955
|
+
# # Read the counter using a shared lock.
|
|
1956
|
+
# File.open('counter', 'r') do |f|
|
|
1957
|
+
# f.flock(File::LOCK_SH)
|
|
1958
|
+
# f.read
|
|
1959
|
+
# end
|
|
1960
|
+
#
|
|
1961
|
+
def flock: (int locking_constant) -> (0 | false)
|
|
1962
|
+
|
|
1963
|
+
# <!--
|
|
1964
|
+
# rdoc-file=file.c
|
|
1965
|
+
# - lstat -> stat
|
|
1966
|
+
# -->
|
|
1967
|
+
# Like File#stat, but does not follow the last symbolic link; instead, returns a
|
|
1968
|
+
# File::Stat object for the link itself:
|
|
1969
|
+
#
|
|
1970
|
+
# File.symlink('t.txt', 'symlink')
|
|
1971
|
+
# f = File.new('symlink')
|
|
1972
|
+
# f.stat.size # => 47
|
|
1973
|
+
# f.lstat.size # => 11
|
|
1974
|
+
#
|
|
1975
|
+
def lstat: () -> (File::Stat | nil)
|
|
1976
|
+
|
|
1977
|
+
# <!--
|
|
1978
|
+
# rdoc-file=file.c
|
|
1979
|
+
# - file.mtime -> time
|
|
1980
|
+
# -->
|
|
1981
|
+
# Returns the modification time for *file*.
|
|
1982
|
+
#
|
|
1983
|
+
# File.new("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
|
|
1984
|
+
#
|
|
1985
|
+
def mtime: () -> Time
|
|
1986
|
+
|
|
1987
|
+
# <!--
|
|
1988
|
+
# rdoc-file=file.c
|
|
1989
|
+
# - file.path -> filename
|
|
1990
|
+
# - file.to_path -> filename
|
|
1991
|
+
# -->
|
|
1992
|
+
# Returns the pathname used to create *file* as a string. Does not normalize the
|
|
1993
|
+
# name.
|
|
1994
|
+
#
|
|
1995
|
+
# The pathname may not point to the file corresponding to *file*. For instance,
|
|
1996
|
+
# the pathname becomes void when the file has been moved or deleted.
|
|
1997
|
+
#
|
|
1998
|
+
# This method raises IOError for a *file* created using File::Constants::TMPFILE
|
|
1999
|
+
# because they don't have a pathname.
|
|
2000
|
+
#
|
|
2001
|
+
# File.new("testfile").path #=> "testfile"
|
|
2002
|
+
# File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx"
|
|
2003
|
+
#
|
|
2004
|
+
def path: () -> String
|
|
2005
|
+
|
|
2006
|
+
# <!--
|
|
2007
|
+
# rdoc-file=file.c
|
|
2008
|
+
# - file.size -> integer
|
|
2009
|
+
# -->
|
|
2010
|
+
# Returns the size of *file* in bytes.
|
|
2011
|
+
#
|
|
2012
|
+
# File.new("testfile").size #=> 66
|
|
2013
|
+
#
|
|
2014
|
+
def size: () -> Integer
|
|
2015
|
+
|
|
2016
|
+
# <!-- rdoc-file=file.c -->
|
|
2017
|
+
# Returns the pathname used to create *file* as a string. Does not normalize the
|
|
2018
|
+
# name.
|
|
2019
|
+
#
|
|
2020
|
+
# The pathname may not point to the file corresponding to *file*. For instance,
|
|
2021
|
+
# the pathname becomes void when the file has been moved or deleted.
|
|
2022
|
+
#
|
|
2023
|
+
# This method raises IOError for a *file* created using File::Constants::TMPFILE
|
|
2024
|
+
# because they don't have a pathname.
|
|
2025
|
+
#
|
|
2026
|
+
# File.new("testfile").path #=> "testfile"
|
|
2027
|
+
# File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx"
|
|
2028
|
+
#
|
|
2029
|
+
alias to_path path
|
|
2030
|
+
|
|
2031
|
+
# <!--
|
|
2032
|
+
# rdoc-file=file.c
|
|
2033
|
+
# - file.truncate(integer) -> 0
|
|
2034
|
+
# -->
|
|
2035
|
+
# Truncates *file* to at most *integer* bytes. The file must be opened for
|
|
2036
|
+
# writing. Not available on all platforms.
|
|
2037
|
+
#
|
|
2038
|
+
# f = File.new("out", "w")
|
|
2039
|
+
# f.syswrite("1234567890") #=> 10
|
|
2040
|
+
# f.truncate(5) #=> 0
|
|
2041
|
+
# f.close() #=> nil
|
|
2042
|
+
# File.size("out") #=> 5
|
|
2043
|
+
#
|
|
2044
|
+
def truncate: (int length) -> 0
|
|
2045
|
+
end
|