From 4b316b39b9eb0a13a7b9009fa5578a5a084c88d5 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 11 Oct 2026 14:21:47 +0900 Subject: [PATCH] Add missing core instance methods Add signatures for public instance methods that are defined in Ruby 4.0 but were missing from core/: - Binding#implicit_parameter_defined?, #implicit_parameter_get, #implicit_parameters - IO#external_encoding, IO#to_path, IO#wait_priority - Process::Tms#utime, #stime, #cutime, #cstime and their setters - Thread#set_trace_func --- core/binding.rbs | 66 +++++++++++++++++++++++++++++++++ core/io.rbs | 22 +++++++++++ core/io/wait.rbs | 11 ++++++ core/process.rbs | 19 ++++++++++ core/thread.rbs | 13 +++++++ test/stdlib/Binding_test.rb | 43 +++++++++++++++++++++ test/stdlib/IO_test.rb | 47 +++++++++++++++++++++++ test/stdlib/Process_Tms_test.rb | 39 +++++++++++++++++++ test/stdlib/Thread_test.rb | 11 ++++++ 9 files changed, 271 insertions(+) create mode 100644 test/stdlib/Process_Tms_test.rb diff --git a/core/binding.rbs b/core/binding.rbs index fea7af371a..31952d547a 100644 --- a/core/binding.rbs +++ b/core/binding.rbs @@ -48,6 +48,72 @@ class Binding # def eval: (string src, ?string filename, ?int lineno) -> untyped + # + # Returns `true` if the numbered parameter or "it" parameter exists. + # + # def foo + # [42].each do + # it + # binding.implicit_parameter_defined?(:it) #=> true + # binding.implicit_parameter_defined?(:_1) #=> false + # end + # + # { k: 42 }.each do + # _2 + # binding.implicit_parameter_defined?(:_1) #=> true + # binding.implicit_parameter_defined?(:_2) #=> true + # binding.implicit_parameter_defined?(:_3) #=> false + # binding.implicit_parameter_defined?(:it) #=> false + # end + # end + # + def implicit_parameter_defined?: (interned symbol) -> bool + + # + # Returns the value of the numbered parameter or "it" parameter. + # + # def foo + # [42].each do + # it + # binding.implicit_parameter_get(:it) #=> 42 + # end + # + # { k: 42 }.each do + # _2 + # binding.implicit_parameter_get(:_1) #=> :k + # binding.implicit_parameter_get(:_2) #=> 42 + # end + # end + # + def implicit_parameter_get: (interned symbol) -> untyped + + # + # Returns the names of numbered parameters and "it" parameter that are defined + # in the binding. + # + # def foo + # [42].each do + # it + # binding.implicit_parameters #=> [:it] + # end + # + # { k: 42 }.each do + # _2 + # binding.implicit_parameters #=> [:_1, :_2] + # end + # end + # + def implicit_parameters: () -> Array[Symbol] + # + # Returns the Encoding object that represents the encoding of the stream, or + # `nil` if the stream is in write mode and no encoding is specified. + # + # See [Encodings](rdoc-ref:File@Encodings). + # + def external_encoding: () -> Encoding? + # + # Returns the path associated with the IO, or `nil` if there is no path + # associated with the IO. It is not guaranteed that the path exists on the + # filesystem. + # + # $stdin.path # => "" + # + # File.open("testfile") {|f| f.path} # => "testfile" + # + alias to_path path + # # Returns `true` if the stream is associated with a terminal device (tty), # `false` otherwise: diff --git a/core/io/wait.rbs b/core/io/wait.rbs index e5a5e797d2..0f7efe1897 100644 --- a/core/io/wait.rbs +++ b/core/io/wait.rbs @@ -25,6 +25,17 @@ class IO type wait_mode = :read | :r | :readable | :write | :w | :writable | :read_write | :rw | :readable_writable + # + # Waits until IO is priority and returns a truthy value or a falsy value when + # times out. Priority data is sent and received using the Socket::MSG_OOB flag + # and is typically limited to streams. + # + def wait_priority: (?Time::_Timeout? timeout) -> boolish + # + # user time used in this process + # + attr_accessor utime: Float + + # + # system time used in this process + # + attr_accessor stime: Float + + # + # user time used in the child processes + # + attr_accessor cutime: Float + + # + # system time used in the child processes + # + attr_accessor cstime: Float end class Process::Waiter < Thread diff --git a/core/thread.rbs b/core/thread.rbs index 4ce6bc7a6b..234a380cd8 100644 --- a/core/thread.rbs +++ b/core/thread.rbs @@ -647,6 +647,19 @@ class Thread < Object # check $SAFE. def safe_level: () -> Integer + # + # Establishes *proc* on *thr* as the handler for tracing, or disables tracing if + # the parameter is `nil`. + # + # See Kernel#set_trace_func. + # + def set_trace_func: (Proc proc) -> Proc + | (nil) -> nil + #