Project

General

Profile

Bug #22422 ยป integer_at_repro.rb

zevblut (Zev Blut), 10/09/2026 05:50 AM

 
# Compare MatchData#integer_at with $N&.to_i, which Feature #21932 says it is equivalent to.
[
["2024", 10], ["12abc", 10],
["foo", 10], ["", 10], ["T", 10], ["_1", 10], ["0x", 0],
].each do |capture, base|
m = /\A(.*)\z/.match(capture)
printf "%-8p base %-2d integer_at: %-5p $N&.to_i: %p\n", capture, base, m.integer_at(1, base), m[1]&.to_i(base)
end
m = /(a)|b/.match("b")
printf "%-17s integer_at: %-5p $N&.to_i: %p\n", "unmatched group", m.integer_at(1), m[1]&.to_i
    (1-1/1)