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

Implement String.new encoding optional argument #3583

Merged
merged 1 commit into from Jan 21, 2016

Conversation

tak1n
Copy link
Member

@tak1n tak1n commented Jan 21, 2016

Related to #3559

replace arg unless undefined.equal?(arg)
self.force_encoding(encoding) if encoding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this using force_encoding and not encode!?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not aware of encode! thats the only reason
Should I change it to use encode! ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After digging into mri's c code @yorickpeterse and me came to the conclusion to use force_encoding here.
MRI is using rb_enc_associate: https://github.com/ruby/ruby/blob/trunk/string.c#L1354
Which is also used in force_encoding: https://github.com/ruby/ruby/blob/trunk/string.c#L8671

tak1n added a commit that referenced this pull request Jan 21, 2016
Implement String.new encoding optional argument
@tak1n tak1n merged commit f5d9420 into master Jan 21, 2016
@tak1n tak1n deleted the implement_string_new_encoding branch January 21, 2016 14:38
@chuckremes chuckremes mentioned this pull request Jan 21, 2016
52 tasks
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.

None yet

2 participants