From: "Eregon (Benoit Daloze) via ruby-core" Date: 2023-01-04T17:09:46+00:00 Subject: [ruby-core:111629] [Ruby master Feature#8088] Method#parameters (and friends) should provide useful information about core methods Issue #8088 has been updated by Eregon (Benoit Daloze). One way nowadays to do this is to use the `Primitive.foo` system and define the method in Ruby code. Another would be to add a new `rb_define_method` variant to which the parameters can be passed. That could then be used for all core methods. As a note, `rb_define_method` does give `parameters` if the passed arity is >= 0 (e.g., `Process.method(:gid=).parameters # => [[:req]]`), but not if the passed arity is -1, which is this issue. Having parameter names is valuable notably for `Method#inspect` e.g.: ``` > "".method(:gsub) CRuby: => # TruffleRuby: => # core/string.rb:844> ``` ---------------------------------------- Feature #8088: Method#parameters (and friends) should provide useful information about core methods https://bugs.ruby-lang.org/issues/8088#change-101001 * Author: headius (Charles Nutter) * Status: Open * Priority: Normal ---------------------------------------- I was wiring up #parameters to work for native methods today when I realized MRI doesn't give very good information about variable-arity native methods: ``` $ ruby2.0.0 -e "p ''.method(:gsub).to_proc.parameters" [[:rest]] $ jruby -e "p ''.method(:gsub).to_proc.parameters" [[:req], [:opt]] ``` I think MRI should present the same as JRuby here; gsub is obviously not a rest-arg method and you can't call it with less than 1 or more than 2 arguments. JRuby's presenting the right output here. I'm probably going to have to change JRuby to do the less-helpful version so we're compliant and tests pass, but I think the specification of #parameters should be that it presents the JRuby version about rather than the MRI version. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/