Project

General

Profile

Actions

Feature #21932

open

`MatchData#get_int`

Feature #21932: `MatchData#get_int`

Added by nobu (Nobuyoshi Nakada) 4 days ago. Updated about 23 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:124905]

Description

This is suggested by @akr (Akira Tanaka) 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


Related issues 1 (1 open0 closed)

Related to Ruby - Feature #21943: Add StringScanner#get_int to extract capture group as Integer without intermediate StringOpenActions

Updated by nobu (Nobuyoshi Nakada) 4 days ago Actions #1

  • Description updated (diff)

Updated by zenspider (Ryan Davis) 3 days ago Actions #2 [ruby-core:124916]

Tried to add a comment to your commit but github is being very sketchy today.

In the method comment on the impl side, you have examples for parsing a date... but IDGI... 1/2/10 are supposed to be the base arg, right? Base 1?

Updated by nobu (Nobuyoshi Nakada) 3 days ago Actions #3 [ruby-core:124917]

zenspider (Ryan Davis) wrote in #note-2:

In the method comment on the impl side, you have examples for parsing a date... but IDGI... 1/2/10 are supposed to be the base arg, right? Base 1?

I can't get from where the example comes.

Do you want to mean something like this?

/\d+/.match("1/2/10").get_int(0)    # => 1
/\d+/.match("1/2/10").get_int(0, 1) # invalid radix 1 (ArgumentError)

Updated by Eregon (Benoit Daloze) about 14 hours ago Actions #5

  • Related to Feature #21943: Add StringScanner#get_int to extract capture group as Integer without intermediate String added
Actions

Also available in: PDF Atom