Skip to content

Add missing core singleton methods - #3218

Open
zonuexe wants to merge 1 commit into
ruby:masterfrom
zonuexe:add-missing-singleton-methods
Open

zonuexe wants to merge 1 commit into
ruby:masterfrom
zonuexe:add-missing-singleton-methods

Conversation

@zonuexe

@zonuexe zonuexe commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds signatures for singleton methods that Ruby 4.0 defines and core/ lacks. I left out RubyVM internals and Process::Tms.[]. rbs annotate generated the doc comments from the v4.0.7 RDoc.

Ruby Method Change C function
Hash.ruby2_keywords_hash Added. Accepts only a Hash (Check_Type, no to_hash conversion) and returns an instance of the argument's class, subclasses included rb_hash_s_ruby2_keywords_hash
Hash.ruby2_keywords_hash? Added. Accepts only a Hash (Check_Type, no to_hash conversion) rb_hash_s_ruby2_keywords_hash_p
Kernel.set_trace_func Added as a global function set_trace_func
Kernel.trap Added as a global function. It shares its C function with Signal.trap, so it uses the same signature sig_trap
Process.last_status Added. Returns nil until the current thread has a child status proc_s_last_status
Process.setpgrp Added. Not tested, since calling it changes the test runner's process group proc_setpgrp
Process::Status.wait Added. Returns nil when flags includes WNOHANG and no child has exited (source). The call-seq omits this case rb_process_status_waitv
Process::Sys.getegid Added proc_getegid

The Process.setpgrp test runs in a forked child, so the test runner keeps its process group.

Comment thread test/stdlib/Process_test.rb Outdated
Comment on lines +19 to +40
def test_setpgrp
omit "fork/setpgrp is not available" unless Process.respond_to?(:fork) && Process.respond_to?(:setpgrp)

# Run in a child process so that the test runner's process group is not changed.
r, w = IO.pipe
pid = fork do
r.close
assert_send_type "() -> Integer",
Process, :setpgrp
exit!(true)
rescue Exception => e
w.write(e.full_message(highlight: false))
exit!(false)
end
w.close
message = r.read
_, status = Process.wait2(pid)
assert_predicate status, :success?, message
ensure
r&.close
end
end

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we need to go this far to check the type of Process.setpgrp.
Unstable tests are not welcome.

Add signatures for singleton methods that are defined in Ruby 4.0 but
were missing from core/:

- Hash.ruby2_keywords_hash, Hash.ruby2_keywords_hash?
- Kernel.set_trace_func, Kernel.trap
- Process.last_status, Process.setpgrp
- Process::Status.wait
- Process::Sys.getegid
@zonuexe
zonuexe force-pushed the add-missing-singleton-methods branch from 3ffddb2 to e36555b Compare October 11, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants