From c0804a05fbb10e8d3a8bd0059bba187b1f426711 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Thu, 21 May 2026 20:23:31 +0900 Subject: [PATCH] Correct core/stdlib signatures to match Ruby 4.0 Update several signatures that were inaccurate against the Ruby 4.0 implementation: - `IO#pathconf`: add the method (`(Integer) -> Integer?`). - `Digest::Instance#finish`: return `String`, not `self`. - `Digest::Class.{digest,hexdigest,bubblebabble,file,base64digest}`: accept the trailing `*args` passed to the constructor. - `Etc.sysconf` / `Etc.systmpdir`: return types are nilable. - `Etc::Group.each` / `Etc::Passwd.each`: add block / Enumerator overloads. - `Etc::Passwd`: add the `age`, `comment`, and `quota` members. - `StringIO`: non-block `self.open` overload; `fcntl` always raises (`bot`); `fsync` returns `0`; `internal_encoding` returns `nil`; `external_encoding` is nilable; add `pread` and `write_nonblock`; `read_nonblock` takes `exception:` and is nilable; `sysread` `outbuf` is optional; `ungetc` also accepts an `Integer`; add `set_encoding_by_bom`. --- core/io.rbs | 18 ++++++++++++++++ stdlib/digest/0/digest.rbs | 12 +++++------ stdlib/etc/0/etc.rbs | 22 ++++++++++++++++---- stdlib/stringio/0/stringio.rbs | 38 +++++++++++++++++++++++++++------- 4 files changed, 72 insertions(+), 18 deletions(-) diff --git a/core/io.rbs b/core/io.rbs index 96f82c1aff..1b6f79bb95 100644 --- a/core/io.rbs +++ b/core/io.rbs @@ -1230,6 +1230,24 @@ class IO < Object # def ioctl: (Integer integer_cmd, String | Integer argument) -> Integer + # + # Returns pathname configuration variable using fpathconf(). + # + # *name* should be a constant under `Etc` which begins with `PC_`. + # + # The return value is an integer or nil. nil means indefinite limit. + # (fpathconf() returns -1 but errno is not set.) + # + # require 'etc' + # IO.pipe {|r, w| + # p w.pathconf(Etc::PC_PIPE_BUF) #=> 4096 + # } + # + def pathconf: (Integer name) -> Integer? + # @@ -319,7 +319,7 @@ class Digest::Class # Returns the base64 encoded hash value of a given *string*. The return value # is properly padded with '=' and contains no line feeds. # - def self.base64digest: (string str) -> String + def self.base64digest: (string str, *untyped args) -> String # # Returns the BubbleBabble encoded hash value of a given *string*. # - def self.bubblebabble: (string) -> String + def self.bubblebabble: (string, *untyped) -> String # # Returns system temporary directory; typically "/tmp". # - def self?.systmpdir: () -> ::String + def self?.systmpdir: () -> ::String? # # Raises NotImplementedError. # - def fcntl: (Integer integer_cmd, String | Integer arg) -> Integer + def fcntl: (*untyped) -> bot # # Returns 0; for compatibility with IO. # - def fsync: () -> Integer? + def fsync: () -> Integer # # Returns `nil`; for compatibility with IO. # - def internal_encoding: () -> Encoding + def internal_encoding: () -> nil # + # See IO#pread. + # + def pread: (Integer maxlen, Integer offset, ?String outbuf) -> String + + def read_nonblock: (int len, ?string buf, ?exception: bool) -> String? def readbyte: () -> Integer @@ -1358,6 +1368,16 @@ class StringIO def set_encoding: (?String | Encoding ext_or_ext_int_enc) -> self | (?String | Encoding ext_or_ext_int_enc, ?String | Encoding int_enc) -> self + # + # Sets the encoding according to the BOM (Byte Order Mark) in the string. + # + # Returns `self` if the BOM is found, otherwise +nil. + # + def set_encoding_by_bom: () -> Encoding? + #