rbs-relaxed 3.9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/dependabot.yml +22 -0
- data/.github/workflows/comments.yml +35 -0
- data/.github/workflows/dependabot.yml +30 -0
- data/.github/workflows/ruby.yml +82 -0
- data/.github/workflows/typecheck.yml +38 -0
- data/.github/workflows/windows.yml +43 -0
- data/.gitignore +23 -0
- data/.rubocop.yml +68 -0
- data/BSDL +22 -0
- data/CHANGELOG.md +1868 -0
- data/COPYING +56 -0
- data/README.md +203 -0
- data/Rakefile +417 -0
- data/Steepfile +44 -0
- data/config.yml +313 -0
- data/core/array.rbs +4062 -0
- data/core/basic_object.rbs +375 -0
- data/core/binding.rbs +150 -0
- data/core/builtin.rbs +277 -0
- data/core/class.rbs +220 -0
- data/core/comparable.rbs +171 -0
- data/core/complex.rbs +786 -0
- data/core/constants.rbs +96 -0
- data/core/data.rbs +415 -0
- data/core/dir.rbs +981 -0
- data/core/encoding.rbs +1371 -0
- data/core/enumerable.rbs +2405 -0
- data/core/enumerator/product.rbs +92 -0
- data/core/enumerator.rbs +630 -0
- data/core/env.rbs +6 -0
- data/core/errno.rbs +673 -0
- data/core/errors.rbs +760 -0
- data/core/exception.rbs +485 -0
- data/core/false_class.rbs +82 -0
- data/core/fiber.rbs +550 -0
- data/core/fiber_error.rbs +11 -0
- data/core/file.rbs +2936 -0
- data/core/file_test.rbs +331 -0
- data/core/float.rbs +1151 -0
- data/core/gc.rbs +644 -0
- data/core/global_variables.rbs +184 -0
- data/core/hash.rbs +1861 -0
- data/core/integer.rbs +1413 -0
- data/core/io/buffer.rbs +984 -0
- data/core/io/wait.rbs +70 -0
- data/core/io.rbs +3406 -0
- data/core/kernel.rbs +3096 -0
- data/core/marshal.rbs +207 -0
- data/core/match_data.rbs +635 -0
- data/core/math.rbs +729 -0
- data/core/method.rbs +386 -0
- data/core/module.rbs +1704 -0
- data/core/nil_class.rbs +209 -0
- data/core/numeric.rbs +818 -0
- data/core/object.rbs +110 -0
- data/core/object_space/weak_key_map.rbs +166 -0
- data/core/object_space.rbs +190 -0
- data/core/proc.rbs +868 -0
- data/core/process.rbs +2296 -0
- data/core/ractor.rbs +1068 -0
- data/core/random.rbs +237 -0
- data/core/range.rbs +1107 -0
- data/core/rational.rbs +531 -0
- data/core/rb_config.rbs +88 -0
- data/core/rbs/unnamed/argf.rbs +1229 -0
- data/core/rbs/unnamed/env_class.rbs +1209 -0
- data/core/rbs/unnamed/random.rbs +293 -0
- data/core/refinement.rbs +59 -0
- data/core/regexp.rbs +1930 -0
- data/core/ruby_vm.rbs +765 -0
- data/core/rubygems/basic_specification.rbs +6 -0
- data/core/rubygems/config_file.rbs +38 -0
- data/core/rubygems/dependency_installer.rbs +6 -0
- data/core/rubygems/errors.rbs +176 -0
- data/core/rubygems/installer.rbs +15 -0
- data/core/rubygems/path_support.rbs +6 -0
- data/core/rubygems/platform.rbs +7 -0
- data/core/rubygems/request_set.rbs +49 -0
- data/core/rubygems/requirement.rbs +148 -0
- data/core/rubygems/rubygems.rbs +1171 -0
- data/core/rubygems/source_list.rbs +15 -0
- data/core/rubygems/specification.rbs +23 -0
- data/core/rubygems/stream_ui.rbs +5 -0
- data/core/rubygems/uninstaller.rbs +10 -0
- data/core/rubygems/version.rbs +294 -0
- data/core/set.rbs +621 -0
- data/core/signal.rbs +100 -0
- data/core/string.rbs +3583 -0
- data/core/struct.rbs +667 -0
- data/core/symbol.rbs +475 -0
- data/core/thread.rbs +1765 -0
- data/core/thread_group.rbs +79 -0
- data/core/time.rbs +1762 -0
- data/core/trace_point.rbs +477 -0
- data/core/true_class.rbs +98 -0
- data/core/unbound_method.rbs +329 -0
- data/core/warning.rbs +87 -0
- data/docs/CONTRIBUTING.md +106 -0
- data/docs/architecture.md +110 -0
- data/docs/collection.md +192 -0
- data/docs/data_and_struct.md +86 -0
- data/docs/gem.md +57 -0
- data/docs/rbs_by_example.md +309 -0
- data/docs/repo.md +125 -0
- data/docs/sigs.md +167 -0
- data/docs/stdlib.md +147 -0
- data/docs/syntax.md +910 -0
- data/docs/tools.md +17 -0
- data/exe/rbs +7 -0
- data/ext/rbs_extension/extconf.rb +15 -0
- data/ext/rbs_extension/lexer.c +2728 -0
- data/ext/rbs_extension/lexer.h +179 -0
- data/ext/rbs_extension/lexer.re +147 -0
- data/ext/rbs_extension/lexstate.c +175 -0
- data/ext/rbs_extension/location.c +325 -0
- data/ext/rbs_extension/location.h +85 -0
- data/ext/rbs_extension/main.c +33 -0
- data/ext/rbs_extension/parser.c +2973 -0
- data/ext/rbs_extension/parser.h +18 -0
- data/ext/rbs_extension/parserstate.c +397 -0
- data/ext/rbs_extension/parserstate.h +163 -0
- data/ext/rbs_extension/rbs_extension.h +31 -0
- data/ext/rbs_extension/unescape.c +32 -0
- data/goodcheck.yml +91 -0
- data/include/rbs/constants.h +82 -0
- data/include/rbs/ruby_objs.h +72 -0
- data/include/rbs/util/rbs_constant_pool.h +219 -0
- data/include/rbs.h +7 -0
- data/lib/rbs/ancestor_graph.rb +92 -0
- data/lib/rbs/annotate/annotations.rb +199 -0
- data/lib/rbs/annotate/formatter.rb +92 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +400 -0
- data/lib/rbs/annotate/rdoc_source.rb +131 -0
- data/lib/rbs/annotate.rb +8 -0
- data/lib/rbs/ast/annotation.rb +29 -0
- data/lib/rbs/ast/comment.rb +29 -0
- data/lib/rbs/ast/declarations.rb +467 -0
- data/lib/rbs/ast/directives.rb +49 -0
- data/lib/rbs/ast/members.rb +451 -0
- data/lib/rbs/ast/type_param.rb +225 -0
- data/lib/rbs/ast/visitor.rb +137 -0
- data/lib/rbs/buffer.rb +67 -0
- data/lib/rbs/builtin_names.rb +58 -0
- data/lib/rbs/cli/colored_io.rb +48 -0
- data/lib/rbs/cli/diff.rb +83 -0
- data/lib/rbs/cli/validate.rb +357 -0
- data/lib/rbs/cli.rb +1223 -0
- data/lib/rbs/collection/cleaner.rb +38 -0
- data/lib/rbs/collection/config/lockfile.rb +92 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +218 -0
- data/lib/rbs/collection/config.rb +81 -0
- data/lib/rbs/collection/installer.rb +32 -0
- data/lib/rbs/collection/sources/base.rb +14 -0
- data/lib/rbs/collection/sources/git.rb +258 -0
- data/lib/rbs/collection/sources/local.rb +81 -0
- data/lib/rbs/collection/sources/rubygems.rb +48 -0
- data/lib/rbs/collection/sources/stdlib.rb +50 -0
- data/lib/rbs/collection/sources.rb +38 -0
- data/lib/rbs/collection.rb +16 -0
- data/lib/rbs/constant.rb +28 -0
- data/lib/rbs/definition.rb +401 -0
- data/lib/rbs/definition_builder/ancestor_builder.rb +620 -0
- data/lib/rbs/definition_builder/method_builder.rb +254 -0
- data/lib/rbs/definition_builder.rb +845 -0
- data/lib/rbs/diff.rb +125 -0
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +829 -0
- data/lib/rbs/environment_loader.rb +173 -0
- data/lib/rbs/environment_walker.rb +155 -0
- data/lib/rbs/errors.rb +645 -0
- data/lib/rbs/factory.rb +18 -0
- data/lib/rbs/file_finder.rb +28 -0
- data/lib/rbs/location_aux.rb +138 -0
- data/lib/rbs/locator.rb +243 -0
- data/lib/rbs/method_type.rb +143 -0
- data/lib/rbs/namespace.rb +125 -0
- data/lib/rbs/parser/lex_result.rb +15 -0
- data/lib/rbs/parser/token.rb +23 -0
- data/lib/rbs/parser_aux.rb +114 -0
- data/lib/rbs/prototype/helpers.rb +140 -0
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +840 -0
- data/lib/rbs/prototype/rbi.rb +641 -0
- data/lib/rbs/prototype/runtime/helpers.rb +59 -0
- data/lib/rbs/prototype/runtime/reflection.rb +19 -0
- data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
- data/lib/rbs/prototype/runtime.rb +667 -0
- data/lib/rbs/repository.rb +127 -0
- data/lib/rbs/resolver/constant_resolver.rb +219 -0
- data/lib/rbs/resolver/type_name_resolver.rb +91 -0
- data/lib/rbs/sorter.rb +198 -0
- data/lib/rbs/substitution.rb +83 -0
- data/lib/rbs/subtractor.rb +201 -0
- data/lib/rbs/test/errors.rb +80 -0
- data/lib/rbs/test/guaranteed.rb +30 -0
- data/lib/rbs/test/hook.rb +212 -0
- data/lib/rbs/test/observer.rb +19 -0
- data/lib/rbs/test/setup.rb +84 -0
- data/lib/rbs/test/setup_helper.rb +50 -0
- data/lib/rbs/test/tester.rb +167 -0
- data/lib/rbs/test/type_check.rb +435 -0
- data/lib/rbs/test.rb +112 -0
- data/lib/rbs/type_alias_dependency.rb +100 -0
- data/lib/rbs/type_alias_regularity.rb +126 -0
- data/lib/rbs/type_name.rb +109 -0
- data/lib/rbs/types.rb +1596 -0
- data/lib/rbs/unit_test/convertibles.rb +176 -0
- data/lib/rbs/unit_test/spy.rb +138 -0
- data/lib/rbs/unit_test/type_assertions.rb +347 -0
- data/lib/rbs/unit_test/with_aliases.rb +143 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/validator.rb +186 -0
- data/lib/rbs/variance_calculator.rb +189 -0
- data/lib/rbs/vendorer.rb +71 -0
- data/lib/rbs/version.rb +5 -0
- data/lib/rbs/writer.rb +424 -0
- data/lib/rbs.rb +94 -0
- data/lib/rdoc/discover.rb +20 -0
- data/lib/rdoc_plugin/parser.rb +163 -0
- data/rbs-relaxed.gemspec +48 -0
- data/schema/annotation.json +14 -0
- data/schema/comment.json +26 -0
- data/schema/decls.json +326 -0
- data/schema/function.json +87 -0
- data/schema/location.json +56 -0
- data/schema/members.json +266 -0
- data/schema/methodType.json +50 -0
- data/schema/typeParam.json +36 -0
- data/schema/types.json +317 -0
- data/sig/ancestor_builder.rbs +163 -0
- data/sig/ancestor_graph.rbs +60 -0
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +82 -0
- data/sig/annotate/rdoc_source.rbs +30 -0
- data/sig/annotation.rbs +27 -0
- data/sig/buffer.rbs +32 -0
- data/sig/builtin_names.rbs +44 -0
- data/sig/cli/colored_io.rbs +15 -0
- data/sig/cli/diff.rbs +21 -0
- data/sig/cli/validate.rbs +43 -0
- data/sig/cli.rbs +87 -0
- data/sig/collection/cleaner.rbs +13 -0
- data/sig/collection/config/lockfile.rbs +74 -0
- data/sig/collection/config/lockfile_generator.rbs +66 -0
- data/sig/collection/config.rbs +46 -0
- data/sig/collection/installer.rbs +17 -0
- data/sig/collection/sources.rbs +214 -0
- data/sig/collection.rbs +4 -0
- data/sig/comment.rbs +26 -0
- data/sig/constant.rbs +21 -0
- data/sig/declarations.rbs +267 -0
- data/sig/definition.rbs +173 -0
- data/sig/definition_builder.rbs +165 -0
- data/sig/diff.rbs +28 -0
- data/sig/directives.rbs +77 -0
- data/sig/environment.rbs +279 -0
- data/sig/environment_loader.rbs +111 -0
- data/sig/environment_walker.rbs +65 -0
- data/sig/errors.rbs +405 -0
- data/sig/factory.rbs +5 -0
- data/sig/file_finder.rbs +28 -0
- data/sig/location.rbs +110 -0
- data/sig/locator.rbs +58 -0
- data/sig/manifest.yaml +7 -0
- data/sig/members.rbs +258 -0
- data/sig/method_builder.rbs +84 -0
- data/sig/method_types.rbs +58 -0
- data/sig/namespace.rbs +146 -0
- data/sig/parser.rbs +100 -0
- data/sig/prototype/helpers.rbs +27 -0
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/prototype/rb.rbs +96 -0
- data/sig/prototype/rbi.rbs +75 -0
- data/sig/prototype/runtime.rbs +182 -0
- data/sig/rbs.rbs +21 -0
- data/sig/rdoc/rbs.rbs +67 -0
- data/sig/repository.rbs +85 -0
- data/sig/resolver/constant_resolver.rbs +92 -0
- data/sig/resolver/context.rbs +34 -0
- data/sig/resolver/type_name_resolver.rbs +35 -0
- data/sig/shims/bundler.rbs +38 -0
- data/sig/shims/enumerable.rbs +5 -0
- data/sig/shims/rubygems.rbs +19 -0
- data/sig/sorter.rbs +41 -0
- data/sig/substitution.rbs +48 -0
- data/sig/subtractor.rbs +37 -0
- data/sig/test/errors.rbs +52 -0
- data/sig/test/guranteed.rbs +9 -0
- data/sig/test/type_check.rbs +19 -0
- data/sig/test.rbs +82 -0
- data/sig/type_alias_dependency.rbs +53 -0
- data/sig/type_alias_regularity.rbs +98 -0
- data/sig/type_param.rbs +110 -0
- data/sig/typename.rbs +79 -0
- data/sig/types.rbs +579 -0
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +30 -0
- data/sig/unit_test/type_assertions.rbs +196 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/sig/use_map.rbs +35 -0
- data/sig/util.rbs +9 -0
- data/sig/validator.rbs +63 -0
- data/sig/variance_calculator.rbs +87 -0
- data/sig/vendorer.rbs +51 -0
- data/sig/version.rbs +3 -0
- data/sig/visitor.rbs +47 -0
- data/sig/writer.rbs +127 -0
- data/src/constants.c +153 -0
- data/src/ruby_objs.c +795 -0
- data/src/util/rbs_constant_pool.c +342 -0
- data/stdlib/abbrev/0/abbrev.rbs +66 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +355 -0
- data/stdlib/benchmark/0/benchmark.rbs +452 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +1629 -0
- data/stdlib/bigdecimal-math/0/big_math.rbs +119 -0
- data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
- data/stdlib/cgi/0/core.rbs +1285 -0
- data/stdlib/cgi/0/manifest.yaml +3 -0
- data/stdlib/coverage/0/coverage.rbs +263 -0
- data/stdlib/csv/0/csv.rbs +3776 -0
- data/stdlib/csv/0/manifest.yaml +3 -0
- data/stdlib/date/0/date.rbs +1585 -0
- data/stdlib/date/0/date_time.rbs +616 -0
- data/stdlib/date/0/time.rbs +26 -0
- data/stdlib/dbm/0/dbm.rbs +421 -0
- data/stdlib/delegate/0/delegator.rbs +184 -0
- data/stdlib/delegate/0/kernel.rbs +47 -0
- data/stdlib/delegate/0/simple_delegator.rbs +96 -0
- data/stdlib/did_you_mean/0/did_you_mean.rbs +343 -0
- data/stdlib/digest/0/digest.rbs +577 -0
- data/stdlib/erb/0/erb.rbs +532 -0
- data/stdlib/etc/0/etc.rbs +865 -0
- data/stdlib/fileutils/0/fileutils.rbs +1734 -0
- data/stdlib/find/0/find.rbs +49 -0
- data/stdlib/forwardable/0/forwardable.rbs +268 -0
- data/stdlib/io-console/0/io-console.rbs +414 -0
- data/stdlib/ipaddr/0/ipaddr.rbs +428 -0
- data/stdlib/json/0/json.rbs +1916 -0
- data/stdlib/kconv/0/kconv.rbs +166 -0
- data/stdlib/logger/0/formatter.rbs +45 -0
- data/stdlib/logger/0/log_device.rbs +100 -0
- data/stdlib/logger/0/logger.rbs +796 -0
- data/stdlib/logger/0/manifest.yaml +2 -0
- data/stdlib/logger/0/period.rbs +17 -0
- data/stdlib/logger/0/severity.rbs +34 -0
- data/stdlib/minitest/0/kernel.rbs +42 -0
- data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
- data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
- data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
- data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
- data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
- data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
- data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
- data/stdlib/minitest/0/minitest/compress.rbs +13 -0
- data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
- data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
- data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
- data/stdlib/minitest/0/minitest/guard.rbs +64 -0
- data/stdlib/minitest/0/minitest/mock.rbs +64 -0
- data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
- data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
- data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
- data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
- data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
- data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
- data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
- data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
- data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
- data/stdlib/minitest/0/minitest/result.rbs +28 -0
- data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
- data/stdlib/minitest/0/minitest/skip.rbs +6 -0
- data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
- data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
- data/stdlib/minitest/0/minitest/spec.rbs +11 -0
- data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
- data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
- data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
- data/stdlib/minitest/0/minitest/test.rbs +69 -0
- data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
- data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
- data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
- data/stdlib/minitest/0/minitest/unit.rbs +4 -0
- data/stdlib/minitest/0/minitest.rbs +115 -0
- data/stdlib/monitor/0/monitor.rbs +363 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
- data/stdlib/net-http/0/manifest.yaml +3 -0
- data/stdlib/net-http/0/net-http.rbs +5552 -0
- data/stdlib/net-protocol/0/manifest.yaml +2 -0
- data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
- data/stdlib/net-smtp/0/manifest.yaml +2 -0
- data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
- data/stdlib/nkf/0/nkf.rbs +402 -0
- data/stdlib/objspace/0/objspace.rbs +487 -0
- data/stdlib/observable/0/observable.rbs +217 -0
- data/stdlib/open-uri/0/manifest.yaml +4 -0
- data/stdlib/open-uri/0/open-uri.rbs +393 -0
- data/stdlib/open3/0/open3.rbs +147 -0
- data/stdlib/openssl/0/manifest.yaml +3 -0
- data/stdlib/openssl/0/openssl.rbs +12113 -0
- data/stdlib/optparse/0/optparse.rbs +1725 -0
- data/stdlib/pathname/0/pathname.rbs +1406 -0
- data/stdlib/pp/0/manifest.yaml +2 -0
- data/stdlib/pp/0/pp.rbs +300 -0
- data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
- data/stdlib/pstore/0/pstore.rbs +603 -0
- data/stdlib/psych/0/core_ext.rbs +12 -0
- data/stdlib/psych/0/dbm.rbs +237 -0
- data/stdlib/psych/0/manifest.yaml +3 -0
- data/stdlib/psych/0/psych.rbs +402 -0
- data/stdlib/psych/0/store.rbs +59 -0
- data/stdlib/pty/0/pty.rbs +237 -0
- data/stdlib/rdoc/0/code_object.rbs +51 -0
- data/stdlib/rdoc/0/comment.rbs +59 -0
- data/stdlib/rdoc/0/context.rbs +153 -0
- data/stdlib/rdoc/0/markup.rbs +117 -0
- data/stdlib/rdoc/0/parser.rbs +56 -0
- data/stdlib/rdoc/0/rdoc.rbs +391 -0
- data/stdlib/rdoc/0/ri.rbs +17 -0
- data/stdlib/rdoc/0/store.rbs +48 -0
- data/stdlib/rdoc/0/top_level.rbs +97 -0
- data/stdlib/resolv/0/manifest.yaml +3 -0
- data/stdlib/resolv/0/resolv.rbs +1830 -0
- data/stdlib/ripper/0/ripper.rbs +1648 -0
- data/stdlib/securerandom/0/securerandom.rbs +62 -0
- data/stdlib/shellwords/0/shellwords.rbs +229 -0
- data/stdlib/singleton/0/singleton.rbs +131 -0
- data/stdlib/socket/0/addrinfo.rbs +666 -0
- data/stdlib/socket/0/basic_socket.rbs +590 -0
- data/stdlib/socket/0/constants.rbs +2295 -0
- data/stdlib/socket/0/ip_socket.rbs +92 -0
- data/stdlib/socket/0/socket.rbs +4157 -0
- data/stdlib/socket/0/socket_error.rbs +5 -0
- data/stdlib/socket/0/tcp_server.rbs +192 -0
- data/stdlib/socket/0/tcp_socket.rbs +79 -0
- data/stdlib/socket/0/udp_socket.rbs +133 -0
- data/stdlib/socket/0/unix_server.rbs +169 -0
- data/stdlib/socket/0/unix_socket.rbs +172 -0
- data/stdlib/stringio/0/stringio.rbs +567 -0
- data/stdlib/strscan/0/string_scanner.rbs +1627 -0
- data/stdlib/tempfile/0/tempfile.rbs +479 -0
- data/stdlib/time/0/time.rbs +432 -0
- data/stdlib/timeout/0/timeout.rbs +81 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
- data/stdlib/tsort/0/cyclic.rbs +5 -0
- data/stdlib/tsort/0/interfaces.rbs +20 -0
- data/stdlib/tsort/0/tsort.rbs +409 -0
- data/stdlib/uri/0/common.rbs +582 -0
- data/stdlib/uri/0/file.rbs +118 -0
- data/stdlib/uri/0/ftp.rbs +13 -0
- data/stdlib/uri/0/generic.rbs +1108 -0
- data/stdlib/uri/0/http.rbs +104 -0
- data/stdlib/uri/0/https.rbs +14 -0
- data/stdlib/uri/0/ldap.rbs +230 -0
- data/stdlib/uri/0/ldaps.rbs +14 -0
- data/stdlib/uri/0/mailto.rbs +92 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
- data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
- data/stdlib/uri/0/ws.rbs +13 -0
- data/stdlib/uri/0/wss.rbs +9 -0
- data/stdlib/yaml/0/manifest.yaml +2 -0
- data/stdlib/yaml/0/yaml.rbs +1 -0
- data/stdlib/zlib/0/buf_error.rbs +10 -0
- data/stdlib/zlib/0/data_error.rbs +10 -0
- data/stdlib/zlib/0/deflate.rbs +210 -0
- data/stdlib/zlib/0/error.rbs +20 -0
- data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
- data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
- data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
- data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
- data/stdlib/zlib/0/gzip_file.rbs +156 -0
- data/stdlib/zlib/0/gzip_reader.rbs +293 -0
- data/stdlib/zlib/0/gzip_writer.rbs +166 -0
- data/stdlib/zlib/0/inflate.rbs +180 -0
- data/stdlib/zlib/0/mem_error.rbs +10 -0
- data/stdlib/zlib/0/need_dict.rbs +13 -0
- data/stdlib/zlib/0/stream_end.rbs +11 -0
- data/stdlib/zlib/0/stream_error.rbs +11 -0
- data/stdlib/zlib/0/version_error.rbs +11 -0
- data/stdlib/zlib/0/zlib.rbs +449 -0
- data/stdlib/zlib/0/zstream.rbs +200 -0
- metadata +532 -0
data/core/file.rbs
ADDED
@@ -0,0 +1,2936 @@
|
|
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
|
+
# `File.exist?`.
|
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 `'r'` and `'r+'` are not allowed for a non-existent file
|
97
|
+
# (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
|
+
# * `'r'`:
|
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
|
+
# * `'w'`:
|
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
|
+
# * `'a'`:
|
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
|
+
# * `'r+'`:
|
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
|
+
# * `'a+'`:
|
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 `'r'` and `'r+'` are not allowed for a non-existent file
|
323
|
+
# (exception raised).
|
324
|
+
#
|
325
|
+
# * `'w'`:
|
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
|
+
# * `'a'`:
|
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
|
+
# * `'w+'`:
|
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
|
+
# * `'a+'`:
|
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
|
+
# * `'t'`: Text data; sets the default external encoding to `Encoding::UTF_8`;
|
510
|
+
# on Windows, enables conversion between EOL and CRLF and enables
|
511
|
+
# interpreting `0x1A` as an end-of-file marker.
|
512
|
+
# * `'b'`: Binary data; sets the default external encoding to
|
513
|
+
# `Encoding::ASCII_8BIT`; on Windows, suppresses conversion between EOL and
|
514
|
+
# CRLF and disables interpreting `0x1A` as an end-of-file marker.
|
515
|
+
#
|
516
|
+
# If neither is given, the stream defaults to text data.
|
517
|
+
#
|
518
|
+
# Examples:
|
519
|
+
#
|
520
|
+
# File.new('t.txt', 'rt')
|
521
|
+
# File.new('t.dat', 'rb')
|
522
|
+
#
|
523
|
+
# When the data mode is specified, the read/write mode may not be omitted, and
|
524
|
+
# the data mode must precede the file-create mode, if given:
|
525
|
+
#
|
526
|
+
# File.new('t.dat', 'b') # Raises an exception.
|
527
|
+
# File.new('t.dat', 'rxb') # Raises an exception.
|
528
|
+
#
|
529
|
+
# #### File-Create Mode
|
530
|
+
#
|
531
|
+
# The following may be suffixed to any writable string mode above:
|
532
|
+
#
|
533
|
+
# * `'x'`: Creates the file if it does not exist; raises an exception if the
|
534
|
+
# file exists.
|
535
|
+
#
|
536
|
+
# Example:
|
537
|
+
#
|
538
|
+
# File.new('t.tmp', 'wx')
|
539
|
+
#
|
540
|
+
# When the file-create mode is specified, the read/write mode may not be
|
541
|
+
# omitted, and the file-create mode must follow the data mode:
|
542
|
+
#
|
543
|
+
# File.new('t.dat', 'x') # Raises an exception.
|
544
|
+
# File.new('t.dat', 'rxb') # Raises an exception.
|
545
|
+
#
|
546
|
+
# ### Integer Access Modes
|
547
|
+
#
|
548
|
+
# When mode is an integer it must be one or more of the following constants,
|
549
|
+
# which may be combined by the bitwise OR operator `|`:
|
550
|
+
#
|
551
|
+
# * `File::RDONLY`: Open for reading only.
|
552
|
+
# * `File::WRONLY`: Open for writing only.
|
553
|
+
# * `File::RDWR`: Open for reading and writing.
|
554
|
+
# * `File::APPEND`: Open for appending only.
|
555
|
+
#
|
556
|
+
# Examples:
|
557
|
+
#
|
558
|
+
# File.new('t.txt', File::RDONLY)
|
559
|
+
# File.new('t.tmp', File::RDWR | File::CREAT | File::EXCL)
|
560
|
+
#
|
561
|
+
# Note: Method IO#set_encoding does not allow the mode to be specified as an
|
562
|
+
# integer.
|
563
|
+
#
|
564
|
+
# ### File-Create Mode Specified as an Integer
|
565
|
+
#
|
566
|
+
# These constants may also be ORed into the integer mode:
|
567
|
+
#
|
568
|
+
# * `File::CREAT`: Create file if it does not exist.
|
569
|
+
# * `File::EXCL`: Raise an exception if `File::CREAT` is given and the file
|
570
|
+
# exists.
|
571
|
+
#
|
572
|
+
# ### Data Mode Specified as an Integer
|
573
|
+
#
|
574
|
+
# Data mode cannot be specified as an integer. When the stream access mode is
|
575
|
+
# given as an integer, the data mode is always text, never binary.
|
576
|
+
#
|
577
|
+
# Note that although there is a constant `File::BINARY`, setting its value in an
|
578
|
+
# integer stream mode has no effect; this is because, as documented in
|
579
|
+
# File::Constants, the `File::BINARY` value disables line code conversion, but
|
580
|
+
# does not change the external encoding.
|
581
|
+
#
|
582
|
+
# ### Encodings
|
583
|
+
#
|
584
|
+
# Any of the string modes above may specify encodings - either external encoding
|
585
|
+
# only or both external and internal encodings - by appending one or both
|
586
|
+
# encoding names, separated by colons:
|
587
|
+
#
|
588
|
+
# f = File.new('t.dat', 'rb')
|
589
|
+
# f.external_encoding # => #<Encoding:ASCII-8BIT>
|
590
|
+
# f.internal_encoding # => nil
|
591
|
+
# f = File.new('t.dat', 'rb:UTF-16')
|
592
|
+
# f.external_encoding # => #<Encoding:UTF-16 (dummy)>
|
593
|
+
# f.internal_encoding # => nil
|
594
|
+
# f = File.new('t.dat', 'rb:UTF-16:UTF-16')
|
595
|
+
# f.external_encoding # => #<Encoding:UTF-16 (dummy)>
|
596
|
+
# f.internal_encoding # => #<Encoding:UTF-16>
|
597
|
+
# f.close
|
598
|
+
#
|
599
|
+
# The numerous encoding names are available in array Encoding.name_list:
|
600
|
+
#
|
601
|
+
# Encoding.name_list.take(3) # => ["ASCII-8BIT", "UTF-8", "US-ASCII"]
|
602
|
+
#
|
603
|
+
# When the external encoding is set, strings read are tagged by that encoding
|
604
|
+
# when reading, and strings written are converted to that encoding when writing.
|
605
|
+
#
|
606
|
+
# When both external and internal encodings are set, strings read are converted
|
607
|
+
# from external to internal encoding, and strings written are converted from
|
608
|
+
# internal to external encoding. For further details about transcoding input and
|
609
|
+
# output, see [Encodings](rdoc-ref:encodings.rdoc@Encodings).
|
610
|
+
#
|
611
|
+
# If the external encoding is `'BOM|UTF-8'`, `'BOM|UTF-16LE'` or
|
612
|
+
# `'BOM|UTF16-BE'`, Ruby checks for a Unicode BOM in the input document to help
|
613
|
+
# determine the encoding. For UTF-16 encodings the file open mode must be
|
614
|
+
# binary. If the BOM is found, it is stripped and the external encoding from the
|
615
|
+
# BOM is used.
|
616
|
+
#
|
617
|
+
# Note that the BOM-style encoding option is case insensitive, so `'bom|utf-8'`
|
618
|
+
# is also valid.
|
619
|
+
#
|
620
|
+
# ## File Permissions
|
621
|
+
#
|
622
|
+
# A File object has *permissions*, an octal integer representing the permissions
|
623
|
+
# of an actual file in the underlying platform.
|
624
|
+
#
|
625
|
+
# Note that file permissions are quite different from the *mode* of a file
|
626
|
+
# stream (File object).
|
627
|
+
#
|
628
|
+
# In a File object, the permissions are available thus, where method `mode`,
|
629
|
+
# despite its name, returns permissions:
|
630
|
+
#
|
631
|
+
# f = File.new('t.txt')
|
632
|
+
# f.lstat.mode.to_s(8) # => "100644"
|
633
|
+
#
|
634
|
+
# On a Unix-based operating system, the three low-order octal digits represent
|
635
|
+
# the permissions for owner (6), group (4), and world (4). The triplet of bits
|
636
|
+
# in each octal digit represent, respectively, read, write, and execute
|
637
|
+
# permissions.
|
638
|
+
#
|
639
|
+
# Permissions `0644` thus represent read-write access for owner and read-only
|
640
|
+
# access for group and world. See man pages
|
641
|
+
# [open(2)](https://www.unix.com/man-page/bsd/2/open) and
|
642
|
+
# [chmod(2)](https://www.unix.com/man-page/bsd/2/chmod).
|
643
|
+
#
|
644
|
+
# For a directory, the meaning of the execute bit changes: when set, the
|
645
|
+
# directory can be searched.
|
646
|
+
#
|
647
|
+
# Higher-order bits in permissions may indicate the type of file (plain,
|
648
|
+
# directory, pipe, socket, etc.) and various other special features.
|
649
|
+
#
|
650
|
+
# On non-Posix operating systems, permissions may include only read-only or
|
651
|
+
# read-write, in which case, the remaining permission will resemble typical
|
652
|
+
# values. On Windows, for instance, the default permissions are `0644`; The only
|
653
|
+
# change that can be made is to make the file read-only, which is reported as
|
654
|
+
# `0444`.
|
655
|
+
#
|
656
|
+
# For a method that actually creates a file in the underlying platform (as
|
657
|
+
# opposed to merely creating a File object), permissions may be specified:
|
658
|
+
#
|
659
|
+
# File.new('t.tmp', File::CREAT, 0644)
|
660
|
+
# File.new('t.tmp', File::CREAT, 0444)
|
661
|
+
#
|
662
|
+
# Permissions may also be changed:
|
663
|
+
#
|
664
|
+
# f = File.new('t.tmp', File::CREAT, 0444)
|
665
|
+
# f.chmod(0644)
|
666
|
+
# f.chmod(0444)
|
667
|
+
#
|
668
|
+
# ## File Constants
|
669
|
+
#
|
670
|
+
# Various constants for use in File and IO methods may be found in module
|
671
|
+
# File::Constants; an array of their names is returned by
|
672
|
+
# `File::Constants.constants`.
|
673
|
+
#
|
674
|
+
# ## What's Here
|
675
|
+
#
|
676
|
+
# First, what's elsewhere. Class File:
|
677
|
+
#
|
678
|
+
# * Inherits from [class IO](rdoc-ref:IO@What-27s+Here), in particular,
|
679
|
+
# methods for creating, reading, and writing files
|
680
|
+
# * Includes module FileTest, which provides dozens of additional methods.
|
681
|
+
#
|
682
|
+
# Here, class File provides methods that are useful for:
|
683
|
+
#
|
684
|
+
# * [Creating](rdoc-ref:File@Creating)
|
685
|
+
# * [Querying](rdoc-ref:File@Querying)
|
686
|
+
# * [Settings](rdoc-ref:File@Settings)
|
687
|
+
# * [Other](rdoc-ref:File@Other)
|
688
|
+
#
|
689
|
+
# ### Creating
|
690
|
+
#
|
691
|
+
# * ::new: Opens the file at the given path; returns the file.
|
692
|
+
# * ::open: Same as ::new, but when given a block will yield the file to the
|
693
|
+
# block, and close the file upon exiting the block.
|
694
|
+
# * ::link: Creates a new name for an existing file using a hard link.
|
695
|
+
# * ::mkfifo: Returns the FIFO file created at the given path.
|
696
|
+
# * ::symlink: Creates a symbolic link for the given file path.
|
697
|
+
#
|
698
|
+
# ### Querying
|
699
|
+
#
|
700
|
+
# *Paths*
|
701
|
+
#
|
702
|
+
# * ::absolute_path: Returns the absolute file path for the given path.
|
703
|
+
# * ::absolute_path?: Returns whether the given path is the absolute file
|
704
|
+
# path.
|
705
|
+
# * ::basename: Returns the last component of the given file path.
|
706
|
+
# * ::dirname: Returns all but the last component of the given file path.
|
707
|
+
# * ::expand_path: Returns the absolute file path for the given path,
|
708
|
+
# expanding `~` for a home directory.
|
709
|
+
# * ::extname: Returns the file extension for the given file path.
|
710
|
+
# * ::fnmatch? (aliased as ::fnmatch): Returns whether the given file path
|
711
|
+
# matches the given pattern.
|
712
|
+
# * ::join: Joins path components into a single path string.
|
713
|
+
# * ::path: Returns the string representation of the given path.
|
714
|
+
# * ::readlink: Returns the path to the file at the given symbolic link.
|
715
|
+
# * ::realdirpath: Returns the real path for the given file path, where the
|
716
|
+
# last component need not exist.
|
717
|
+
# * ::realpath: Returns the real path for the given file path, where all
|
718
|
+
# components must exist.
|
719
|
+
# * ::split: Returns an array of two strings: the directory name and basename
|
720
|
+
# of the file at the given path.
|
721
|
+
# * #path (aliased as #to_path): Returns the string representation of the
|
722
|
+
# given path.
|
723
|
+
#
|
724
|
+
# *Times*
|
725
|
+
#
|
726
|
+
# * ::atime: Returns a Time for the most recent access to the given file.
|
727
|
+
# * ::birthtime: Returns a Time for the creation of the given file.
|
728
|
+
# * ::ctime: Returns a Time for the metadata change of the given file.
|
729
|
+
# * ::mtime: Returns a Time for the most recent data modification to the
|
730
|
+
# content of the given file.
|
731
|
+
# * #atime: Returns a Time for the most recent access to `self`.
|
732
|
+
# * #birthtime: Returns a Time the creation for `self`.
|
733
|
+
# * #ctime: Returns a Time for the metadata change of `self`.
|
734
|
+
# * #mtime: Returns a Time for the most recent data modification to the
|
735
|
+
# content of `self`.
|
736
|
+
#
|
737
|
+
# *Types*
|
738
|
+
#
|
739
|
+
# * ::blockdev?: Returns whether the file at the given path is a block device.
|
740
|
+
# * ::chardev?: Returns whether the file at the given path is a character
|
741
|
+
# device.
|
742
|
+
# * ::directory?: Returns whether the file at the given path is a directory.
|
743
|
+
# * ::executable?: Returns whether the file at the given path is executable by
|
744
|
+
# the effective user and group of the current process.
|
745
|
+
# * ::executable_real?: Returns whether the file at the given path is
|
746
|
+
# executable by the real user and group of the current process.
|
747
|
+
# * ::exist?: Returns whether the file at the given path exists.
|
748
|
+
# * ::file?: Returns whether the file at the given path is a regular file.
|
749
|
+
# * ::ftype: Returns a string giving the type of the file at the given path.
|
750
|
+
# * ::grpowned?: Returns whether the effective group of the current process
|
751
|
+
# owns the file at the given path.
|
752
|
+
# * ::identical?: Returns whether the files at two given paths are identical.
|
753
|
+
# * ::lstat: Returns the File::Stat object for the last symbolic link in the
|
754
|
+
# given path.
|
755
|
+
# * ::owned?: Returns whether the effective user of the current process owns
|
756
|
+
# the file at the given path.
|
757
|
+
# * ::pipe?: Returns whether the file at the given path is a pipe.
|
758
|
+
# * ::readable?: Returns whether the file at the given path is readable by the
|
759
|
+
# effective user and group of the current process.
|
760
|
+
# * ::readable_real?: Returns whether the file at the given path is readable
|
761
|
+
# by the real user and group of the current process.
|
762
|
+
# * ::setgid?: Returns whether the setgid bit is set for the file at the given
|
763
|
+
# path.
|
764
|
+
# * ::setuid?: Returns whether the setuid bit is set for the file at the given
|
765
|
+
# path.
|
766
|
+
# * ::socket?: Returns whether the file at the given path is a socket.
|
767
|
+
# * ::stat: Returns the File::Stat object for the file at the given path.
|
768
|
+
# * ::sticky?: Returns whether the file at the given path has its sticky bit
|
769
|
+
# set.
|
770
|
+
# * ::symlink?: Returns whether the file at the given path is a symbolic link.
|
771
|
+
# * ::umask: Returns the umask value for the current process.
|
772
|
+
# * ::world_readable?: Returns whether the file at the given path is readable
|
773
|
+
# by others.
|
774
|
+
# * ::world_writable?: Returns whether the file at the given path is writable
|
775
|
+
# by others.
|
776
|
+
# * ::writable?: Returns whether the file at the given path is writable by the
|
777
|
+
# effective user and group of the current process.
|
778
|
+
# * ::writable_real?: Returns whether the file at the given path is writable
|
779
|
+
# by the real user and group of the current process.
|
780
|
+
# * #lstat: Returns the File::Stat object for the last symbolic link in the
|
781
|
+
# path for `self`.
|
782
|
+
#
|
783
|
+
# *Contents*
|
784
|
+
#
|
785
|
+
# * ::empty? (aliased as ::zero?): Returns whether the file at the given path
|
786
|
+
# exists and is empty.
|
787
|
+
# * ::size: Returns the size (bytes) of the file at the given path.
|
788
|
+
# * ::size?: Returns `nil` if there is no file at the given path, or if that
|
789
|
+
# file is empty; otherwise returns the file size (bytes).
|
790
|
+
# * #size: Returns the size (bytes) of `self`.
|
791
|
+
#
|
792
|
+
# ### Settings
|
793
|
+
#
|
794
|
+
# * ::chmod: Changes permissions of the file at the given path.
|
795
|
+
# * ::chown: Change ownership of the file at the given path.
|
796
|
+
# * ::lchmod: Changes permissions of the last symbolic link in the given path.
|
797
|
+
# * ::lchown: Change ownership of the last symbolic in the given path.
|
798
|
+
# * ::lutime: For each given file path, sets the access time and modification
|
799
|
+
# time of the last symbolic link in the path.
|
800
|
+
# * ::rename: Moves the file at one given path to another given path.
|
801
|
+
# * ::utime: Sets the access time and modification time of each file at the
|
802
|
+
# given paths.
|
803
|
+
# * #flock: Locks or unlocks `self`.
|
804
|
+
#
|
805
|
+
# ### Other
|
806
|
+
#
|
807
|
+
# * ::truncate: Truncates the file at the given file path to the given size.
|
808
|
+
# * ::unlink (aliased as ::delete): Deletes the file for each given file path.
|
809
|
+
# * #truncate: Truncates `self` to the given size.
|
810
|
+
#
|
811
|
+
class File < IO
|
812
|
+
# <!--
|
813
|
+
# rdoc-file=io.c
|
814
|
+
# - File.new(path, mode = 'r', perm = 0666, **opts) -> file
|
815
|
+
# -->
|
816
|
+
# Opens the file at the given `path` according to the given `mode`; creates and
|
817
|
+
# returns a new File object for that file.
|
818
|
+
#
|
819
|
+
# The new File object is buffered mode (or non-sync mode), unless `filename` is
|
820
|
+
# a tty. See IO#flush, IO#fsync, IO#fdatasync, and IO#sync=.
|
821
|
+
#
|
822
|
+
# Argument `path` must be a valid file path:
|
823
|
+
#
|
824
|
+
# f = File.new('/etc/fstab')
|
825
|
+
# f.close
|
826
|
+
# f = File.new('t.txt')
|
827
|
+
# f.close
|
828
|
+
#
|
829
|
+
# Optional argument `mode` (defaults to 'r') must specify a valid mode; see
|
830
|
+
# [Access Modes](rdoc-ref:File@Access+Modes):
|
831
|
+
#
|
832
|
+
# f = File.new('t.tmp', 'w')
|
833
|
+
# f.close
|
834
|
+
# f = File.new('t.tmp', File::RDONLY)
|
835
|
+
# f.close
|
836
|
+
#
|
837
|
+
# Optional argument `perm` (defaults to 0666) must specify valid permissions see
|
838
|
+
# [File Permissions](rdoc-ref:File@File+Permissions):
|
839
|
+
#
|
840
|
+
# f = File.new('t.tmp', File::CREAT, 0644)
|
841
|
+
# f.close
|
842
|
+
# f = File.new('t.tmp', File::CREAT, 0444)
|
843
|
+
# f.close
|
844
|
+
#
|
845
|
+
# Optional keyword arguments `opts` specify:
|
846
|
+
#
|
847
|
+
# * [Open Options](rdoc-ref:IO@Open+Options).
|
848
|
+
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
849
|
+
#
|
850
|
+
def initialize: (string | _ToPath | int file_name, ?string | int mode, ?int perm) -> void
|
851
|
+
|
852
|
+
# <!--
|
853
|
+
# rdoc-file=file.c
|
854
|
+
# - File.absolute_path(file_name [, dir_string] ) -> abs_file_name
|
855
|
+
# -->
|
856
|
+
# Converts a pathname to an absolute pathname. Relative paths are referenced
|
857
|
+
# from the current working directory of the process unless *dir_string* is
|
858
|
+
# given, in which case it will be used as the starting point. If the given
|
859
|
+
# pathname starts with a ```~`'' it is NOT expanded, it is treated as a normal
|
860
|
+
# directory name.
|
861
|
+
#
|
862
|
+
# File.absolute_path("~oracle/bin") #=> "<relative_path>/~oracle/bin"
|
863
|
+
#
|
864
|
+
def self.absolute_path: (string | _ToPath file_name, ?string | _ToPath dir_string) -> String
|
865
|
+
|
866
|
+
# <!--
|
867
|
+
# rdoc-file=file.c
|
868
|
+
# - File.absolute_path?(file_name) -> true or false
|
869
|
+
# -->
|
870
|
+
# Returns `true` if `file_name` is an absolute path, and `false` otherwise.
|
871
|
+
#
|
872
|
+
# File.absolute_path?("c:/foo") #=> false (on Linux), true (on Windows)
|
873
|
+
#
|
874
|
+
def self.absolute_path?: (string | _ToPath file_name) -> bool
|
875
|
+
|
876
|
+
# <!--
|
877
|
+
# rdoc-file=file.c
|
878
|
+
# - File.atime(file_name) -> time
|
879
|
+
# -->
|
880
|
+
# Returns the last access time for the named file as a Time object.
|
881
|
+
#
|
882
|
+
# *file_name* can be an IO object.
|
883
|
+
#
|
884
|
+
# File.atime("testfile") #=> Wed Apr 09 08:51:48 CDT 2003
|
885
|
+
#
|
886
|
+
def self.atime: (string | _ToPath | IO file_name) -> Time
|
887
|
+
|
888
|
+
# <!--
|
889
|
+
# rdoc-file=file.c
|
890
|
+
# - File.basename(file_name [, suffix] ) -> base_name
|
891
|
+
# -->
|
892
|
+
# Returns the last component of the filename given in *file_name* (after first
|
893
|
+
# stripping trailing separators), which can be formed using both File::SEPARATOR
|
894
|
+
# and File::ALT_SEPARATOR as the separator when File::ALT_SEPARATOR is not
|
895
|
+
# `nil`. If *suffix* is given and present at the end of *file_name*, it is
|
896
|
+
# removed. If *suffix* is ".*", any extension will be removed.
|
897
|
+
#
|
898
|
+
# File.basename("/home/gumby/work/ruby.rb") #=> "ruby.rb"
|
899
|
+
# File.basename("/home/gumby/work/ruby.rb", ".rb") #=> "ruby"
|
900
|
+
# File.basename("/home/gumby/work/ruby.rb", ".*") #=> "ruby"
|
901
|
+
#
|
902
|
+
def self.basename: (string | _ToPath file_name, ?string suffix) -> String
|
903
|
+
|
904
|
+
# <!--
|
905
|
+
# rdoc-file=file.c
|
906
|
+
# - File.birthtime(file_name) -> time
|
907
|
+
# -->
|
908
|
+
# Returns the birth time for the named file.
|
909
|
+
#
|
910
|
+
# *file_name* can be an IO object.
|
911
|
+
#
|
912
|
+
# File.birthtime("testfile") #=> Wed Apr 09 08:53:13 CDT 2003
|
913
|
+
#
|
914
|
+
# If the platform doesn't have birthtime, raises NotImplementedError.
|
915
|
+
#
|
916
|
+
def self.birthtime: (string | _ToPath | IO file_name) -> Time
|
917
|
+
|
918
|
+
# <!--
|
919
|
+
# rdoc-file=file.c
|
920
|
+
# - File.blockdev?(filepath) -> true or false
|
921
|
+
# -->
|
922
|
+
# Returns `true` if `filepath` points to a block device, `false` otherwise:
|
923
|
+
#
|
924
|
+
# File.blockdev?('/dev/sda1') # => true
|
925
|
+
# File.blockdev?(File.new('t.tmp')) # => false
|
926
|
+
#
|
927
|
+
def self.blockdev?: (string | _ToPath | IO file_name) -> bool
|
928
|
+
|
929
|
+
# <!--
|
930
|
+
# rdoc-file=file.c
|
931
|
+
# - File.chardev?(filepath) -> true or false
|
932
|
+
# -->
|
933
|
+
# Returns `true` if `filepath` points to a character device, `false` otherwise.
|
934
|
+
#
|
935
|
+
# File.chardev?($stdin) # => true
|
936
|
+
# File.chardev?('t.txt') # => false
|
937
|
+
#
|
938
|
+
def self.chardev?: (string | _ToPath | IO file_name) -> bool
|
939
|
+
|
940
|
+
# <!--
|
941
|
+
# rdoc-file=file.c
|
942
|
+
# - File.chmod(mode_int, file_name, ... ) -> integer
|
943
|
+
# -->
|
944
|
+
# Changes permission bits on the named file(s) to the bit pattern represented by
|
945
|
+
# *mode_int*. Actual effects are operating system dependent (see the beginning
|
946
|
+
# of this section). On Unix systems, see `chmod(2)` for details. Returns the
|
947
|
+
# number of files processed.
|
948
|
+
#
|
949
|
+
# File.chmod(0644, "testfile", "out") #=> 2
|
950
|
+
#
|
951
|
+
def self.chmod: (int mode, *string | _ToPath file_name) -> Integer
|
952
|
+
|
953
|
+
# <!--
|
954
|
+
# rdoc-file=file.c
|
955
|
+
# - File.chown(owner_int, group_int, file_name, ...) -> integer
|
956
|
+
# -->
|
957
|
+
# Changes the owner and group of the named file(s) to the given numeric owner
|
958
|
+
# and group id's. Only a process with superuser privileges may change the owner
|
959
|
+
# of a file. The current owner of a file may change the file's group to any
|
960
|
+
# group to which the owner belongs. A `nil` or -1 owner or group id is ignored.
|
961
|
+
# Returns the number of files processed.
|
962
|
+
#
|
963
|
+
# File.chown(nil, 100, "testfile")
|
964
|
+
#
|
965
|
+
def self.chown: (int? owner, int? group, *string | _ToPath file_name) -> Integer
|
966
|
+
|
967
|
+
# <!--
|
968
|
+
# rdoc-file=file.c
|
969
|
+
# - File.ctime(file_name) -> time
|
970
|
+
# -->
|
971
|
+
# Returns the change time for the named file (the time at which directory
|
972
|
+
# information about the file was changed, not the file itself).
|
973
|
+
#
|
974
|
+
# *file_name* can be an IO object.
|
975
|
+
#
|
976
|
+
# Note that on Windows (NTFS), returns creation time (birth time).
|
977
|
+
#
|
978
|
+
# File.ctime("testfile") #=> Wed Apr 09 08:53:13 CDT 2003
|
979
|
+
#
|
980
|
+
def self.ctime: (string | _ToPath | IO file_name) -> Time
|
981
|
+
|
982
|
+
# <!--
|
983
|
+
# rdoc-file=file.c
|
984
|
+
# - File.delete(file_name, ...) -> integer
|
985
|
+
# - File.unlink(file_name, ...) -> integer
|
986
|
+
# -->
|
987
|
+
# Deletes the named files, returning the number of names passed as arguments.
|
988
|
+
# Raises an exception on any error. Since the underlying implementation relies
|
989
|
+
# on the `unlink(2)` system call, the type of exception raised depends on its
|
990
|
+
# error type (see https://linux.die.net/man/2/unlink) and has the form of e.g.
|
991
|
+
# Errno::ENOENT.
|
992
|
+
#
|
993
|
+
# See also Dir::rmdir.
|
994
|
+
#
|
995
|
+
alias self.delete self.unlink
|
996
|
+
|
997
|
+
# <!--
|
998
|
+
# rdoc-file=file.c
|
999
|
+
# - File.directory?(path) -> true or false
|
1000
|
+
# -->
|
1001
|
+
# With string `object` given, returns `true` if `path` is a string path leading
|
1002
|
+
# to a directory, or to a symbolic link to a directory; `false` otherwise:
|
1003
|
+
#
|
1004
|
+
# File.directory?('.') # => true
|
1005
|
+
# File.directory?('foo') # => false
|
1006
|
+
# File.symlink('.', 'dirlink') # => 0
|
1007
|
+
# File.directory?('dirlink') # => true
|
1008
|
+
# File.symlink('t,txt', 'filelink') # => 0
|
1009
|
+
# File.directory?('filelink') # => false
|
1010
|
+
#
|
1011
|
+
# Argument `path` can be an IO object.
|
1012
|
+
#
|
1013
|
+
def self.directory?: (string | _ToPath | IO path) -> bool
|
1014
|
+
|
1015
|
+
# <!--
|
1016
|
+
# rdoc-file=file.c
|
1017
|
+
# - File.dirname(file_name, level = 1) -> dir_name
|
1018
|
+
# -->
|
1019
|
+
# Returns all components of the filename given in *file_name* except the last
|
1020
|
+
# one (after first stripping trailing separators). The filename can be formed
|
1021
|
+
# using both File::SEPARATOR and File::ALT_SEPARATOR as the separator when
|
1022
|
+
# File::ALT_SEPARATOR is not `nil`.
|
1023
|
+
#
|
1024
|
+
# File.dirname("/home/gumby/work/ruby.rb") #=> "/home/gumby/work"
|
1025
|
+
#
|
1026
|
+
# If `level` is given, removes the last `level` components, not only one.
|
1027
|
+
#
|
1028
|
+
# File.dirname("/home/gumby/work/ruby.rb", 2) #=> "/home/gumby"
|
1029
|
+
# File.dirname("/home/gumby/work/ruby.rb", 4) #=> "/"
|
1030
|
+
#
|
1031
|
+
def self.dirname: (string | _ToPath file_name, ?Integer level) -> String
|
1032
|
+
|
1033
|
+
# <!--
|
1034
|
+
# rdoc-file=file.c
|
1035
|
+
# - File.zero?(file_name) -> true or false
|
1036
|
+
# -->
|
1037
|
+
# Returns `true` if the named file exists and has a zero size.
|
1038
|
+
#
|
1039
|
+
# *file_name* can be an IO object.
|
1040
|
+
#
|
1041
|
+
alias self.empty? self.zero?
|
1042
|
+
|
1043
|
+
# <!--
|
1044
|
+
# rdoc-file=file.c
|
1045
|
+
# - File.executable?(file_name) -> true or false
|
1046
|
+
# -->
|
1047
|
+
# Returns `true` if the named file is executable by the effective user and group
|
1048
|
+
# id of this process. See eaccess(3).
|
1049
|
+
#
|
1050
|
+
# Windows does not support execute permissions separately from read permissions.
|
1051
|
+
# On Windows, a file is only considered executable if it ends in .bat, .cmd,
|
1052
|
+
# .com, or .exe.
|
1053
|
+
#
|
1054
|
+
# Note that some OS-level security features may cause this to return true even
|
1055
|
+
# though the file is not executable by the effective user/group.
|
1056
|
+
#
|
1057
|
+
def self.executable?: (string | _ToPath file_name) -> bool
|
1058
|
+
|
1059
|
+
# <!--
|
1060
|
+
# rdoc-file=file.c
|
1061
|
+
# - File.executable_real?(file_name) -> true or false
|
1062
|
+
# -->
|
1063
|
+
# Returns `true` if the named file is executable by the real user and group id
|
1064
|
+
# of this process. See access(3).
|
1065
|
+
#
|
1066
|
+
# Windows does not support execute permissions separately from read permissions.
|
1067
|
+
# On Windows, a file is only considered executable if it ends in .bat, .cmd,
|
1068
|
+
# .com, or .exe.
|
1069
|
+
#
|
1070
|
+
# Note that some OS-level security features may cause this to return true even
|
1071
|
+
# though the file is not executable by the real user/group.
|
1072
|
+
#
|
1073
|
+
def self.executable_real?: (string | _ToPath file_name) -> bool
|
1074
|
+
|
1075
|
+
# <!--
|
1076
|
+
# rdoc-file=file.c
|
1077
|
+
# - File.exist?(file_name) -> true or false
|
1078
|
+
# -->
|
1079
|
+
# Return `true` if the named file exists.
|
1080
|
+
#
|
1081
|
+
# *file_name* can be an IO object.
|
1082
|
+
#
|
1083
|
+
# "file exists" means that stat() or fstat() system call is successful.
|
1084
|
+
#
|
1085
|
+
def self.exist?: (string | _ToPath | IO file_name) -> bool
|
1086
|
+
|
1087
|
+
# <!--
|
1088
|
+
# rdoc-file=file.c
|
1089
|
+
# - File.expand_path(file_name [, dir_string] ) -> abs_file_name
|
1090
|
+
# -->
|
1091
|
+
# Converts a pathname to an absolute pathname. Relative paths are referenced
|
1092
|
+
# from the current working directory of the process unless `dir_string` is
|
1093
|
+
# given, in which case it will be used as the starting point. The given pathname
|
1094
|
+
# may start with a ```~`'', which expands to the process owner's home directory
|
1095
|
+
# (the environment variable `HOME` must be set correctly). ```~`*user*'' expands
|
1096
|
+
# to the named user's home directory.
|
1097
|
+
#
|
1098
|
+
# File.expand_path("~oracle/bin") #=> "/home/oracle/bin"
|
1099
|
+
#
|
1100
|
+
# A simple example of using `dir_string` is as follows.
|
1101
|
+
# File.expand_path("ruby", "/usr/bin") #=> "/usr/bin/ruby"
|
1102
|
+
#
|
1103
|
+
# A more complex example which also resolves parent directory is as follows.
|
1104
|
+
# Suppose we are in bin/mygem and want the absolute path of lib/mygem.rb.
|
1105
|
+
#
|
1106
|
+
# File.expand_path("../../lib/mygem.rb", __FILE__)
|
1107
|
+
# #=> ".../path/to/project/lib/mygem.rb"
|
1108
|
+
#
|
1109
|
+
# So first it resolves the parent of __FILE__, that is bin/, then go to the
|
1110
|
+
# parent, the root of the project and appends `lib/mygem.rb`.
|
1111
|
+
#
|
1112
|
+
def self.expand_path: (string | _ToPath file_name, ?string | _ToPath dir_string) -> String
|
1113
|
+
|
1114
|
+
# <!--
|
1115
|
+
# rdoc-file=file.c
|
1116
|
+
# - File.extname(path) -> string
|
1117
|
+
# -->
|
1118
|
+
# Returns the extension (the portion of file name in `path` starting from the
|
1119
|
+
# last period).
|
1120
|
+
#
|
1121
|
+
# If `path` is a dotfile, or starts with a period, then the starting dot is not
|
1122
|
+
# dealt with the start of the extension.
|
1123
|
+
#
|
1124
|
+
# An empty string will also be returned when the period is the last character in
|
1125
|
+
# `path`.
|
1126
|
+
#
|
1127
|
+
# On Windows, trailing dots are truncated.
|
1128
|
+
#
|
1129
|
+
# File.extname("test.rb") #=> ".rb"
|
1130
|
+
# File.extname("a/b/d/test.rb") #=> ".rb"
|
1131
|
+
# File.extname(".a/b/d/test.rb") #=> ".rb"
|
1132
|
+
# File.extname("foo.") #=> "" on Windows
|
1133
|
+
# File.extname("foo.") #=> "." on non-Windows
|
1134
|
+
# File.extname("test") #=> ""
|
1135
|
+
# File.extname(".profile") #=> ""
|
1136
|
+
# File.extname(".profile.sh") #=> ".sh"
|
1137
|
+
#
|
1138
|
+
def self.extname: (string | _ToPath path) -> String
|
1139
|
+
|
1140
|
+
# <!--
|
1141
|
+
# rdoc-file=file.c
|
1142
|
+
# - File.file?(file) -> true or false
|
1143
|
+
# -->
|
1144
|
+
# Returns `true` if the named `file` exists and is a regular file.
|
1145
|
+
#
|
1146
|
+
# `file` can be an IO object.
|
1147
|
+
#
|
1148
|
+
# If the `file` argument is a symbolic link, it will resolve the symbolic link
|
1149
|
+
# and use the file referenced by the link.
|
1150
|
+
#
|
1151
|
+
def self.file?: (string | _ToPath | IO file) -> bool
|
1152
|
+
|
1153
|
+
# <!--
|
1154
|
+
# rdoc-file=dir.rb
|
1155
|
+
# - File.fnmatch( pattern, path, [flags] ) -> (true or false)
|
1156
|
+
# - File.fnmatch?( pattern, path, [flags] ) -> (true or false)
|
1157
|
+
# -->
|
1158
|
+
# Returns true if `path` matches against `pattern`. The pattern is not a
|
1159
|
+
# regular expression; instead it follows rules similar to shell filename
|
1160
|
+
# globbing. It may contain the following metacharacters:
|
1161
|
+
#
|
1162
|
+
# `*`
|
1163
|
+
# : Matches any file. Can be restricted by other values in the glob.
|
1164
|
+
# Equivalent to `/.*/x` in regexp.
|
1165
|
+
#
|
1166
|
+
# `*`
|
1167
|
+
# : Matches all regular files
|
1168
|
+
#
|
1169
|
+
# `c*`
|
1170
|
+
# : Matches all files beginning with `c`
|
1171
|
+
#
|
1172
|
+
# `*c`
|
1173
|
+
# : Matches all files ending with `c`
|
1174
|
+
#
|
1175
|
+
# `*c*`
|
1176
|
+
# : Matches all files that have `c` in them (including at the beginning or
|
1177
|
+
# end).
|
1178
|
+
#
|
1179
|
+
#
|
1180
|
+
# To match hidden files (that start with a `.`) set the File::FNM_DOTMATCH
|
1181
|
+
# flag.
|
1182
|
+
#
|
1183
|
+
#
|
1184
|
+
# `**`
|
1185
|
+
# : Matches directories recursively or files expansively.
|
1186
|
+
#
|
1187
|
+
#
|
1188
|
+
# `?`
|
1189
|
+
# : Matches any one character. Equivalent to `/.{1}/` in regexp.
|
1190
|
+
#
|
1191
|
+
#
|
1192
|
+
# `[set]`
|
1193
|
+
# : Matches any one character in `set`. Behaves exactly like character sets
|
1194
|
+
# in Regexp, including set negation (`[^a-z]`).
|
1195
|
+
#
|
1196
|
+
#
|
1197
|
+
# `\`
|
1198
|
+
# : Escapes the next metacharacter.
|
1199
|
+
#
|
1200
|
+
#
|
1201
|
+
# `{a,b}`
|
1202
|
+
# : Matches pattern a and pattern b if File::FNM_EXTGLOB flag is enabled.
|
1203
|
+
# Behaves like a Regexp union (`(?:a|b)`).
|
1204
|
+
#
|
1205
|
+
#
|
1206
|
+
# `flags` is a bitwise OR of the `FNM_XXX` constants. The same glob pattern and
|
1207
|
+
# flags are used by Dir::glob.
|
1208
|
+
#
|
1209
|
+
# Examples:
|
1210
|
+
#
|
1211
|
+
# File.fnmatch('cat', 'cat') #=> true # match entire string
|
1212
|
+
# File.fnmatch('cat', 'category') #=> false # only match partial string
|
1213
|
+
#
|
1214
|
+
# File.fnmatch('c{at,ub}s', 'cats') #=> false # { } isn't supported by default
|
1215
|
+
# File.fnmatch('c{at,ub}s', 'cats', File::FNM_EXTGLOB) #=> true # { } is supported on FNM_EXTGLOB
|
1216
|
+
#
|
1217
|
+
# File.fnmatch('c?t', 'cat') #=> true # '?' match only 1 character
|
1218
|
+
# File.fnmatch('c??t', 'cat') #=> false # ditto
|
1219
|
+
# File.fnmatch('c*', 'cats') #=> true # '*' match 0 or more characters
|
1220
|
+
# File.fnmatch('c*t', 'c/a/b/t') #=> true # ditto
|
1221
|
+
# File.fnmatch('ca[a-z]', 'cat') #=> true # inclusive bracket expression
|
1222
|
+
# File.fnmatch('ca[^t]', 'cat') #=> false # exclusive bracket expression ('^' or '!')
|
1223
|
+
#
|
1224
|
+
# File.fnmatch('cat', 'CAT') #=> false # case sensitive
|
1225
|
+
# File.fnmatch('cat', 'CAT', File::FNM_CASEFOLD) #=> true # case insensitive
|
1226
|
+
# File.fnmatch('cat', 'CAT', File::FNM_SYSCASE) #=> true or false # depends on the system default
|
1227
|
+
#
|
1228
|
+
# File.fnmatch('?', '/', File::FNM_PATHNAME) #=> false # wildcard doesn't match '/' on FNM_PATHNAME
|
1229
|
+
# File.fnmatch('*', '/', File::FNM_PATHNAME) #=> false # ditto
|
1230
|
+
# File.fnmatch('[/]', '/', File::FNM_PATHNAME) #=> false # ditto
|
1231
|
+
#
|
1232
|
+
# File.fnmatch('\?', '?') #=> true # escaped wildcard becomes ordinary
|
1233
|
+
# File.fnmatch('\a', 'a') #=> true # escaped ordinary remains ordinary
|
1234
|
+
# File.fnmatch('\a', '\a', File::FNM_NOESCAPE) #=> true # FNM_NOESCAPE makes '\' ordinary
|
1235
|
+
# File.fnmatch('[\?]', '?') #=> true # can escape inside bracket expression
|
1236
|
+
#
|
1237
|
+
# File.fnmatch('*', '.profile') #=> false # wildcard doesn't match leading
|
1238
|
+
# File.fnmatch('*', '.profile', File::FNM_DOTMATCH) #=> true # period by default.
|
1239
|
+
# File.fnmatch('.*', '.profile') #=> true
|
1240
|
+
#
|
1241
|
+
# File.fnmatch('**/*.rb', 'main.rb') #=> false
|
1242
|
+
# File.fnmatch('**/*.rb', './main.rb') #=> false
|
1243
|
+
# File.fnmatch('**/*.rb', 'lib/song.rb') #=> true
|
1244
|
+
# File.fnmatch('**.rb', 'main.rb') #=> true
|
1245
|
+
# File.fnmatch('**.rb', './main.rb') #=> false
|
1246
|
+
# File.fnmatch('**.rb', 'lib/song.rb') #=> true
|
1247
|
+
# File.fnmatch('*', 'dave/.profile') #=> true
|
1248
|
+
#
|
1249
|
+
# File.fnmatch('**/foo', 'a/b/c/foo', File::FNM_PATHNAME) #=> true
|
1250
|
+
# File.fnmatch('**/foo', '/a/b/c/foo', File::FNM_PATHNAME) #=> true
|
1251
|
+
# File.fnmatch('**/foo', 'c:/a/b/c/foo', File::FNM_PATHNAME) #=> true
|
1252
|
+
# File.fnmatch('**/foo', 'a/.b/c/foo', File::FNM_PATHNAME) #=> false
|
1253
|
+
# File.fnmatch('**/foo', 'a/.b/c/foo', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true
|
1254
|
+
#
|
1255
|
+
def self.fnmatch: (string pattern, string | _ToPath path, ?int flags) -> bool
|
1256
|
+
|
1257
|
+
# <!--
|
1258
|
+
# rdoc-file=dir.rb
|
1259
|
+
# - fnmatch?(pattern, path, flags = 0)
|
1260
|
+
# -->
|
1261
|
+
#
|
1262
|
+
alias self.fnmatch? self.fnmatch
|
1263
|
+
|
1264
|
+
# <!--
|
1265
|
+
# rdoc-file=file.c
|
1266
|
+
# - File.ftype(file_name) -> string
|
1267
|
+
# -->
|
1268
|
+
# Identifies the type of the named file; the return string is one of ```file`'',
|
1269
|
+
# ```directory`'', ```characterSpecial`'', ```blockSpecial`'', ```fifo`'',
|
1270
|
+
# ```link`'', ```socket`'', or ```unknown`''.
|
1271
|
+
#
|
1272
|
+
# File.ftype("testfile") #=> "file"
|
1273
|
+
# File.ftype("/dev/tty") #=> "characterSpecial"
|
1274
|
+
# File.ftype("/tmp/.X11-unix/X0") #=> "socket"
|
1275
|
+
#
|
1276
|
+
def self.ftype: (string | _ToPath file_name) -> String
|
1277
|
+
|
1278
|
+
# <!--
|
1279
|
+
# rdoc-file=file.c
|
1280
|
+
# - File.grpowned?(file_name) -> true or false
|
1281
|
+
# -->
|
1282
|
+
# Returns `true` if the named file exists and the effective group id of the
|
1283
|
+
# calling process is the owner of the file. Returns `false` on Windows.
|
1284
|
+
#
|
1285
|
+
# *file_name* can be an IO object.
|
1286
|
+
#
|
1287
|
+
def self.grpowned?: (string | _ToPath | IO file_name) -> bool
|
1288
|
+
|
1289
|
+
# <!--
|
1290
|
+
# rdoc-file=file.c
|
1291
|
+
# - File.identical?(file_1, file_2) -> true or false
|
1292
|
+
# -->
|
1293
|
+
# Returns `true` if the named files are identical.
|
1294
|
+
#
|
1295
|
+
# *file_1* and *file_2* can be an IO object.
|
1296
|
+
#
|
1297
|
+
# open("a", "w") {}
|
1298
|
+
# p File.identical?("a", "a") #=> true
|
1299
|
+
# p File.identical?("a", "./a") #=> true
|
1300
|
+
# File.link("a", "b")
|
1301
|
+
# p File.identical?("a", "b") #=> true
|
1302
|
+
# File.symlink("a", "c")
|
1303
|
+
# p File.identical?("a", "c") #=> true
|
1304
|
+
# open("d", "w") {}
|
1305
|
+
# p File.identical?("a", "d") #=> false
|
1306
|
+
#
|
1307
|
+
def self.identical?: (string | _ToPath | IO file_1, string | _ToPath | IO file_2) -> bool
|
1308
|
+
|
1309
|
+
# <!--
|
1310
|
+
# rdoc-file=file.c
|
1311
|
+
# - File.join(string, ...) -> string
|
1312
|
+
# -->
|
1313
|
+
# Returns a new string formed by joining the strings using `"/"`.
|
1314
|
+
#
|
1315
|
+
# File.join("usr", "mail", "gumby") #=> "usr/mail/gumby"
|
1316
|
+
#
|
1317
|
+
def self.join: (*path) -> String
|
1318
|
+
|
1319
|
+
# <!--
|
1320
|
+
# rdoc-file=file.c
|
1321
|
+
# - File.lchmod(mode_int, file_name, ...) -> integer
|
1322
|
+
# -->
|
1323
|
+
# Equivalent to File::chmod, but does not follow symbolic links (so it will
|
1324
|
+
# change the permissions associated with the link, not the file referenced by
|
1325
|
+
# the link). Often not available.
|
1326
|
+
#
|
1327
|
+
def self.lchmod: (int mode, *string | _ToPath file_name) -> Integer
|
1328
|
+
|
1329
|
+
# <!--
|
1330
|
+
# rdoc-file=file.c
|
1331
|
+
# - File.lchown(owner_int, group_int, file_name,..) -> integer
|
1332
|
+
# -->
|
1333
|
+
# Equivalent to File::chown, but does not follow symbolic links (so it will
|
1334
|
+
# change the owner associated with the link, not the file referenced by the
|
1335
|
+
# link). Often not available. Returns number of files in the argument list.
|
1336
|
+
#
|
1337
|
+
def self.lchown: (int? owner, int? group, *string | _ToPath file_name) -> Integer
|
1338
|
+
|
1339
|
+
# <!--
|
1340
|
+
# rdoc-file=file.c
|
1341
|
+
# - File.link(old_name, new_name) -> 0
|
1342
|
+
# -->
|
1343
|
+
# Creates a new name for an existing file using a hard link. Will not overwrite
|
1344
|
+
# *new_name* if it already exists (raising a subclass of SystemCallError). Not
|
1345
|
+
# available on all platforms.
|
1346
|
+
#
|
1347
|
+
# File.link("testfile", ".testfile") #=> 0
|
1348
|
+
# IO.readlines(".testfile")[0] #=> "This is line one\n"
|
1349
|
+
#
|
1350
|
+
def self.link: (string | _ToPath old_name, string | _ToPath new_name) -> 0
|
1351
|
+
|
1352
|
+
# <!--
|
1353
|
+
# rdoc-file=file.c
|
1354
|
+
# - File.lstat(filepath) -> stat
|
1355
|
+
# -->
|
1356
|
+
# Like File::stat, but does not follow the last symbolic link; instead, returns
|
1357
|
+
# a File::Stat object for the link itself.
|
1358
|
+
#
|
1359
|
+
# File.symlink('t.txt', 'symlink')
|
1360
|
+
# File.stat('symlink').size # => 47
|
1361
|
+
# File.lstat('symlink').size # => 5
|
1362
|
+
#
|
1363
|
+
def self.lstat: (string | _ToPath file_name) -> File::Stat
|
1364
|
+
|
1365
|
+
# <!--
|
1366
|
+
# rdoc-file=file.c
|
1367
|
+
# - File.lutime(atime, mtime, file_name, ...) -> integer
|
1368
|
+
# -->
|
1369
|
+
# Sets the access and modification times of each named file to the first two
|
1370
|
+
# arguments. If a file is a symlink, this method acts upon the link itself as
|
1371
|
+
# opposed to its referent; for the inverse behavior, see File.utime. Returns the
|
1372
|
+
# number of file names in the argument list.
|
1373
|
+
#
|
1374
|
+
def self.lutime: (Time | Numeric atime, Time | Numeric mtime, *string | _ToPath file_name) -> Integer
|
1375
|
+
|
1376
|
+
# <!--
|
1377
|
+
# rdoc-file=file.c
|
1378
|
+
# - File.mkfifo(file_name, mode=0666) => 0
|
1379
|
+
# -->
|
1380
|
+
# Creates a FIFO special file with name *file_name*. *mode* specifies the
|
1381
|
+
# FIFO's permissions. It is modified by the process's umask in the usual way:
|
1382
|
+
# the permissions of the created file are (mode & ~umask).
|
1383
|
+
#
|
1384
|
+
def self.mkfifo: (string | _ToPath file_name, ?int mode) -> 0
|
1385
|
+
|
1386
|
+
# <!--
|
1387
|
+
# rdoc-file=file.c
|
1388
|
+
# - File.mtime(file_name) -> time
|
1389
|
+
# -->
|
1390
|
+
# Returns the modification time for the named file as a Time object.
|
1391
|
+
#
|
1392
|
+
# *file_name* can be an IO object.
|
1393
|
+
#
|
1394
|
+
# File.mtime("testfile") #=> Tue Apr 08 12:58:04 CDT 2003
|
1395
|
+
#
|
1396
|
+
def self.mtime: (string | _ToPath | IO file_name) -> Time
|
1397
|
+
|
1398
|
+
# <!--
|
1399
|
+
# rdoc-file=io.c
|
1400
|
+
# - File.open(path, mode = 'r', perm = 0666, **opts) -> file
|
1401
|
+
# - File.open(path, mode = 'r', perm = 0666, **opts) {|f| ... } -> object
|
1402
|
+
# -->
|
1403
|
+
# Creates a new File object, via File.new with the given arguments.
|
1404
|
+
#
|
1405
|
+
# With no block given, returns the File object.
|
1406
|
+
#
|
1407
|
+
# With a block given, calls the block with the File object and returns the
|
1408
|
+
# block's value.
|
1409
|
+
#
|
1410
|
+
def self.open: (string | _ToPath | int file_name, ?string | int mode, ?int perm) -> instance
|
1411
|
+
| [T] (string | _ToPath | int file_name, ?string | int mode, ?int perm) { (File) -> T } -> T
|
1412
|
+
|
1413
|
+
# <!--
|
1414
|
+
# rdoc-file=file.c
|
1415
|
+
# - File.owned?(file_name) -> true or false
|
1416
|
+
# -->
|
1417
|
+
# Returns `true` if the named file exists and the effective used id of the
|
1418
|
+
# calling process is the owner of the file.
|
1419
|
+
#
|
1420
|
+
# *file_name* can be an IO object.
|
1421
|
+
#
|
1422
|
+
def self.owned?: (string | _ToPath | IO file_name) -> bool
|
1423
|
+
|
1424
|
+
# <!--
|
1425
|
+
# rdoc-file=file.c
|
1426
|
+
# - File.path(path) -> string
|
1427
|
+
# -->
|
1428
|
+
# Returns the string representation of the path
|
1429
|
+
#
|
1430
|
+
# File.path(File::NULL) #=> "/dev/null"
|
1431
|
+
# File.path(Pathname.new("/tmp")) #=> "/tmp"
|
1432
|
+
#
|
1433
|
+
def self.path: (string | _ToPath path) -> String
|
1434
|
+
|
1435
|
+
# <!--
|
1436
|
+
# rdoc-file=file.c
|
1437
|
+
# - File.pipe?(filepath) -> true or false
|
1438
|
+
# -->
|
1439
|
+
# Returns `true` if `filepath` points to a pipe, `false` otherwise:
|
1440
|
+
#
|
1441
|
+
# File.mkfifo('tmp/fifo')
|
1442
|
+
# File.pipe?('tmp/fifo') # => true
|
1443
|
+
# File.pipe?('t.txt') # => false
|
1444
|
+
#
|
1445
|
+
def self.pipe?: (string | _ToPath | IO file_name) -> bool
|
1446
|
+
|
1447
|
+
# <!--
|
1448
|
+
# rdoc-file=file.c
|
1449
|
+
# - File.readable?(file_name) -> true or false
|
1450
|
+
# -->
|
1451
|
+
# Returns `true` if the named file is readable by the effective user and group
|
1452
|
+
# id of this process. See eaccess(3).
|
1453
|
+
#
|
1454
|
+
# Note that some OS-level security features may cause this to return true even
|
1455
|
+
# though the file is not readable by the effective user/group.
|
1456
|
+
#
|
1457
|
+
def self.readable?: (string | _ToPath file_name) -> bool
|
1458
|
+
|
1459
|
+
# <!--
|
1460
|
+
# rdoc-file=file.c
|
1461
|
+
# - File.readable_real?(file_name) -> true or false
|
1462
|
+
# -->
|
1463
|
+
# Returns `true` if the named file is readable by the real user and group id of
|
1464
|
+
# this process. See access(3).
|
1465
|
+
#
|
1466
|
+
# Note that some OS-level security features may cause this to return true even
|
1467
|
+
# though the file is not readable by the real user/group.
|
1468
|
+
#
|
1469
|
+
def self.readable_real?: (string | _ToPath file_name) -> bool
|
1470
|
+
|
1471
|
+
# <!--
|
1472
|
+
# rdoc-file=file.c
|
1473
|
+
# - File.readlink(link_name) -> file_name
|
1474
|
+
# -->
|
1475
|
+
# Returns the name of the file referenced by the given link. Not available on
|
1476
|
+
# all platforms.
|
1477
|
+
#
|
1478
|
+
# File.symlink("testfile", "link2test") #=> 0
|
1479
|
+
# File.readlink("link2test") #=> "testfile"
|
1480
|
+
#
|
1481
|
+
def self.readlink: (string | _ToPath link_name) -> String
|
1482
|
+
|
1483
|
+
# <!--
|
1484
|
+
# rdoc-file=file.c
|
1485
|
+
# - File.realdirpath(pathname [, dir_string]) -> real_pathname
|
1486
|
+
# -->
|
1487
|
+
# Returns the real (absolute) pathname of *pathname* in the actual filesystem.
|
1488
|
+
# The real pathname doesn't contain symlinks or useless dots.
|
1489
|
+
#
|
1490
|
+
# If *dir_string* is given, it is used as a base directory for interpreting
|
1491
|
+
# relative pathname instead of the current directory.
|
1492
|
+
#
|
1493
|
+
# The last component of the real pathname can be nonexistent.
|
1494
|
+
#
|
1495
|
+
def self.realdirpath: (string | _ToPath pathname, ?string | _ToPath dir_string) -> String
|
1496
|
+
|
1497
|
+
# <!--
|
1498
|
+
# rdoc-file=file.c
|
1499
|
+
# - File.realpath(pathname [, dir_string]) -> real_pathname
|
1500
|
+
# -->
|
1501
|
+
# Returns the real (absolute) pathname of *pathname* in the actual filesystem
|
1502
|
+
# not containing symlinks or useless dots.
|
1503
|
+
#
|
1504
|
+
# If *dir_string* is given, it is used as a base directory for interpreting
|
1505
|
+
# relative pathname instead of the current directory.
|
1506
|
+
#
|
1507
|
+
# All components of the pathname must exist when this method is called.
|
1508
|
+
#
|
1509
|
+
def self.realpath: (string | _ToPath pathname, ?string | _ToPath dir_string) -> String
|
1510
|
+
|
1511
|
+
# <!--
|
1512
|
+
# rdoc-file=file.c
|
1513
|
+
# - File.rename(old_name, new_name) -> 0
|
1514
|
+
# -->
|
1515
|
+
# Renames the given file to the new name. Raises a SystemCallError if the file
|
1516
|
+
# cannot be renamed.
|
1517
|
+
#
|
1518
|
+
# File.rename("afile", "afile.bak") #=> 0
|
1519
|
+
#
|
1520
|
+
def self.rename: (string | _ToPath old_name, string | _ToPath new_name) -> 0
|
1521
|
+
|
1522
|
+
# <!--
|
1523
|
+
# rdoc-file=file.c
|
1524
|
+
# - File.setgid?(file_name) -> true or false
|
1525
|
+
# -->
|
1526
|
+
# Returns `true` if the named file has the setgid bit set.
|
1527
|
+
#
|
1528
|
+
# *file_name* can be an IO object.
|
1529
|
+
#
|
1530
|
+
def self.setgid?: (string | _ToPath | IO file_name) -> bool
|
1531
|
+
|
1532
|
+
# <!--
|
1533
|
+
# rdoc-file=file.c
|
1534
|
+
# - File.setuid?(file_name) -> true or false
|
1535
|
+
# -->
|
1536
|
+
# Returns `true` if the named file has the setuid bit set.
|
1537
|
+
#
|
1538
|
+
# *file_name* can be an IO object.
|
1539
|
+
#
|
1540
|
+
def self.setuid?: (string | _ToPath | IO file_name) -> bool
|
1541
|
+
|
1542
|
+
# <!--
|
1543
|
+
# rdoc-file=file.c
|
1544
|
+
# - File.size(file_name) -> integer
|
1545
|
+
# -->
|
1546
|
+
# Returns the size of `file_name`.
|
1547
|
+
#
|
1548
|
+
# *file_name* can be an IO object.
|
1549
|
+
#
|
1550
|
+
def self.size: (string | _ToPath | IO file_name) -> Integer
|
1551
|
+
|
1552
|
+
# <!--
|
1553
|
+
# rdoc-file=file.c
|
1554
|
+
# - File.size?(file_name) -> Integer or nil
|
1555
|
+
# -->
|
1556
|
+
# Returns `nil` if `file_name` doesn't exist or has zero size, the size of the
|
1557
|
+
# file otherwise.
|
1558
|
+
#
|
1559
|
+
# *file_name* can be an IO object.
|
1560
|
+
#
|
1561
|
+
def self.size?: (string | _ToPath | IO file_name) -> Integer?
|
1562
|
+
|
1563
|
+
# <!--
|
1564
|
+
# rdoc-file=file.c
|
1565
|
+
# - File.socket?(filepath) -> true or false
|
1566
|
+
# -->
|
1567
|
+
# Returns `true` if `filepath` points to a socket, `false` otherwise:
|
1568
|
+
#
|
1569
|
+
# require 'socket'
|
1570
|
+
# File.socket?(Socket.new(:INET, :STREAM)) # => true
|
1571
|
+
# File.socket?(File.new('t.txt')) # => false
|
1572
|
+
#
|
1573
|
+
def self.socket?: (string | _ToPath | IO file_name) -> bool
|
1574
|
+
|
1575
|
+
# <!--
|
1576
|
+
# rdoc-file=file.c
|
1577
|
+
# - File.split(file_name) -> array
|
1578
|
+
# -->
|
1579
|
+
# Splits the given string into a directory and a file component and returns them
|
1580
|
+
# in a two-element array. See also File::dirname and File::basename.
|
1581
|
+
#
|
1582
|
+
# File.split("/home/gumby/.profile") #=> ["/home/gumby", ".profile"]
|
1583
|
+
#
|
1584
|
+
def self.split: (string | _ToPath file_name) -> [ String, String ]
|
1585
|
+
|
1586
|
+
# <!--
|
1587
|
+
# rdoc-file=file.c
|
1588
|
+
# - File.stat(filepath) -> stat
|
1589
|
+
# -->
|
1590
|
+
# Returns a File::Stat object for the file at `filepath` (see File::Stat):
|
1591
|
+
#
|
1592
|
+
# File.stat('t.txt').class # => File::Stat
|
1593
|
+
#
|
1594
|
+
def self.stat: (string | _ToPath file_name) -> File::Stat
|
1595
|
+
|
1596
|
+
# <!--
|
1597
|
+
# rdoc-file=file.c
|
1598
|
+
# - File.sticky?(file_name) -> true or false
|
1599
|
+
# -->
|
1600
|
+
# Returns `true` if the named file has the sticky bit set.
|
1601
|
+
#
|
1602
|
+
# *file_name* can be an IO object.
|
1603
|
+
#
|
1604
|
+
def self.sticky?: (string | _ToPath | IO file_name) -> bool
|
1605
|
+
|
1606
|
+
# <!--
|
1607
|
+
# rdoc-file=file.c
|
1608
|
+
# - File.symlink(old_name, new_name) -> 0
|
1609
|
+
# -->
|
1610
|
+
# Creates a symbolic link called *new_name* for the existing file *old_name*.
|
1611
|
+
# Raises a NotImplemented exception on platforms that do not support symbolic
|
1612
|
+
# links.
|
1613
|
+
#
|
1614
|
+
# File.symlink("testfile", "link2test") #=> 0
|
1615
|
+
#
|
1616
|
+
def self.symlink: (string | _ToPath old_name, string | _ToPath new_name) -> 0
|
1617
|
+
|
1618
|
+
# <!--
|
1619
|
+
# rdoc-file=file.c
|
1620
|
+
# - File.symlink?(filepath) -> true or false
|
1621
|
+
# -->
|
1622
|
+
# Returns `true` if `filepath` points to a symbolic link, `false` otherwise:
|
1623
|
+
#
|
1624
|
+
# symlink = File.symlink('t.txt', 'symlink')
|
1625
|
+
# File.symlink?('symlink') # => true
|
1626
|
+
# File.symlink?('t.txt') # => false
|
1627
|
+
#
|
1628
|
+
def self.symlink?: (string | _ToPath file_name) -> bool
|
1629
|
+
|
1630
|
+
# <!--
|
1631
|
+
# rdoc-file=file.c
|
1632
|
+
# - File.truncate(file_name, integer) -> 0
|
1633
|
+
# -->
|
1634
|
+
# Truncates the file *file_name* to be at most *integer* bytes long. Not
|
1635
|
+
# available on all platforms.
|
1636
|
+
#
|
1637
|
+
# f = File.new("out", "w")
|
1638
|
+
# f.write("1234567890") #=> 10
|
1639
|
+
# f.close #=> nil
|
1640
|
+
# File.truncate("out", 5) #=> 0
|
1641
|
+
# File.size("out") #=> 5
|
1642
|
+
#
|
1643
|
+
def self.truncate: (string | _ToPath file_name, int length) -> 0
|
1644
|
+
|
1645
|
+
# <!--
|
1646
|
+
# rdoc-file=file.c
|
1647
|
+
# - File.umask() -> integer
|
1648
|
+
# - File.umask(integer) -> integer
|
1649
|
+
# -->
|
1650
|
+
# Returns the current umask value for this process. If the optional argument is
|
1651
|
+
# given, set the umask to that value and return the previous value. Umask values
|
1652
|
+
# are *subtracted* from the default permissions, so a umask of `0222` would make
|
1653
|
+
# a file read-only for everyone.
|
1654
|
+
#
|
1655
|
+
# File.umask(0006) #=> 18
|
1656
|
+
# File.umask #=> 6
|
1657
|
+
#
|
1658
|
+
def self.umask: (?int umask) -> Integer
|
1659
|
+
|
1660
|
+
# <!--
|
1661
|
+
# rdoc-file=file.c
|
1662
|
+
# - File.delete(file_name, ...) -> integer
|
1663
|
+
# - File.unlink(file_name, ...) -> integer
|
1664
|
+
# -->
|
1665
|
+
# Deletes the named files, returning the number of names passed as arguments.
|
1666
|
+
# Raises an exception on any error. Since the underlying implementation relies
|
1667
|
+
# on the `unlink(2)` system call, the type of exception raised depends on its
|
1668
|
+
# error type (see https://linux.die.net/man/2/unlink) and has the form of e.g.
|
1669
|
+
# Errno::ENOENT.
|
1670
|
+
#
|
1671
|
+
# See also Dir::rmdir.
|
1672
|
+
#
|
1673
|
+
def self.unlink: (*string | _ToPath file_name) -> Integer
|
1674
|
+
|
1675
|
+
# <!--
|
1676
|
+
# rdoc-file=file.c
|
1677
|
+
# - File.utime(atime, mtime, file_name, ...) -> integer
|
1678
|
+
# -->
|
1679
|
+
# Sets the access and modification times of each named file to the first two
|
1680
|
+
# arguments. If a file is a symlink, this method acts upon its referent rather
|
1681
|
+
# than the link itself; for the inverse behavior see File.lutime. Returns the
|
1682
|
+
# number of file names in the argument list.
|
1683
|
+
#
|
1684
|
+
def self.utime: (Time | Numeric atime, Time | Numeric mtime, *string | _ToPath file_name) -> Integer
|
1685
|
+
|
1686
|
+
# <!--
|
1687
|
+
# rdoc-file=file.c
|
1688
|
+
# - File.world_readable?(file_name) -> integer or nil
|
1689
|
+
# -->
|
1690
|
+
# If *file_name* is readable by others, returns an integer representing the file
|
1691
|
+
# permission bits of *file_name*. Returns `nil` otherwise. The meaning of the
|
1692
|
+
# bits is platform dependent; on Unix systems, see `stat(2)`.
|
1693
|
+
#
|
1694
|
+
# *file_name* can be an IO object.
|
1695
|
+
#
|
1696
|
+
# File.world_readable?("/etc/passwd") #=> 420
|
1697
|
+
# m = File.world_readable?("/etc/passwd")
|
1698
|
+
# sprintf("%o", m) #=> "644"
|
1699
|
+
#
|
1700
|
+
def self.world_readable?: (string | _ToPath | IO file_name) -> Integer?
|
1701
|
+
|
1702
|
+
# <!--
|
1703
|
+
# rdoc-file=file.c
|
1704
|
+
# - File.world_writable?(file_name) -> integer or nil
|
1705
|
+
# -->
|
1706
|
+
# If *file_name* is writable by others, returns an integer representing the file
|
1707
|
+
# permission bits of *file_name*. Returns `nil` otherwise. The meaning of the
|
1708
|
+
# bits is platform dependent; on Unix systems, see `stat(2)`.
|
1709
|
+
#
|
1710
|
+
# *file_name* can be an IO object.
|
1711
|
+
#
|
1712
|
+
# File.world_writable?("/tmp") #=> 511
|
1713
|
+
# m = File.world_writable?("/tmp")
|
1714
|
+
# sprintf("%o", m) #=> "777"
|
1715
|
+
#
|
1716
|
+
def self.world_writable?: (string | _ToPath | IO file_name) -> Integer?
|
1717
|
+
|
1718
|
+
# <!--
|
1719
|
+
# rdoc-file=file.c
|
1720
|
+
# - File.writable?(file_name) -> true or false
|
1721
|
+
# -->
|
1722
|
+
# Returns `true` if the named file is writable by the effective user and group
|
1723
|
+
# id of this process. See eaccess(3).
|
1724
|
+
#
|
1725
|
+
# Note that some OS-level security features may cause this to return true even
|
1726
|
+
# though the file is not writable by the effective user/group.
|
1727
|
+
#
|
1728
|
+
def self.writable?: (string | _ToPath file_name) -> bool
|
1729
|
+
|
1730
|
+
# <!--
|
1731
|
+
# rdoc-file=file.c
|
1732
|
+
# - File.writable_real?(file_name) -> true or false
|
1733
|
+
# -->
|
1734
|
+
# Returns `true` if the named file is writable by the real user and group id of
|
1735
|
+
# this process. See access(3).
|
1736
|
+
#
|
1737
|
+
# Note that some OS-level security features may cause this to return true even
|
1738
|
+
# though the file is not writable by the real user/group.
|
1739
|
+
#
|
1740
|
+
def self.writable_real?: (string | _ToPath file_name) -> bool
|
1741
|
+
|
1742
|
+
# <!--
|
1743
|
+
# rdoc-file=file.c
|
1744
|
+
# - File.zero?(file_name) -> true or false
|
1745
|
+
# -->
|
1746
|
+
# Returns `true` if the named file exists and has a zero size.
|
1747
|
+
#
|
1748
|
+
# *file_name* can be an IO object.
|
1749
|
+
#
|
1750
|
+
def self.zero?: (string | _ToPath | IO file_name) -> bool
|
1751
|
+
|
1752
|
+
# <!--
|
1753
|
+
# rdoc-file=file.c
|
1754
|
+
# - file.atime -> time
|
1755
|
+
# -->
|
1756
|
+
# Returns the last access time (a Time object) for *file*, or epoch if *file*
|
1757
|
+
# has not been accessed.
|
1758
|
+
#
|
1759
|
+
# File.new("testfile").atime #=> Wed Dec 31 18:00:00 CST 1969
|
1760
|
+
#
|
1761
|
+
def atime: () -> Time
|
1762
|
+
|
1763
|
+
# <!--
|
1764
|
+
# rdoc-file=file.c
|
1765
|
+
# - file.birthtime -> time
|
1766
|
+
# -->
|
1767
|
+
# Returns the birth time for *file*.
|
1768
|
+
#
|
1769
|
+
# File.new("testfile").birthtime #=> Wed Apr 09 08:53:14 CDT 2003
|
1770
|
+
#
|
1771
|
+
# If the platform doesn't have birthtime, raises NotImplementedError.
|
1772
|
+
#
|
1773
|
+
def birthtime: () -> Time
|
1774
|
+
|
1775
|
+
# <!--
|
1776
|
+
# rdoc-file=file.c
|
1777
|
+
# - file.chmod(mode_int) -> 0
|
1778
|
+
# -->
|
1779
|
+
# Changes permission bits on *file* to the bit pattern represented by
|
1780
|
+
# *mode_int*. Actual effects are platform dependent; on Unix systems, see
|
1781
|
+
# `chmod(2)` for details. Follows symbolic links. Also see File#lchmod.
|
1782
|
+
#
|
1783
|
+
# f = File.new("out", "w");
|
1784
|
+
# f.chmod(0644) #=> 0
|
1785
|
+
#
|
1786
|
+
def chmod: (int mode) -> (0 | nil)
|
1787
|
+
|
1788
|
+
# <!--
|
1789
|
+
# rdoc-file=file.c
|
1790
|
+
# - file.chown(owner_int, group_int ) -> 0
|
1791
|
+
# -->
|
1792
|
+
# Changes the owner and group of *file* to the given numeric owner and group
|
1793
|
+
# id's. Only a process with superuser privileges may change the owner of a file.
|
1794
|
+
# The current owner of a file may change the file's group to any group to which
|
1795
|
+
# the owner belongs. A `nil` or -1 owner or group id is ignored. Follows
|
1796
|
+
# symbolic links. See also File#lchown.
|
1797
|
+
#
|
1798
|
+
# File.new("testfile").chown(502, 1000)
|
1799
|
+
#
|
1800
|
+
def chown: (int? owner, int? group) -> (0 | nil)
|
1801
|
+
|
1802
|
+
# <!--
|
1803
|
+
# rdoc-file=file.c
|
1804
|
+
# - file.ctime -> time
|
1805
|
+
# -->
|
1806
|
+
# Returns the change time for *file* (that is, the time directory information
|
1807
|
+
# about the file was changed, not the file itself).
|
1808
|
+
#
|
1809
|
+
# Note that on Windows (NTFS), returns creation time (birth time).
|
1810
|
+
#
|
1811
|
+
# File.new("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
|
1812
|
+
#
|
1813
|
+
def ctime: () -> Time
|
1814
|
+
|
1815
|
+
# <!--
|
1816
|
+
# rdoc-file=file.c
|
1817
|
+
# - flock(locking_constant) -> 0 or false
|
1818
|
+
# -->
|
1819
|
+
# Locks or unlocks file `self` according to the given `locking_constant`,
|
1820
|
+
# a bitwise OR of the values in the table below.
|
1821
|
+
# Not available on all platforms.
|
1822
|
+
# Returns `false` if `File::LOCK_NB` is specified and the operation would have
|
1823
|
+
# blocked;
|
1824
|
+
# otherwise returns `0`.
|
1825
|
+
# Constant | Lock | Effect
|
1826
|
+
# ---------------|------------|--------------------------------------------------------------------------------------------------------------
|
1827
|
+
# +File::LOCK_EX+| Exclusive | Only one process may hold an exclusive lock for +self+ at a time.
|
1828
|
+
# +File::LOCK_NB+|Non-blocking|No blocking; may be combined with +File::LOCK_SH+ or +File::LOCK_EX+ using the bitwise OR operator <tt>|</tt>.
|
1829
|
+
# +File::LOCK_SH+| Shared | Multiple processes may each hold a shared lock for +self+ at the same time.
|
1830
|
+
# +File::LOCK_UN+| Unlock | Remove an existing lock held by this process.
|
1831
|
+
# Example:
|
1832
|
+
# # Update a counter using an exclusive lock.
|
1833
|
+
# # Don't use File::WRONLY because it truncates the file.
|
1834
|
+
# File.open('counter', File::RDWR | File::CREAT, 0644) do |f|
|
1835
|
+
# f.flock(File::LOCK_EX)
|
1836
|
+
# value = f.read.to_i + 1
|
1837
|
+
# f.rewind
|
1838
|
+
# f.write("#{value}\n")
|
1839
|
+
# f.flush
|
1840
|
+
# f.truncate(f.pos)
|
1841
|
+
# end
|
1842
|
+
#
|
1843
|
+
# # Read the counter using a shared lock.
|
1844
|
+
# File.open('counter', 'r') do |f|
|
1845
|
+
# f.flock(File::LOCK_SH)
|
1846
|
+
# f.read
|
1847
|
+
# end
|
1848
|
+
#
|
1849
|
+
def flock: (int locking_constant) -> (0 | false)
|
1850
|
+
|
1851
|
+
# <!--
|
1852
|
+
# rdoc-file=file.c
|
1853
|
+
# - lstat -> stat
|
1854
|
+
# -->
|
1855
|
+
# Like File#stat, but does not follow the last symbolic link; instead, returns a
|
1856
|
+
# File::Stat object for the link itself:
|
1857
|
+
#
|
1858
|
+
# File.symlink('t.txt', 'symlink')
|
1859
|
+
# f = File.new('symlink')
|
1860
|
+
# f.stat.size # => 47
|
1861
|
+
# f.lstat.size # => 11
|
1862
|
+
#
|
1863
|
+
def lstat: () -> (File::Stat | nil)
|
1864
|
+
|
1865
|
+
# <!--
|
1866
|
+
# rdoc-file=file.c
|
1867
|
+
# - file.mtime -> time
|
1868
|
+
# -->
|
1869
|
+
# Returns the modification time for *file*.
|
1870
|
+
#
|
1871
|
+
# File.new("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
|
1872
|
+
#
|
1873
|
+
def mtime: () -> Time
|
1874
|
+
|
1875
|
+
# <!--
|
1876
|
+
# rdoc-file=file.c
|
1877
|
+
# - file.path -> filename
|
1878
|
+
# - file.to_path -> filename
|
1879
|
+
# -->
|
1880
|
+
# Returns the pathname used to create *file* as a string. Does not normalize the
|
1881
|
+
# name.
|
1882
|
+
#
|
1883
|
+
# The pathname may not point to the file corresponding to *file*. For instance,
|
1884
|
+
# the pathname becomes void when the file has been moved or deleted.
|
1885
|
+
#
|
1886
|
+
# This method raises IOError for a *file* created using File::Constants::TMPFILE
|
1887
|
+
# because they don't have a pathname.
|
1888
|
+
#
|
1889
|
+
# File.new("testfile").path #=> "testfile"
|
1890
|
+
# File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx"
|
1891
|
+
#
|
1892
|
+
def path: () -> String
|
1893
|
+
|
1894
|
+
# <!--
|
1895
|
+
# rdoc-file=file.c
|
1896
|
+
# - file.size -> integer
|
1897
|
+
# -->
|
1898
|
+
# Returns the size of *file* in bytes.
|
1899
|
+
#
|
1900
|
+
# File.new("testfile").size #=> 66
|
1901
|
+
#
|
1902
|
+
def size: () -> Integer
|
1903
|
+
|
1904
|
+
# <!-- rdoc-file=file.c -->
|
1905
|
+
# Returns the pathname used to create *file* as a string. Does not normalize the
|
1906
|
+
# name.
|
1907
|
+
#
|
1908
|
+
# The pathname may not point to the file corresponding to *file*. For instance,
|
1909
|
+
# the pathname becomes void when the file has been moved or deleted.
|
1910
|
+
#
|
1911
|
+
# This method raises IOError for a *file* created using File::Constants::TMPFILE
|
1912
|
+
# because they don't have a pathname.
|
1913
|
+
#
|
1914
|
+
# File.new("testfile").path #=> "testfile"
|
1915
|
+
# File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx"
|
1916
|
+
#
|
1917
|
+
alias to_path path
|
1918
|
+
|
1919
|
+
# <!--
|
1920
|
+
# rdoc-file=file.c
|
1921
|
+
# - file.truncate(integer) -> 0
|
1922
|
+
# -->
|
1923
|
+
# Truncates *file* to at most *integer* bytes. The file must be opened for
|
1924
|
+
# writing. Not available on all platforms.
|
1925
|
+
#
|
1926
|
+
# f = File.new("out", "w")
|
1927
|
+
# f.syswrite("1234567890") #=> 10
|
1928
|
+
# f.truncate(5) #=> 0
|
1929
|
+
# f.close() #=> nil
|
1930
|
+
# File.size("out") #=> 5
|
1931
|
+
#
|
1932
|
+
def truncate: (int length) -> 0
|
1933
|
+
end
|
1934
|
+
|
1935
|
+
# <!-- rdoc-file=file.c -->
|
1936
|
+
# platform specific alternative separator
|
1937
|
+
#
|
1938
|
+
File::ALT_SEPARATOR: String?
|
1939
|
+
|
1940
|
+
# <!-- rdoc-file=file.c -->
|
1941
|
+
# path list separator
|
1942
|
+
#
|
1943
|
+
File::PATH_SEPARATOR: String
|
1944
|
+
|
1945
|
+
# <!-- rdoc-file=file.c -->
|
1946
|
+
# separates directory parts in path
|
1947
|
+
#
|
1948
|
+
File::SEPARATOR: String
|
1949
|
+
|
1950
|
+
# <!-- rdoc-file=file.c -->
|
1951
|
+
# separates directory parts in path
|
1952
|
+
#
|
1953
|
+
File::Separator: String
|
1954
|
+
|
1955
|
+
# <!-- rdoc-file=file.c -->
|
1956
|
+
# Module `File::Constants` defines file-related constants.
|
1957
|
+
#
|
1958
|
+
# There are two families of constants here:
|
1959
|
+
#
|
1960
|
+
# * Those having to do with [file
|
1961
|
+
# access](rdoc-ref:File::Constants@File+Access).
|
1962
|
+
# * Those having to do with [filename
|
1963
|
+
# globbing](rdoc-ref:File::Constants@Filename+Globbing+Constants+-28File-3A-
|
1964
|
+
# 3AFNM_-2A-29).
|
1965
|
+
#
|
1966
|
+
# File constants defined for the local process may be retrieved with method
|
1967
|
+
# File::Constants.constants:
|
1968
|
+
#
|
1969
|
+
# File::Constants.constants.take(5)
|
1970
|
+
# # => [:RDONLY, :WRONLY, :RDWR, :APPEND, :CREAT]
|
1971
|
+
#
|
1972
|
+
# ## File Access
|
1973
|
+
#
|
1974
|
+
# File-access constants may be used with optional argument `mode` in calls to
|
1975
|
+
# the following methods:
|
1976
|
+
#
|
1977
|
+
# * File.new.
|
1978
|
+
# * File.open.
|
1979
|
+
# * IO.for_fd.
|
1980
|
+
# * IO.new.
|
1981
|
+
# * IO.open.
|
1982
|
+
# * IO.popen.
|
1983
|
+
# * IO.reopen.
|
1984
|
+
# * IO.sysopen.
|
1985
|
+
# * StringIO.new.
|
1986
|
+
# * StringIO.open.
|
1987
|
+
# * StringIO#reopen.
|
1988
|
+
#
|
1989
|
+
# ### Read/Write Access
|
1990
|
+
#
|
1991
|
+
# Read-write access for a stream may be specified by a file-access constant.
|
1992
|
+
#
|
1993
|
+
# The constant may be specified as part of a bitwise OR of other such constants.
|
1994
|
+
#
|
1995
|
+
# Any combination of the constants in this section may be specified.
|
1996
|
+
#
|
1997
|
+
# #### File::RDONLY
|
1998
|
+
#
|
1999
|
+
# Flag File::RDONLY specifies the stream should be opened for reading only:
|
2000
|
+
#
|
2001
|
+
# filepath = '/tmp/t.tmp'
|
2002
|
+
# f = File.new(filepath, File::RDONLY)
|
2003
|
+
# f.write('Foo') # Raises IOError (not opened for writing).
|
2004
|
+
#
|
2005
|
+
# #### File::WRONLY
|
2006
|
+
#
|
2007
|
+
# Flag File::WRONLY specifies that the stream should be opened for writing only:
|
2008
|
+
#
|
2009
|
+
# f = File.new(filepath, File::WRONLY)
|
2010
|
+
# f.read # Raises IOError (not opened for reading).
|
2011
|
+
#
|
2012
|
+
# #### File::RDWR
|
2013
|
+
#
|
2014
|
+
# Flag File::RDWR specifies that the stream should be opened for both reading
|
2015
|
+
# and writing:
|
2016
|
+
#
|
2017
|
+
# f = File.new(filepath, File::RDWR)
|
2018
|
+
# f.write('Foo') # => 3
|
2019
|
+
# f.rewind # => 0
|
2020
|
+
# f.read # => "Foo"
|
2021
|
+
#
|
2022
|
+
# ### File Positioning
|
2023
|
+
#
|
2024
|
+
# #### File::APPEND
|
2025
|
+
#
|
2026
|
+
# Flag File::APPEND specifies that the stream should be opened in append mode.
|
2027
|
+
#
|
2028
|
+
# Before each write operation, the position is set to end-of-stream. The
|
2029
|
+
# modification of the position and the following write operation are performed
|
2030
|
+
# as a single atomic step.
|
2031
|
+
#
|
2032
|
+
# #### File::TRUNC
|
2033
|
+
#
|
2034
|
+
# Flag File::TRUNC specifies that the stream should be truncated at its
|
2035
|
+
# beginning. If the file exists and is successfully opened for writing, it is to
|
2036
|
+
# be truncated to position zero; its ctime and mtime are updated.
|
2037
|
+
#
|
2038
|
+
# There is no effect on a FIFO special file or a terminal device. The effect on
|
2039
|
+
# other file types is implementation-defined. The result of using File::TRUNC
|
2040
|
+
# with File::RDONLY is undefined.
|
2041
|
+
#
|
2042
|
+
# ### Creating and Preserving
|
2043
|
+
#
|
2044
|
+
# #### File::CREAT
|
2045
|
+
#
|
2046
|
+
# Flag File::CREAT specifies that the stream should be created if it does not
|
2047
|
+
# already exist.
|
2048
|
+
#
|
2049
|
+
# If the file exists:
|
2050
|
+
#
|
2051
|
+
# - Raise an exception if File::EXCL is also specified.
|
2052
|
+
# - Otherwise, do nothing.
|
2053
|
+
#
|
2054
|
+
# If the file does not exist, then it is created. Upon successful completion,
|
2055
|
+
# the atime, ctime, and mtime of the file are updated, and the ctime and mtime
|
2056
|
+
# of the parent directory are updated.
|
2057
|
+
#
|
2058
|
+
# #### File::EXCL
|
2059
|
+
#
|
2060
|
+
# Flag File::EXCL specifies that the stream should not already exist; If flags
|
2061
|
+
# File::CREAT and File::EXCL are both specified and the stream already exists,
|
2062
|
+
# an exception is raised.
|
2063
|
+
#
|
2064
|
+
# The check for the existence and creation of the file is performed as an atomic
|
2065
|
+
# operation.
|
2066
|
+
#
|
2067
|
+
# If both File::EXCL and File::CREAT are specified and the path names a symbolic
|
2068
|
+
# link, an exception is raised regardless of the contents of the symbolic link.
|
2069
|
+
#
|
2070
|
+
# If File::EXCL is specified and File::CREAT is not specified, the result is
|
2071
|
+
# undefined.
|
2072
|
+
#
|
2073
|
+
# ### POSIX File Constants
|
2074
|
+
#
|
2075
|
+
# Some file-access constants are defined only on POSIX-compliant systems; those
|
2076
|
+
# are:
|
2077
|
+
#
|
2078
|
+
# * File::SYNC.
|
2079
|
+
# * File::DSYNC.
|
2080
|
+
# * File::RSYNC.
|
2081
|
+
# * File::DIRECT.
|
2082
|
+
# * File::NOATIME.
|
2083
|
+
# * File::NOCTTY.
|
2084
|
+
# * File::NOFOLLOW.
|
2085
|
+
# * File::TMPFILE.
|
2086
|
+
#
|
2087
|
+
# #### File::SYNC, File::RSYNC, and File::DSYNC
|
2088
|
+
#
|
2089
|
+
# Flag File::SYNC, File::RSYNC, or File::DSYNC specifies synchronization of I/O
|
2090
|
+
# operations with the underlying file system.
|
2091
|
+
#
|
2092
|
+
# These flags are valid only for POSIX-compliant systems.
|
2093
|
+
#
|
2094
|
+
# * File::SYNC specifies that all write operations (both data and metadata)
|
2095
|
+
# are immediately to be flushed to the underlying storage device. This means
|
2096
|
+
# that the data is written to the storage device, and the file's metadata
|
2097
|
+
# (e.g., file size, timestamps, permissions) are also synchronized. This
|
2098
|
+
# guarantees that data is safely stored on the storage medium before
|
2099
|
+
# returning control to the calling program. This flag can have a significant
|
2100
|
+
# impact on performance since it requires synchronous writes, which can be
|
2101
|
+
# slower compared to asynchronous writes.
|
2102
|
+
#
|
2103
|
+
# * File::RSYNC specifies that any read operations on the file will not return
|
2104
|
+
# until all outstanding write operations (those that have been issued but
|
2105
|
+
# not completed) are also synchronized. This is useful when you want to read
|
2106
|
+
# the most up-to-date data, which may still be in the process of being
|
2107
|
+
# written.
|
2108
|
+
#
|
2109
|
+
# * File::DSYNC specifies that all *data* write operations are immediately to
|
2110
|
+
# be flushed to the underlying storage device; this differs from File::SYNC,
|
2111
|
+
# which requires that *metadata* also be synchronized.
|
2112
|
+
#
|
2113
|
+
# Note that the behavior of these flags may vary slightly depending on the
|
2114
|
+
# operating system and filesystem being used. Additionally, using these flags
|
2115
|
+
# can have an impact on performance due to the synchronous nature of the I/O
|
2116
|
+
# operations, so they should be used judiciously, especially in
|
2117
|
+
# performance-critical applications.
|
2118
|
+
#
|
2119
|
+
# #### File::NOCTTY
|
2120
|
+
#
|
2121
|
+
# Flag File::NOCTTY specifies that if the stream is a terminal device, that
|
2122
|
+
# device does not become the controlling terminal for the process.
|
2123
|
+
#
|
2124
|
+
# Defined only for POSIX-compliant systems.
|
2125
|
+
#
|
2126
|
+
# #### File::DIRECT
|
2127
|
+
#
|
2128
|
+
# Flag File::DIRECT requests that cache effects of the I/O to and from the
|
2129
|
+
# stream be minimized.
|
2130
|
+
#
|
2131
|
+
# Defined only for POSIX-compliant systems.
|
2132
|
+
#
|
2133
|
+
# #### File::NOATIME
|
2134
|
+
#
|
2135
|
+
# Flag File::NOATIME specifies that act of opening the stream should not modify
|
2136
|
+
# its access time (atime).
|
2137
|
+
#
|
2138
|
+
# Defined only for POSIX-compliant systems.
|
2139
|
+
#
|
2140
|
+
# #### File::NOFOLLOW
|
2141
|
+
#
|
2142
|
+
# Flag File::NOFOLLOW specifies that if path is a symbolic link, it should not
|
2143
|
+
# be followed.
|
2144
|
+
#
|
2145
|
+
# Defined only for POSIX-compliant systems.
|
2146
|
+
#
|
2147
|
+
# #### File::TMPFILE
|
2148
|
+
#
|
2149
|
+
# Flag File::TMPFILE specifies that the opened stream should be a new temporary
|
2150
|
+
# file.
|
2151
|
+
#
|
2152
|
+
# Defined only for POSIX-compliant systems.
|
2153
|
+
#
|
2154
|
+
# ### Other File-Access Constants
|
2155
|
+
#
|
2156
|
+
# #### File::NONBLOCK
|
2157
|
+
#
|
2158
|
+
# When possible, the file is opened in nonblocking mode. Neither the open
|
2159
|
+
# operation nor any subsequent I/O operations on the file will cause the calling
|
2160
|
+
# process to wait.
|
2161
|
+
#
|
2162
|
+
# #### File::BINARY
|
2163
|
+
#
|
2164
|
+
# Flag File::BINARY specifies that the stream is to be accessed in binary mode.
|
2165
|
+
#
|
2166
|
+
# #### File::SHARE_DELETE
|
2167
|
+
#
|
2168
|
+
# Flag File::SHARE_DELETE enables other processes to open the stream with delete
|
2169
|
+
# access.
|
2170
|
+
#
|
2171
|
+
# Windows only.
|
2172
|
+
#
|
2173
|
+
# If the stream is opened for (local) delete access without File::SHARE_DELETE,
|
2174
|
+
# and another process attempts to open it with delete access, the attempt fails
|
2175
|
+
# and the stream is not opened for that process.
|
2176
|
+
#
|
2177
|
+
# ## Locking
|
2178
|
+
#
|
2179
|
+
# Four file constants relate to stream locking; see File#flock:
|
2180
|
+
#
|
2181
|
+
# #### File::LOCK_EX
|
2182
|
+
#
|
2183
|
+
# Flag File::LOCK_EX specifies an exclusive lock; only one process a a time may
|
2184
|
+
# lock the stream.
|
2185
|
+
#
|
2186
|
+
# #### File::LOCK_NB
|
2187
|
+
#
|
2188
|
+
# Flag File::LOCK_NB specifies non-blocking locking for the stream; may be
|
2189
|
+
# combined with File::LOCK_EX or File::LOCK_SH.
|
2190
|
+
#
|
2191
|
+
# #### File::LOCK_SH
|
2192
|
+
#
|
2193
|
+
# Flag File::LOCK_SH specifies that multiple processes may lock the stream at
|
2194
|
+
# the same time.
|
2195
|
+
#
|
2196
|
+
# #### File::LOCK_UN
|
2197
|
+
#
|
2198
|
+
# Flag File::LOCK_UN specifies that the stream is not to be locked.
|
2199
|
+
#
|
2200
|
+
# ## Filename Globbing Constants (File::FNM_*)
|
2201
|
+
#
|
2202
|
+
# Filename-globbing constants may be used with optional argument `flags` in
|
2203
|
+
# calls to the following methods:
|
2204
|
+
#
|
2205
|
+
# * Dir.glob.
|
2206
|
+
# * File.fnmatch.
|
2207
|
+
# * Pathname#fnmatch.
|
2208
|
+
# * Pathname.glob.
|
2209
|
+
# * Pathname#glob.
|
2210
|
+
#
|
2211
|
+
# The constants are:
|
2212
|
+
#
|
2213
|
+
# #### File::FNM_CASEFOLD
|
2214
|
+
#
|
2215
|
+
# Flag File::FNM_CASEFOLD makes patterns case insensitive for File.fnmatch (but
|
2216
|
+
# not Dir.glob).
|
2217
|
+
#
|
2218
|
+
# #### File::FNM_DOTMATCH
|
2219
|
+
#
|
2220
|
+
# Flag File::FNM_DOTMATCH makes the `'*'` pattern match a filename starting with
|
2221
|
+
# `'.'`.
|
2222
|
+
#
|
2223
|
+
# #### File::FNM_EXTGLOB
|
2224
|
+
#
|
2225
|
+
# Flag File::FNM_EXTGLOB enables pattern `'{*a*,*b*}'`, which matches pattern
|
2226
|
+
# '*a*' and pattern '*b*'; behaves like a [regexp union](rdoc-ref:Regexp.union)
|
2227
|
+
# (e.g., `'(?:*a*|*b*)'`):
|
2228
|
+
#
|
2229
|
+
# pattern = '{LEGAL,BSDL}'
|
2230
|
+
# Dir.glob(pattern) # => ["LEGAL", "BSDL"]
|
2231
|
+
# Pathname.glob(pattern) # => [#<Pathname:LEGAL>, #<Pathname:BSDL>]
|
2232
|
+
# pathname.glob(pattern) # => [#<Pathname:LEGAL>, #<Pathname:BSDL>]
|
2233
|
+
#
|
2234
|
+
# #### File::FNM_NOESCAPE
|
2235
|
+
#
|
2236
|
+
# Flag File::FNM_NOESCAPE disables `'\'` escaping.
|
2237
|
+
#
|
2238
|
+
# #### File::FNM_PATHNAME
|
2239
|
+
#
|
2240
|
+
# Flag File::FNM_PATHNAME specifies that patterns `'*'` and `'?'` do not match
|
2241
|
+
# the directory separator (the value of constant File::SEPARATOR).
|
2242
|
+
#
|
2243
|
+
# #### File::FNM_SHORTNAME
|
2244
|
+
#
|
2245
|
+
# Flag File::FNM_SHORTNAME allows patterns to match short names if they exist.
|
2246
|
+
#
|
2247
|
+
# Windows only.
|
2248
|
+
#
|
2249
|
+
# #### File::FNM_SYSCASE
|
2250
|
+
#
|
2251
|
+
# Flag File::FNM_SYSCASE specifies that case sensitivity is the same as in the
|
2252
|
+
# underlying operating system; effective for File.fnmatch, but not Dir.glob.
|
2253
|
+
#
|
2254
|
+
# ## Other Constants
|
2255
|
+
#
|
2256
|
+
# #### File::NULL
|
2257
|
+
#
|
2258
|
+
# Flag File::NULL contains the string value of the null device:
|
2259
|
+
#
|
2260
|
+
# * On a Unix-like OS, `'/dev/null'`.
|
2261
|
+
# * On Windows, `'NUL'`.
|
2262
|
+
#
|
2263
|
+
module File::Constants
|
2264
|
+
end
|
2265
|
+
|
2266
|
+
# <!-- rdoc-file=file.c -->
|
2267
|
+
# [File::APPEND](rdoc-ref:File::Constants@File-3A-3AAPPEND)
|
2268
|
+
#
|
2269
|
+
File::Constants::APPEND: Integer
|
2270
|
+
|
2271
|
+
# <!-- rdoc-file=file.c -->
|
2272
|
+
# [File::BINARY](rdoc-ref:File::Constants@File-3A-3ABINARY)
|
2273
|
+
#
|
2274
|
+
File::Constants::BINARY: Integer
|
2275
|
+
|
2276
|
+
# <!-- rdoc-file=file.c -->
|
2277
|
+
# [File::CREAT](rdoc-ref:File::Constants@File-3A-3ACREAT)
|
2278
|
+
#
|
2279
|
+
File::Constants::CREAT: Integer
|
2280
|
+
|
2281
|
+
# <!-- rdoc-file=file.c -->
|
2282
|
+
# [File::DIRECT](rdoc-ref:File::Constants@File-3A-3ADIRECT)
|
2283
|
+
#
|
2284
|
+
File::Constants::DIRECT: Integer
|
2285
|
+
|
2286
|
+
# <!-- rdoc-file=file.c -->
|
2287
|
+
# [File::DSYNC](rdoc-ref:File::Constants@File-3A-3ASYNC-2C+File-3A-3ARSYNC-2C+an
|
2288
|
+
# d+File-3A-3ADSYNC)
|
2289
|
+
#
|
2290
|
+
File::Constants::DSYNC: Integer
|
2291
|
+
|
2292
|
+
# <!-- rdoc-file=file.c -->
|
2293
|
+
# [File::EXCL](rdoc-ref:File::Constants@File-3A-3AEXCL)
|
2294
|
+
#
|
2295
|
+
File::Constants::EXCL: Integer
|
2296
|
+
|
2297
|
+
# <!-- rdoc-file=dir.c -->
|
2298
|
+
# [File::FNM_CASEFOLD](rdoc-ref:File::Constants@File-3A-3AFNM_CASEFOLD)
|
2299
|
+
#
|
2300
|
+
File::Constants::FNM_CASEFOLD: Integer
|
2301
|
+
|
2302
|
+
# <!-- rdoc-file=dir.c -->
|
2303
|
+
# [File::FNM_DOTMATCH](rdoc-ref:File::Constants@File-3A-3AFNM_DOTMATCH)
|
2304
|
+
#
|
2305
|
+
File::Constants::FNM_DOTMATCH: Integer
|
2306
|
+
|
2307
|
+
# <!-- rdoc-file=dir.c -->
|
2308
|
+
# [File::FNM_EXTGLOB](rdoc-ref:File::Constants@File-3A-3AFNM_EXTGLOB)
|
2309
|
+
#
|
2310
|
+
File::Constants::FNM_EXTGLOB: Integer
|
2311
|
+
|
2312
|
+
# <!-- rdoc-file=dir.c -->
|
2313
|
+
# [File::FNM_NOESCAPE](rdoc-ref:File::Constants@File-3A-3AFNM_NOESCAPE)
|
2314
|
+
#
|
2315
|
+
File::Constants::FNM_NOESCAPE: Integer
|
2316
|
+
|
2317
|
+
# <!-- rdoc-file=dir.c -->
|
2318
|
+
# [File::FNM_PATHNAME](rdoc-ref:File::Constants@File-3A-3AFNM_PATHNAME)
|
2319
|
+
#
|
2320
|
+
File::Constants::FNM_PATHNAME: Integer
|
2321
|
+
|
2322
|
+
# <!-- rdoc-file=dir.c -->
|
2323
|
+
# [File::FNM_SHORTNAME](rdoc-ref:File::Constants@File-3A-3AFNM_SHORTNAME)
|
2324
|
+
#
|
2325
|
+
File::Constants::FNM_SHORTNAME: Integer
|
2326
|
+
|
2327
|
+
# <!-- rdoc-file=dir.c -->
|
2328
|
+
# [File::FNM_SYSCASE](rdoc-ref:File::Constants@File-3A-3AFNM_SYSCASE)
|
2329
|
+
#
|
2330
|
+
File::Constants::FNM_SYSCASE: Integer
|
2331
|
+
|
2332
|
+
# <!-- rdoc-file=file.c -->
|
2333
|
+
# [File::LOCK_EX](rdoc-ref:File::Constants@File-3A-3ALOCK_EX)
|
2334
|
+
#
|
2335
|
+
File::Constants::LOCK_EX: Integer
|
2336
|
+
|
2337
|
+
# <!-- rdoc-file=file.c -->
|
2338
|
+
# [File::LOCK_NB](rdoc-ref:File::Constants@File-3A-3ALOCK_NB)
|
2339
|
+
#
|
2340
|
+
File::Constants::LOCK_NB: Integer
|
2341
|
+
|
2342
|
+
# <!-- rdoc-file=file.c -->
|
2343
|
+
# [File::LOCK_SH](rdoc-ref:File::Constants@File-3A-3ALOCK_SH)
|
2344
|
+
#
|
2345
|
+
File::Constants::LOCK_SH: Integer
|
2346
|
+
|
2347
|
+
# <!-- rdoc-file=file.c -->
|
2348
|
+
# [File::LOCK_UN](rdoc-ref:File::Constants@File-3A-3ALOCK_UN)
|
2349
|
+
#
|
2350
|
+
File::Constants::LOCK_UN: Integer
|
2351
|
+
|
2352
|
+
# <!-- rdoc-file=file.c -->
|
2353
|
+
# [File::NOATIME](rdoc-ref:File::Constants@File-3A-3ANOATIME)
|
2354
|
+
#
|
2355
|
+
File::Constants::NOATIME: Integer
|
2356
|
+
|
2357
|
+
# <!-- rdoc-file=file.c -->
|
2358
|
+
# [File::NOCTTY](rdoc-ref:File::Constants@File-3A-3ANOCTTY)
|
2359
|
+
#
|
2360
|
+
File::Constants::NOCTTY: Integer
|
2361
|
+
|
2362
|
+
# <!-- rdoc-file=file.c -->
|
2363
|
+
# [File::NOFOLLOW](rdoc-ref:File::Constants@File-3A-3ANOFOLLOW)
|
2364
|
+
#
|
2365
|
+
File::Constants::NOFOLLOW: Integer
|
2366
|
+
|
2367
|
+
# <!-- rdoc-file=file.c -->
|
2368
|
+
# [File::NONBLOCK](rdoc-ref:File::Constants@File-3A-3ANONBLOCK)
|
2369
|
+
#
|
2370
|
+
File::Constants::NONBLOCK: Integer
|
2371
|
+
|
2372
|
+
# <!-- rdoc-file=file.c -->
|
2373
|
+
# [File::NULL](rdoc-ref:File::Constants@File-3A-3ANULL)
|
2374
|
+
#
|
2375
|
+
File::Constants::NULL: String
|
2376
|
+
|
2377
|
+
# <!-- rdoc-file=file.c -->
|
2378
|
+
# [File::RDONLY](rdoc-ref:File::Constants@File-3A-3ARDONLY)
|
2379
|
+
#
|
2380
|
+
File::Constants::RDONLY: Integer
|
2381
|
+
|
2382
|
+
# <!-- rdoc-file=file.c -->
|
2383
|
+
# [File::RDWR](rdoc-ref:File::Constants@File-3A-3ARDWR)
|
2384
|
+
#
|
2385
|
+
File::Constants::RDWR: Integer
|
2386
|
+
|
2387
|
+
# <!-- rdoc-file=file.c -->
|
2388
|
+
# [File::RSYNC](rdoc-ref:File::Constants@File-3A-3ASYNC-2C+File-3A-3ARSYNC-2C+an
|
2389
|
+
# d+File-3A-3ADSYNC)
|
2390
|
+
#
|
2391
|
+
File::Constants::RSYNC: Integer
|
2392
|
+
|
2393
|
+
# <!-- rdoc-file=file.c -->
|
2394
|
+
# [File::SHARE_DELETE](rdoc-ref:File::Constants@File-3A-3ASHARE_DELETE)
|
2395
|
+
#
|
2396
|
+
File::Constants::SHARE_DELETE: Integer
|
2397
|
+
|
2398
|
+
# <!-- rdoc-file=file.c -->
|
2399
|
+
# [File::SYNC](rdoc-ref:File::Constants@File-3A-3ASYNC-2C+File-3A-3ARSYNC-2C+and
|
2400
|
+
# +File-3A-3ADSYNC)
|
2401
|
+
#
|
2402
|
+
File::Constants::SYNC: Integer
|
2403
|
+
|
2404
|
+
# <!-- rdoc-file=file.c -->
|
2405
|
+
# [File::TMPFILE](rdoc-ref:File::Constants@File-3A-3ATMPFILE)
|
2406
|
+
#
|
2407
|
+
File::Constants::TMPFILE: Integer
|
2408
|
+
|
2409
|
+
# <!-- rdoc-file=file.c -->
|
2410
|
+
# [File::TRUNC](rdoc-ref:File::Constants@File-3A-3ATRUNC)
|
2411
|
+
#
|
2412
|
+
File::Constants::TRUNC: Integer
|
2413
|
+
|
2414
|
+
# <!-- rdoc-file=file.c -->
|
2415
|
+
# [File::WRONLY](rdoc-ref:File::Constants@File-3A-3AWRONLY)
|
2416
|
+
#
|
2417
|
+
File::Constants::WRONLY: Integer
|
2418
|
+
|
2419
|
+
# <!-- rdoc-file=file.c -->
|
2420
|
+
# Objects of class File::Stat encapsulate common status information for File
|
2421
|
+
# objects. The information is recorded at the moment the File::Stat object is
|
2422
|
+
# created; changes made to the file after that point will not be reflected.
|
2423
|
+
# File::Stat objects are returned by IO#stat, File::stat, File#lstat, and
|
2424
|
+
# File::lstat. Many of these methods return platform-specific values, and not
|
2425
|
+
# all values are meaningful on all systems. See also Kernel#test.
|
2426
|
+
#
|
2427
|
+
class File::Stat < Object
|
2428
|
+
include Comparable
|
2429
|
+
|
2430
|
+
# <!--
|
2431
|
+
# rdoc-file=file.c
|
2432
|
+
# - new(p1)
|
2433
|
+
# -->
|
2434
|
+
# File::Stat.new(file_name) -> stat
|
2435
|
+
#
|
2436
|
+
# Create a File::Stat object for the given file name (raising an exception if
|
2437
|
+
# the file doesn't exist).
|
2438
|
+
#
|
2439
|
+
def initialize: (String file) -> void
|
2440
|
+
|
2441
|
+
# <!--
|
2442
|
+
# rdoc-file=file.c
|
2443
|
+
# - stat <=> other_stat -> -1, 0, 1, nil
|
2444
|
+
# -->
|
2445
|
+
# Compares File::Stat objects by comparing their respective modification times.
|
2446
|
+
#
|
2447
|
+
# `nil` is returned if `other_stat` is not a File::Stat object
|
2448
|
+
#
|
2449
|
+
# f1 = File.new("f1", "w")
|
2450
|
+
# sleep 1
|
2451
|
+
# f2 = File.new("f2", "w")
|
2452
|
+
# f1.stat <=> f2.stat #=> -1
|
2453
|
+
#
|
2454
|
+
def <=>: (File::Stat other) -> Integer
|
2455
|
+
| (untyped) -> nil
|
2456
|
+
|
2457
|
+
# <!--
|
2458
|
+
# rdoc-file=file.c
|
2459
|
+
# - stat.atime -> time
|
2460
|
+
# -->
|
2461
|
+
# Returns the last access time for this file as an object of class Time.
|
2462
|
+
#
|
2463
|
+
# File.stat("testfile").atime #=> Wed Dec 31 18:00:00 CST 1969
|
2464
|
+
#
|
2465
|
+
def atime: () -> Time
|
2466
|
+
|
2467
|
+
# <!--
|
2468
|
+
# rdoc-file=file.c
|
2469
|
+
# - stat.birthtime -> time
|
2470
|
+
# -->
|
2471
|
+
# Returns the birth time for *stat*.
|
2472
|
+
#
|
2473
|
+
# If the platform doesn't have birthtime, raises NotImplementedError.
|
2474
|
+
#
|
2475
|
+
# File.write("testfile", "foo")
|
2476
|
+
# sleep 10
|
2477
|
+
# File.write("testfile", "bar")
|
2478
|
+
# sleep 10
|
2479
|
+
# File.chmod(0644, "testfile")
|
2480
|
+
# sleep 10
|
2481
|
+
# File.read("testfile")
|
2482
|
+
# File.stat("testfile").birthtime #=> 2014-02-24 11:19:17 +0900
|
2483
|
+
# File.stat("testfile").mtime #=> 2014-02-24 11:19:27 +0900
|
2484
|
+
# File.stat("testfile").ctime #=> 2014-02-24 11:19:37 +0900
|
2485
|
+
# File.stat("testfile").atime #=> 2014-02-24 11:19:47 +0900
|
2486
|
+
#
|
2487
|
+
def birthtime: () -> Time
|
2488
|
+
|
2489
|
+
# <!--
|
2490
|
+
# rdoc-file=file.c
|
2491
|
+
# - stat.blksize -> integer or nil
|
2492
|
+
# -->
|
2493
|
+
# Returns the native file system's block size. Will return `nil` on platforms
|
2494
|
+
# that don't support this information.
|
2495
|
+
#
|
2496
|
+
# File.stat("testfile").blksize #=> 4096
|
2497
|
+
#
|
2498
|
+
def blksize: () -> Integer?
|
2499
|
+
|
2500
|
+
# <!--
|
2501
|
+
# rdoc-file=file.c
|
2502
|
+
# - stat.blockdev? -> true or false
|
2503
|
+
# -->
|
2504
|
+
# Returns `true` if the file is a block device, `false` if it isn't or if the
|
2505
|
+
# operating system doesn't support this feature.
|
2506
|
+
#
|
2507
|
+
# File.stat("testfile").blockdev? #=> false
|
2508
|
+
# File.stat("/dev/hda1").blockdev? #=> true
|
2509
|
+
#
|
2510
|
+
def blockdev?: () -> bool
|
2511
|
+
|
2512
|
+
# <!--
|
2513
|
+
# rdoc-file=file.c
|
2514
|
+
# - stat.blocks -> integer or nil
|
2515
|
+
# -->
|
2516
|
+
# Returns the number of native file system blocks allocated for this file, or
|
2517
|
+
# `nil` if the operating system doesn't support this feature.
|
2518
|
+
#
|
2519
|
+
# File.stat("testfile").blocks #=> 2
|
2520
|
+
#
|
2521
|
+
def blocks: () -> Integer?
|
2522
|
+
|
2523
|
+
# <!--
|
2524
|
+
# rdoc-file=file.c
|
2525
|
+
# - stat.chardev? -> true or false
|
2526
|
+
# -->
|
2527
|
+
# Returns `true` if the file is a character device, `false` if it isn't or if
|
2528
|
+
# the operating system doesn't support this feature.
|
2529
|
+
#
|
2530
|
+
# File.stat("/dev/tty").chardev? #=> true
|
2531
|
+
#
|
2532
|
+
def chardev?: () -> bool
|
2533
|
+
|
2534
|
+
# <!--
|
2535
|
+
# rdoc-file=file.c
|
2536
|
+
# - stat.ctime -> time
|
2537
|
+
# -->
|
2538
|
+
# Returns the change time for *stat* (that is, the time directory information
|
2539
|
+
# about the file was changed, not the file itself).
|
2540
|
+
#
|
2541
|
+
# Note that on Windows (NTFS), returns creation time (birth time).
|
2542
|
+
#
|
2543
|
+
# File.stat("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
|
2544
|
+
#
|
2545
|
+
def ctime: () -> Time
|
2546
|
+
|
2547
|
+
# <!--
|
2548
|
+
# rdoc-file=file.c
|
2549
|
+
# - stat.dev -> integer
|
2550
|
+
# -->
|
2551
|
+
# Returns an integer representing the device on which *stat* resides.
|
2552
|
+
#
|
2553
|
+
# File.stat("testfile").dev #=> 774
|
2554
|
+
#
|
2555
|
+
def dev: () -> Integer
|
2556
|
+
|
2557
|
+
# <!--
|
2558
|
+
# rdoc-file=file.c
|
2559
|
+
# - stat.dev_major -> integer
|
2560
|
+
# -->
|
2561
|
+
# Returns the major part of `File_Stat#dev` or `nil`.
|
2562
|
+
#
|
2563
|
+
# File.stat("/dev/fd1").dev_major #=> 2
|
2564
|
+
# File.stat("/dev/tty").dev_major #=> 5
|
2565
|
+
#
|
2566
|
+
def dev_major: () -> Integer
|
2567
|
+
|
2568
|
+
# <!--
|
2569
|
+
# rdoc-file=file.c
|
2570
|
+
# - stat.dev_minor -> integer
|
2571
|
+
# -->
|
2572
|
+
# Returns the minor part of `File_Stat#dev` or `nil`.
|
2573
|
+
#
|
2574
|
+
# File.stat("/dev/fd1").dev_minor #=> 1
|
2575
|
+
# File.stat("/dev/tty").dev_minor #=> 0
|
2576
|
+
#
|
2577
|
+
def dev_minor: () -> Integer
|
2578
|
+
|
2579
|
+
# <!--
|
2580
|
+
# rdoc-file=file.c
|
2581
|
+
# - stat.directory? -> true or false
|
2582
|
+
# -->
|
2583
|
+
# Returns `true` if *stat* is a directory, `false` otherwise.
|
2584
|
+
#
|
2585
|
+
# File.stat("testfile").directory? #=> false
|
2586
|
+
# File.stat(".").directory? #=> true
|
2587
|
+
#
|
2588
|
+
def directory?: () -> bool
|
2589
|
+
|
2590
|
+
# <!--
|
2591
|
+
# rdoc-file=file.c
|
2592
|
+
# - stat.executable? -> true or false
|
2593
|
+
# -->
|
2594
|
+
# Returns `true` if *stat* is executable or if the operating system doesn't
|
2595
|
+
# distinguish executable files from nonexecutable files. The tests are made
|
2596
|
+
# using the effective owner of the process.
|
2597
|
+
#
|
2598
|
+
# File.stat("testfile").executable? #=> false
|
2599
|
+
#
|
2600
|
+
def executable?: () -> bool
|
2601
|
+
|
2602
|
+
# <!--
|
2603
|
+
# rdoc-file=file.c
|
2604
|
+
# - stat.executable_real? -> true or false
|
2605
|
+
# -->
|
2606
|
+
# Same as `executable?`, but tests using the real owner of the process.
|
2607
|
+
#
|
2608
|
+
def executable_real?: () -> bool
|
2609
|
+
|
2610
|
+
# <!--
|
2611
|
+
# rdoc-file=file.c
|
2612
|
+
# - stat.file? -> true or false
|
2613
|
+
# -->
|
2614
|
+
# Returns `true` if *stat* is a regular file (not a device file, pipe, socket,
|
2615
|
+
# etc.).
|
2616
|
+
#
|
2617
|
+
# File.stat("testfile").file? #=> true
|
2618
|
+
#
|
2619
|
+
def file?: () -> bool
|
2620
|
+
|
2621
|
+
# <!--
|
2622
|
+
# rdoc-file=file.c
|
2623
|
+
# - stat.ftype -> string
|
2624
|
+
# -->
|
2625
|
+
# Identifies the type of *stat*. The return string is one of: ```file`'',
|
2626
|
+
# ```directory`'', ```characterSpecial`'', ```blockSpecial`'', ```fifo`'',
|
2627
|
+
# ```link`'', ```socket`'', or ```unknown`''.
|
2628
|
+
#
|
2629
|
+
# File.stat("/dev/tty").ftype #=> "characterSpecial"
|
2630
|
+
#
|
2631
|
+
def ftype: () -> String
|
2632
|
+
|
2633
|
+
# <!--
|
2634
|
+
# rdoc-file=file.c
|
2635
|
+
# - stat.gid -> integer
|
2636
|
+
# -->
|
2637
|
+
# Returns the numeric group id of the owner of *stat*.
|
2638
|
+
#
|
2639
|
+
# File.stat("testfile").gid #=> 500
|
2640
|
+
#
|
2641
|
+
def gid: () -> Integer
|
2642
|
+
|
2643
|
+
# <!--
|
2644
|
+
# rdoc-file=file.c
|
2645
|
+
# - stat.grpowned? -> true or false
|
2646
|
+
# -->
|
2647
|
+
# Returns true if the effective group id of the process is the same as the group
|
2648
|
+
# id of *stat*. On Windows, returns `false`.
|
2649
|
+
#
|
2650
|
+
# File.stat("testfile").grpowned? #=> true
|
2651
|
+
# File.stat("/etc/passwd").grpowned? #=> false
|
2652
|
+
#
|
2653
|
+
def grpowned?: () -> bool
|
2654
|
+
|
2655
|
+
# <!--
|
2656
|
+
# rdoc-file=file.c
|
2657
|
+
# - stat.ino -> integer
|
2658
|
+
# -->
|
2659
|
+
# Returns the inode number for *stat*.
|
2660
|
+
#
|
2661
|
+
# File.stat("testfile").ino #=> 1083669
|
2662
|
+
#
|
2663
|
+
def ino: () -> Integer
|
2664
|
+
|
2665
|
+
# <!--
|
2666
|
+
# rdoc-file=file.c
|
2667
|
+
# - stat.inspect -> string
|
2668
|
+
# -->
|
2669
|
+
# Produce a nicely formatted description of *stat*.
|
2670
|
+
#
|
2671
|
+
# File.stat("/etc/passwd").inspect
|
2672
|
+
# #=> "#<File::Stat dev=0xe000005, ino=1078078, mode=0100644,
|
2673
|
+
# # nlink=1, uid=0, gid=0, rdev=0x0, size=1374, blksize=4096,
|
2674
|
+
# # blocks=8, atime=Wed Dec 10 10:16:12 CST 2003,
|
2675
|
+
# # mtime=Fri Sep 12 15:41:41 CDT 2003,
|
2676
|
+
# # ctime=Mon Oct 27 11:20:27 CST 2003,
|
2677
|
+
# # birthtime=Mon Aug 04 08:13:49 CDT 2003>"
|
2678
|
+
#
|
2679
|
+
def inspect: () -> String
|
2680
|
+
|
2681
|
+
# <!--
|
2682
|
+
# rdoc-file=file.c
|
2683
|
+
# - stat.mode -> integer
|
2684
|
+
# -->
|
2685
|
+
# Returns an integer representing the permission bits of *stat*. The meaning of
|
2686
|
+
# the bits is platform dependent; on Unix systems, see `stat(2)`.
|
2687
|
+
#
|
2688
|
+
# File.chmod(0644, "testfile") #=> 1
|
2689
|
+
# s = File.stat("testfile")
|
2690
|
+
# sprintf("%o", s.mode) #=> "100644"
|
2691
|
+
#
|
2692
|
+
def mode: () -> Integer
|
2693
|
+
|
2694
|
+
# <!--
|
2695
|
+
# rdoc-file=file.c
|
2696
|
+
# - stat.mtime -> time
|
2697
|
+
# -->
|
2698
|
+
# Returns the modification time of *stat*.
|
2699
|
+
#
|
2700
|
+
# File.stat("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
|
2701
|
+
#
|
2702
|
+
def mtime: () -> Time
|
2703
|
+
|
2704
|
+
# <!--
|
2705
|
+
# rdoc-file=file.c
|
2706
|
+
# - stat.nlink -> integer
|
2707
|
+
# -->
|
2708
|
+
# Returns the number of hard links to *stat*.
|
2709
|
+
#
|
2710
|
+
# File.stat("testfile").nlink #=> 1
|
2711
|
+
# File.link("testfile", "testfile.bak") #=> 0
|
2712
|
+
# File.stat("testfile").nlink #=> 2
|
2713
|
+
#
|
2714
|
+
def nlink: () -> Integer
|
2715
|
+
|
2716
|
+
# <!--
|
2717
|
+
# rdoc-file=file.c
|
2718
|
+
# - stat.owned? -> true or false
|
2719
|
+
# -->
|
2720
|
+
# Returns `true` if the effective user id of the process is the same as the
|
2721
|
+
# owner of *stat*.
|
2722
|
+
#
|
2723
|
+
# File.stat("testfile").owned? #=> true
|
2724
|
+
# File.stat("/etc/passwd").owned? #=> false
|
2725
|
+
#
|
2726
|
+
def owned?: () -> bool
|
2727
|
+
|
2728
|
+
# <!--
|
2729
|
+
# rdoc-file=file.c
|
2730
|
+
# - stat.pipe? -> true or false
|
2731
|
+
# -->
|
2732
|
+
# Returns `true` if the operating system supports pipes and *stat* is a pipe;
|
2733
|
+
# `false` otherwise.
|
2734
|
+
#
|
2735
|
+
def pipe?: () -> bool
|
2736
|
+
|
2737
|
+
# <!--
|
2738
|
+
# rdoc-file=file.c
|
2739
|
+
# - stat.rdev -> integer or nil
|
2740
|
+
# -->
|
2741
|
+
# Returns an integer representing the device type on which *stat* resides.
|
2742
|
+
# Returns `nil` if the operating system doesn't support this feature.
|
2743
|
+
#
|
2744
|
+
# File.stat("/dev/fd1").rdev #=> 513
|
2745
|
+
# File.stat("/dev/tty").rdev #=> 1280
|
2746
|
+
#
|
2747
|
+
def rdev: () -> Integer?
|
2748
|
+
|
2749
|
+
# <!--
|
2750
|
+
# rdoc-file=file.c
|
2751
|
+
# - stat.rdev_major -> integer
|
2752
|
+
# -->
|
2753
|
+
# Returns the major part of `File_Stat#rdev` or `nil`.
|
2754
|
+
#
|
2755
|
+
# File.stat("/dev/fd1").rdev_major #=> 2
|
2756
|
+
# File.stat("/dev/tty").rdev_major #=> 5
|
2757
|
+
#
|
2758
|
+
def rdev_major: () -> Integer
|
2759
|
+
|
2760
|
+
# <!--
|
2761
|
+
# rdoc-file=file.c
|
2762
|
+
# - stat.rdev_minor -> integer
|
2763
|
+
# -->
|
2764
|
+
# Returns the minor part of `File_Stat#rdev` or `nil`.
|
2765
|
+
#
|
2766
|
+
# File.stat("/dev/fd1").rdev_minor #=> 1
|
2767
|
+
# File.stat("/dev/tty").rdev_minor #=> 0
|
2768
|
+
#
|
2769
|
+
def rdev_minor: () -> Integer
|
2770
|
+
|
2771
|
+
# <!--
|
2772
|
+
# rdoc-file=file.c
|
2773
|
+
# - stat.readable? -> true or false
|
2774
|
+
# -->
|
2775
|
+
# Returns `true` if *stat* is readable by the effective user id of this process.
|
2776
|
+
#
|
2777
|
+
# File.stat("testfile").readable? #=> true
|
2778
|
+
#
|
2779
|
+
def readable?: () -> bool
|
2780
|
+
|
2781
|
+
# <!--
|
2782
|
+
# rdoc-file=file.c
|
2783
|
+
# - stat.readable_real? -> true or false
|
2784
|
+
# -->
|
2785
|
+
# Returns `true` if *stat* is readable by the real user id of this process.
|
2786
|
+
#
|
2787
|
+
# File.stat("testfile").readable_real? #=> true
|
2788
|
+
#
|
2789
|
+
def readable_real?: () -> bool
|
2790
|
+
|
2791
|
+
# <!--
|
2792
|
+
# rdoc-file=file.c
|
2793
|
+
# - stat.setgid? -> true or false
|
2794
|
+
# -->
|
2795
|
+
# Returns `true` if *stat* has the set-group-id permission bit set, `false` if
|
2796
|
+
# it doesn't or if the operating system doesn't support this feature.
|
2797
|
+
#
|
2798
|
+
# File.stat("/usr/sbin/lpc").setgid? #=> true
|
2799
|
+
#
|
2800
|
+
def setgid?: () -> bool
|
2801
|
+
|
2802
|
+
# <!--
|
2803
|
+
# rdoc-file=file.c
|
2804
|
+
# - stat.setuid? -> true or false
|
2805
|
+
# -->
|
2806
|
+
# Returns `true` if *stat* has the set-user-id permission bit set, `false` if it
|
2807
|
+
# doesn't or if the operating system doesn't support this feature.
|
2808
|
+
#
|
2809
|
+
# File.stat("/bin/su").setuid? #=> true
|
2810
|
+
#
|
2811
|
+
def setuid?: () -> bool
|
2812
|
+
|
2813
|
+
# <!--
|
2814
|
+
# rdoc-file=file.c
|
2815
|
+
# - stat.size -> integer
|
2816
|
+
# -->
|
2817
|
+
# Returns the size of *stat* in bytes.
|
2818
|
+
#
|
2819
|
+
# File.stat("testfile").size #=> 66
|
2820
|
+
#
|
2821
|
+
def size: () -> Integer
|
2822
|
+
|
2823
|
+
# <!--
|
2824
|
+
# rdoc-file=file.c
|
2825
|
+
# - stat.size? -> Integer or nil
|
2826
|
+
# -->
|
2827
|
+
# Returns `nil` if *stat* is a zero-length file, the size of the file otherwise.
|
2828
|
+
#
|
2829
|
+
# File.stat("testfile").size? #=> 66
|
2830
|
+
# File.stat(File::NULL).size? #=> nil
|
2831
|
+
#
|
2832
|
+
def size?: () -> Integer?
|
2833
|
+
|
2834
|
+
# <!--
|
2835
|
+
# rdoc-file=file.c
|
2836
|
+
# - stat.socket? -> true or false
|
2837
|
+
# -->
|
2838
|
+
# Returns `true` if *stat* is a socket, `false` if it isn't or if the operating
|
2839
|
+
# system doesn't support this feature.
|
2840
|
+
#
|
2841
|
+
# File.stat("testfile").socket? #=> false
|
2842
|
+
#
|
2843
|
+
def socket?: () -> bool
|
2844
|
+
|
2845
|
+
# <!--
|
2846
|
+
# rdoc-file=file.c
|
2847
|
+
# - stat.sticky? -> true or false
|
2848
|
+
# -->
|
2849
|
+
# Returns `true` if *stat* has its sticky bit set, `false` if it doesn't or if
|
2850
|
+
# the operating system doesn't support this feature.
|
2851
|
+
#
|
2852
|
+
# File.stat("testfile").sticky? #=> false
|
2853
|
+
#
|
2854
|
+
def sticky?: () -> bool
|
2855
|
+
|
2856
|
+
# <!--
|
2857
|
+
# rdoc-file=file.c
|
2858
|
+
# - stat.symlink? -> true or false
|
2859
|
+
# -->
|
2860
|
+
# Returns `true` if *stat* is a symbolic link, `false` if it isn't or if the
|
2861
|
+
# operating system doesn't support this feature. As File::stat automatically
|
2862
|
+
# follows symbolic links, #symlink? will always be `false` for an object
|
2863
|
+
# returned by File::stat.
|
2864
|
+
#
|
2865
|
+
# File.symlink("testfile", "alink") #=> 0
|
2866
|
+
# File.stat("alink").symlink? #=> false
|
2867
|
+
# File.lstat("alink").symlink? #=> true
|
2868
|
+
#
|
2869
|
+
def symlink?: () -> bool
|
2870
|
+
|
2871
|
+
# <!--
|
2872
|
+
# rdoc-file=file.c
|
2873
|
+
# - stat.uid -> integer
|
2874
|
+
# -->
|
2875
|
+
# Returns the numeric user id of the owner of *stat*.
|
2876
|
+
#
|
2877
|
+
# File.stat("testfile").uid #=> 501
|
2878
|
+
#
|
2879
|
+
def uid: () -> Integer
|
2880
|
+
|
2881
|
+
# <!--
|
2882
|
+
# rdoc-file=file.c
|
2883
|
+
# - stat.world_readable? -> integer or nil
|
2884
|
+
# -->
|
2885
|
+
# If *stat* is readable by others, returns an integer representing the file
|
2886
|
+
# permission bits of *stat*. Returns `nil` otherwise. The meaning of the bits is
|
2887
|
+
# platform dependent; on Unix systems, see `stat(2)`.
|
2888
|
+
#
|
2889
|
+
# m = File.stat("/etc/passwd").world_readable? #=> 420
|
2890
|
+
# sprintf("%o", m) #=> "644"
|
2891
|
+
#
|
2892
|
+
def world_readable?: () -> Integer?
|
2893
|
+
|
2894
|
+
# <!--
|
2895
|
+
# rdoc-file=file.c
|
2896
|
+
# - stat.world_writable? -> integer or nil
|
2897
|
+
# -->
|
2898
|
+
# If *stat* is writable by others, returns an integer representing the file
|
2899
|
+
# permission bits of *stat*. Returns `nil` otherwise. The meaning of the bits is
|
2900
|
+
# platform dependent; on Unix systems, see `stat(2)`.
|
2901
|
+
#
|
2902
|
+
# m = File.stat("/tmp").world_writable? #=> 511
|
2903
|
+
# sprintf("%o", m) #=> "777"
|
2904
|
+
#
|
2905
|
+
def world_writable?: () -> Integer?
|
2906
|
+
|
2907
|
+
# <!--
|
2908
|
+
# rdoc-file=file.c
|
2909
|
+
# - stat.writable? -> true or false
|
2910
|
+
# -->
|
2911
|
+
# Returns `true` if *stat* is writable by the effective user id of this process.
|
2912
|
+
#
|
2913
|
+
# File.stat("testfile").writable? #=> true
|
2914
|
+
#
|
2915
|
+
def writable?: () -> bool
|
2916
|
+
|
2917
|
+
# <!--
|
2918
|
+
# rdoc-file=file.c
|
2919
|
+
# - stat.writable_real? -> true or false
|
2920
|
+
# -->
|
2921
|
+
# Returns `true` if *stat* is writable by the real user id of this process.
|
2922
|
+
#
|
2923
|
+
# File.stat("testfile").writable_real? #=> true
|
2924
|
+
#
|
2925
|
+
def writable_real?: () -> bool
|
2926
|
+
|
2927
|
+
# <!--
|
2928
|
+
# rdoc-file=file.c
|
2929
|
+
# - stat.zero? -> true or false
|
2930
|
+
# -->
|
2931
|
+
# Returns `true` if *stat* is a zero-length file; `false` otherwise.
|
2932
|
+
#
|
2933
|
+
# File.stat("testfile").zero? #=> false
|
2934
|
+
#
|
2935
|
+
def zero?: () -> bool
|
2936
|
+
end
|