fastruby / fast-ruby

:dash: Writing Fast Ruby :heart_eyes: -- Collect Common Ruby idioms.
https://github.com/fastruby/fast-ruby
5.67k stars 376 forks source link

ends_with? advice incorrect #53

Closed willbryant closed 1 year ago

willbryant commented 9 years ago

The following text in the regex vs. starts_with?/ends_with? bit (which has a ! next to it) is flatly incorrect:

You can combine start_with? and end_with? to replace error.path =~ /^#{path}(\.rb)?$/ to this 
error.path.start_with?(path) && error.path.end_with?('.rb', '')
—— @igas rails/rails#17316

error.path.end_with?('.rb', ‘’) is equivalent to error.path.end_with?(‘’) which always returns true and is therefore useless. In addition, the combination of starts_with? and ends_with? does not test that nothing else is between path and the end except .rb like the regexp does.

(Notably the cited PR was rejected and it was noted that some of the other suggested replacements were wrong.)

This paragraph should be just deleted, I think.