Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Regexp argument to String#byteindex #2182

Merged
merged 3 commits into from
Jul 4, 2024

Conversation

seven1m
Copy link
Member

@seven1m seven1m commented Jul 3, 2024

This will make it easier to add a regexp case.
Given a script like this:

    s = "foo"
    r = /foo/s.byteindex(r)

    puts "        s.object_id = #{s.object_id}"
    puts "$~.string.object_id = #{$~.string.object_id}"

    puts "        r.object_id = #{r.object_id}"
    puts "$~.regexp.object_id = #{$~.regexp.object_id}"

The results look like this:

            s.object_id = 60
    $~.string.object_id = 80
            r.object_id = 100
    $~.regexp.object_id = 100

So that means Ruby copies the string. I don't know what happens if the
string is frozen, but we can punt that until later.
@seven1m seven1m merged commit 63cec98 into master Jul 4, 2024
15 checks passed
@seven1m seven1m deleted the string-byteindex-regexp branch July 4, 2024 01:45
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.

1 participant