From df3ce9890ae475f7bbd40cc2655139a4f9fde5b0 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Mon, 12 Jan 2026 10:15:05 +0000 Subject: [PATCH] add extra kwarg options for File#initialize and derivatives this adds the missing kwargs (known as "Open options" and "Encoding options" in the docs) signatures to the following methods, which implemented the same derivative signature: * File#initialize * File.open * Pathname#open --- core/file.rbs | 75 ++++++++++++++++++++++++++++++++++-- core/pathname.rbs | 47 +++++++++++++++++++++- test/stdlib/File_test.rb | 9 +++++ test/stdlib/Pathname_test.rb | 3 ++ 4 files changed, 129 insertions(+), 5 deletions(-) diff --git a/core/file.rbs b/core/file.rbs index c77952cf2..5371d76ce 100644 --- a/core/file.rbs +++ b/core/file.rbs @@ -847,7 +847,30 @@ class File < IO # * [Open Options](rdoc-ref:IO@Open+Options). # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options). # - def initialize: (path | int file_name, ?string | int mode, ?int perm) -> void + def initialize: ( + path | int file_name, + ?string | int mode, + ?int perm, + # open options + ?mode: Integer | String, + ?flags: Integer, + ?external_encoding: encoding, + ?internal_encoding: encoding, + ?encoding: encoding, + ?textmode: boolish, + ?binmode: boolish, + ?autoclose: boolish, + ?path: path, + # encoding options + ?invalid: :replace | nil, + ?undef: :replace | nil, + ?replace: String | nil, + ?fallback: Hash[string, string] | ^(String) -> string | Method | nil, + ?xml: :text | :attr | nil, + ?cr_newline: bool, + ?crlf_newline: bool, + ?universal_newline: bool + ) -> void # # See `File.open`. Opens the file for reading or writing. # - def open: (?string | int mode, ?int perm) -> File - | [T] (?string | int mode, ?int perm) { (File) -> T } -> T + def open: ( + ?string | int mode, + ?int perm, + # open options + ?flags: Integer, + ?external_encoding: encoding, + ?internal_encoding: encoding, + ?encoding: encoding, + ?textmode: boolish, + ?binmode: boolish, + ?autoclose: boolish, + ?path: path, + # encoding options + ?invalid: :replace | nil, + ?undef: :replace | nil, + ?replace: String | nil, + ?fallback: Hash[string, string] | ^(String) -> string | Method | nil, + ?xml: :text | :attr | nil, + ?cr_newline: bool, + ?crlf_newline: bool, + ?universal_newline: bool + ) -> File + | [T] ( + ?string | int mode, + ?int perm, + # open options + ?mode: Integer | String, + ?flags: Integer, + ?external_encoding: encoding, + ?internal_encoding: encoding, + ?encoding: encoding, + ?textmode: boolish, + ?binmode: boolish, + ?autoclose: boolish, + ?path: path, + # encoding options + ?invalid: :replace | nil, + ?undef: :replace | nil, + ?replace: String | nil, + ?fallback: Hash[string, string] | ^(String) -> string | Method | nil, + ?xml: :text | :attr | nil, + ?cr_newline: bool, + ?crlf_newline: bool, + ?universal_newline: bool + ) { (File) -> T } -> T #