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.
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).
In message “Re: String starts? and ends? methods”
on Wed, 27 Sep 2006 20:53:54 +0900, [email protected] 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?
My vote is also for naming them start_with? and end_with? because of
consistency and better looks :).
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!
In message “Re: String starts? and ends? methods”
on Wed, 27 Sep 2006 21:29:09 +0900, [email protected] 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!
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.
to be honest, i don’t really think this is that useful.
what wrong with
string=~/^start/
string=~/end$/
this seems to be self-explanatory enough.
For the Regexp-friendly users… In my opinion, a part of Ruby’s
coolness is that you have quite a lot of ways to say similar things,
which leaves you to chose the most readable for the code at hand (and
for your own eyes).
I don’t expect having another method for String will cause a huge
performance drop ;-)… And I definitely think some code will look
easier to read with that.
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
In message “Re: String starts? and ends? methods”
on Wed, 27 Sep 2006 22:40:29 +0900, [email protected] writes:
|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
Right. “is-a” is a too common phrase among object-oriented
programming. I wasn’t brave enough to rename it “be_a” or something
like it.