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.
>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.
matz.
(a newbie speaking)
but what about puralization?
we gonna have "string".respond_to?() but "string".starts_with?()
further: could there be need for starts_with!() and ends_with!() ? or is it bollox?
···
In message "Re: String starts? and ends? methods" > on Wed, 27 Sep 2006 22:40:29 +0900, dblack@wobblini.net writes:
further: could there be need for starts_with!() and ends_with!() ? or is it bollox?
What functionality are you envisioning these methods would have?
James Edward Gray II
maybe without parameters exchanging the first or last char with a string/char, with parameters (unsigned integer) exchanging the first x chars / last x chars
i dont know if it is that useful, it just popped to my mind seeing a method? what would method! do.
newbish regards
Jonas
···
On Sep 27, 2006, at 9:05 AM, Jonas Hartmann wrote:
"Starts" is not the plural form of "start", it's just a conjugation.
I start/you start/he, she, it starts/we start/you start/they start
You would never say in English "a start with b", you say "a starts with b", even when both a and b are singular. I would argue that it should be the same in Ruby, and the method name should be "starts_with?"
Pete Yandell
···
On 28/09/2006, at 12:33 AM, Yukihiro Matsumoto wrote:
In message "Re: String starts? and ends? methods" > on Wed, 27 Sep 2006 23:05:44 +0900, Jonas Hartmann <Mail@Jonas- > Hartmann.com> writes:
>but what about puralization?
As a convention, Ruby method names use plain verb with singular form,
with several exceptions, e.g. is_a? etc. So we use start_with? not
starts_with?
I too find that the second, instead of third person form for
predicates to we just a tad wierd.
But it is what it is.
Or maybe that should be (as a predicate).
are you what you are?
And let me say that Matz' English is much better than my Japanese.
···
On 9/27/06, Michael Glaesemann <grzm@seespotcode.net> wrote:
On Sep 28, 2006, at 9:11 , dblack@wobblini.net wrote:
> Hi --
>
> On Thu, 28 Sep 2006, Hal Fulton wrote:
>
>> dblack@wobblini.net wrote:
>>> 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
>>
>> As the other cases are using the infinitive form,
>> the latter would actually be #be_a?
>
> I think it's the second person -- at least, I seem to remember Matz
> explaining it that way. So you're asking the object: [do you]
> respond_to?...
On 28/09/2006, at 12:33 AM, Yukihiro Matsumoto wrote:
In message "Re: String starts? and ends? methods" >> on Wed, 27 Sep 2006 23:05:44 +0900, Jonas Hartmann >> <Mail@Jonas-Hartmann.com> writes:
>but what about puralization?
As a convention, Ruby method names use plain verb with singular form,
with several exceptions, e.g. is_a? etc. So we use start_with? not
starts_with?
"Starts" is not the plural form of "start", it's just a conjugation.
I start/you start/he, she, it starts/we start/you start/they start
You would never say in English "a start with b", you say "a starts with b", even when both a and b are singular. I would argue that it should be the same in Ruby, and the method name should be "starts_with?"
I believe the rationale is that it's in the second person: do you
start with ... ? I realize Matz mentioned singular vs. plural, but I
think that was just shorthand for with/without an 's'. In the past,
if I remember correctly, he's talked about it as a function of person.
You would never say in English "a start with b", you say "a starts
with b", even when both a and b are singular. I would argue that it
should be the same in Ruby, and the method name should be "starts_with?"
Ruby: foo.start_with? 'snark'
English: does foo start with 'snark'?
I could possibly see your point for something like start_with! (should it
ever exist), but I think the question form sounds correct.
For non-predicate methods, the second person makes sense. Take String.squeeze for example...that's really about you (the second person) squeezing the string.
For predicate methods it still seems odd. In the "starts with" case, it's not you doing the starting; it's the string (third person) doing the starting.
The said, the convention in Ruby does seem to be second person no matter what. Witness the "include?" method for example (which has always felt a little odd to me too.)
Pete Yandell
···
On 28/09/2006, at 10:42 AM, dblack@wobblini.net wrote:
You would never say in English "a start with b", you say "a starts with b", even when both a and b are singular. I would argue that it should be the same in Ruby, and the method name should be "starts_with?"
I believe the rationale is that it's in the second person: do you
start with ... ? I realize Matz mentioned singular vs. plural, but I
think that was just shorthand for with/without an 's'. In the past,
if I remember correctly, he's talked about it as a function of person.