Bug #9041

Please add alias "starts_with?" to class String

Added by Robert A. Heiler 6 months ago. Updated 6 months ago.

[ruby-core:57953]
Status:Rejected
Priority:Low
Assignee:-
Category:-
Target version:-
ruby -v:all Backport:1.9.3: UNKNOWN, 2.0.0: UNKNOWN

Description

Hi.

We can do these:

FileUtils.touch 'test' # => ["test"]
File.exist? 'test' # => true
File.exists? 'test' # => true
'test'.start_with? 't' # => true

However, we can not use .starts_with?

'test'.startswith? 't' NoMethodError: undefined method `startswith?' for "test":String

I propose that, for proper english, and consistency with the duality of File.exist? and File.exists?
to also add alias starts_with? so that we can use proper english.

The proper english way to query such a question would be:

"Does the word abc start with an a?"
and in short form as factual, affirmative statement:
"abc starts with a."
whereas this here would be not proper english:
"abc start with a."

Associated revisions

Revision 43377
Added by Nobuyoshi Nakada 6 months ago

file.c: warn File.exists?

  • file.c (rbfileexists_p): warn deprecated name. [Bug #9041]

Revision 43380
Added by Nobuyoshi Nakada 6 months ago

dir.c: warn Dir.exists?

  • dir.c (rbdirexists_p): warn deprecated name. [Bug #9041]

History

#1 Updated by Robert A. Heiler 6 months ago

I forgot to add - I was told that the reason for this is that we should use the 2nd person, as in:

"Word, do you start with character a?"

This is fine for me, however had in that case, either File.exist? or File.exists? should be removed.

#2 Updated by Yui NARUSE 6 months ago

  • Status changed from Open to Rejected

shevegen (markus heiler) wrote:

I forgot to add - I was told that the reason for this is that we should use the 2nd person, as in:

"Word, do you start with character a?"

This is fine for me, however had in that case, either File.exist? or File.exists? should be removed.

Yes, File.exists? should be removed for consistency.
But the removing breaks compatibility, and its benefit is less than its cost to fix.
So we keep it.

we sometimes remove old API to add new better API.

but this is not the case.

#3 Updated by Boris Stitnicky 6 months ago

@naruse: Thanks for responding and explaining. Yet, 3rd person forms
#startswith?, #endswith?, #exists? etc. seem to be preferred in other
computer langugages.

@shevegen: As you probably know, ActiveSupport provides those aliases:

require 'activesupport/coreext/string/startsendswith'

Also available in: Atom PDF