From: "Eregon (Benoit Daloze) via ruby-core" Date: 2026-03-18T15:37:44+00:00 Subject: [ruby-core:125070] [Ruby Feature#21932] `MatchData#get_int` Issue #21932 has been updated by Eregon (Benoit Daloze). Thanks for the explanations. naruse (Yui NARUSE) wrote in #note-9: > In this use case, interpreting "0x" prefix is not useful It could be useful, but one could workaround that with `/0x(\h+)/` instead of `/(0x\h+)/`. Leading 0 (octal) is likely more dangerous than `0x` though (`Integer("011")` => `9`). > If this behavior is to_i, it is easy to explain the behavior. It wouldn't be hard to explain it's the same as `Integer($N, 10)`. > Distinguish with the group is not matched Yes, agreed returning `nil` for group not matched is good. > for empty string, it will returns 0. Could easily be handled as a special case but yeah not as simple as `Integer($N, 10)` then. Still fairly easy to explain/document. > if you want to reject non integers, you can write strict regexp pattern. This reason convinces me, it's not bulletproof but should be enough guarantee for most cases to not return 0 except for actual 0's in input. BTW, given the method name is `MatchData#integer_at(n)`, people might expect it uses `Integer()` as that's very similar to the method name. ---------------------------------------- Feature #21932: `MatchData#get_int` https://bugs.ruby-lang.org/issues/21932#change-116774 * Author: nobu (Nobuyoshi Nakada) * Status: Open ---------------------------------------- This is suggested by @akr today, `$~.get_int(1)` is equivalent to `$1.to_i` but does not create the intermediate string object. https://github.com/nobu/ruby/tree/match-get_int -- 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/lists/ruby-core.ml.ruby-lang.org/