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

Possibly clearer way of getting rid of ` and " #4843

Merged
merged 2 commits into from
Mar 28, 2012
Merged

Possibly clearer way of getting rid of ` and " #4843

merged 2 commits into from
Mar 28, 2012

Conversation

seamusabshere
Copy link
Contributor

hi,

You may find String#tr clearer than String#gsub in this case (YMMV)

Incidentally it's also faster...
>> a = 'hello "idworld'; Benchmark.realtime { 500_000.times { a.tr('"', "") } }
=> 0.7388770580291748
>> a = 'hello "idworld'; Benchmark.realtime { 500_000.times { a.gsub(/["]/, "") } }
=> 1.7843739986419678

Best,
Seamus

Incidentally it's also faster...
>> a = 'hello "id` world'; Benchmark.realtime { 500_000.times { a.tr('`"', "") } }
=> 0.7388770580291748 
>> a = 'hello "id` world'; Benchmark.realtime { 500_000.times { a.gsub(/[`"]/, "") } }
=> 1.7843739986419678
@jurriaan
Copy link
Contributor

What about String#delete?

>>  a = 'hello "id` world'; Benchmark.realtime { 500_000.times { a.delete('`"') } }
=> 0.683949
>>  a = 'hello "id` world'; Benchmark.realtime { 500_000.times { a.tr('`"', "") } }
=> 0.782426

@seamusabshere
Copy link
Contributor Author

RAILS IS GONNA BE SO FAST :) I love it.

@jurriaan
Copy link
Contributor

Haha! I hope 4.0 will be a lot faster :)

@fxn
Copy link
Member

fxn commented Mar 28, 2012

Better, thanks!

fxn added a commit that referenced this pull request Mar 28, 2012
Possibly clearer way of getting rid of ` and "
@fxn fxn merged commit bbd2cae into rails:master Mar 28, 2012
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

3 participants