This comes up every now and again, and lots of frameworks implement their own versions. I'm thinking of submitting an RCR for something functionally equivalent to the following to be incorporated into the base library:
class String
def starts?(aString)
index(aString) == 0
end
def ends?(aString)
rindex(aString) == length - aString.length
end
end
Of course, the real implementation would have much better performance. The advantage of including something like this is that these common functions can be made both high-performance and readable.
In message "Re: String starts? and ends? methods" on Wed, 27 Sep 2006 20:53:54 +0900, dblack@wobblini.net writes:
It's not that I didn't believe you It just seems a bit unusual,
in terms of the general Ruby practice.
Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?
Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?
matz.
+1 for changing to start_with? end_with?
Consistency in naming is a big plus for ruby (and minus for PHP).
Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?
My vote is also for naming them start_with? and end_with? because of consistency and better looks :).
In message "Re: String starts? and ends? methods" > on Wed, 27 Sep 2006 20:53:54 +0900, dblack@wobblini.net writes:
>It's not that I didn't believe you It just seems a bit unusual,
>in terms of the general Ruby practice.
Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?
Yes: add the underscores. Otherwise we'll have those exceptions "for
historical reasons" -- in this case the history of Python!
Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?
My English-fu has me prefer starts_with? to start_with?, but general Ruby convention seems to be not to conjugate the verbs, so I'll just vote what everybody else is voting.
In message "Re: String starts? and ends? methods" on Wed, 27 Sep 2006 21:29:09 +0900, dblack@wobblini.net writes:
Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?
Yes: add the underscores. Otherwise we'll have those exceptions "for
historical reasons" -- in this case the history of Python!
On Sep 27, 2006, at 7:19 AM, Rimantas Liubertas wrote:
Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?
Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?
Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?
My English-fu has me prefer starts_with? to start_with?, but general Ruby convention seems to be not to conjugate the verbs, so I'll just vote what everybody else is voting.
It's a little inconsistent:
obj.respond_to? # second person
obj.is_a? # third person
But I think second person is the most common. Or maybe are_a? just
sounded too weird
Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?
matz.
+1 for changing to start_with? end_with?
Consistency in naming is a big plus for ruby (and minus for PHP).