String starts? and ends? methods

There seem to be two kinds of predicates – those which ask about what
an object is like, and those which ask about what it is; e.g:

obj.respond_to? :m # does obj respond to :m?
obj.include? item # does obj include item?
obj.all? { cond } # do all members of obj meet cond?

obj.is_a? Class # is obj a Class?
obj.instance_of? Class # is obj an instance of Class?
obj.nil? # is obj nil?

#start_with? seems to fit into the first category, and to be consistant
with the grammar of that category:

obj.start_with? ‘string’ # does obj start with ‘string’?

Regards,
Jordan

On 9/28/06, MonkeeSage [email protected] wrote:

#start_with? seems to fit into the first category, and to be consistant
with the grammar of that category:

obj.start_with? ‘string’ # does obj start with ‘string’?

Not that it’s going to change, and it’s all water long under the bridge,
but…

Those predicates are usually part of a larger expression.

We wouldn’t say

Give me my nine-iron, if does my bag have my nine-iron.

In situ which of these sounds better to the English speaker?

do_something if a.start_with?(‘foo’)
do_something if a.respond_to?(:fred)
do_something if a.include?(:joe)

or

do_something if a.starts_with?(‘foo’)
do_something if a.responds_to?(:fred)
do_something if a.includes?(:joe)

Try it with other statements and modifiers like unless, while, until
etc.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

There seem to be two kinds of predicates – those which ask about what
an object is like, and those which ask about what it is; e.g:

obj.respond_to? :m # does obj respond to :m?
obj.include? item # does obj include item?
obj.all? { cond } # do all members of obj meet cond?

obj.is_a? Class # is obj a Class?
obj.instance_of? Class # is obj an instance of Class?
obj.nil? # is obj nil?

#start_with? seems to fit into the first category, and to be consistant
with the grammar of that category:

obj.start_with? ‘string’ # does obj start with ‘string’?

Regards,
Jordan

On 9/28/06, Hal F. [email protected] wrote:

Marcelo A. wrote:

usually uses the infinitive…)
Well, according to
Infinitive - Wikipedia
most modern grammarians don’t consider the imperative and present
subjunctive to be uses of the bare infinitive.

I think that the older view that they are the same might actually an
example of the trap of thinking that English grammar is the same as
or very similar to Latin grammar.

A good example of this is the old-fashioned prohibition against
splitting an infinitive. “To go boldly where no one has gone before,”
instead of “To boldly go where no one has gone before.” This came
from the fact that in Latin, and some of it’s descendants, the
infinitive was/a single word, so splitting an infinitive is
impossible, whereas in English the use of the full infinitive (to x)
is much more common than the bare infinitive, and splitting an
infinitive seems to be both commonly used and often sounds and flows
better. The prohibition, like not ending a sentence with a
preposition, is “something, up with which I will not put.”

As an analogy to what is commonly said here:

Ruby is not Java
Python is not Ruby
Ruby is not C++
English is not Latin
Le francais, n'est pas l'anglais.

Not that this is a big thing with me, I just find it interesting.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

^ Sorry to double-post, google mail was acting up.

On 9/28/06, Rick DeNatale [email protected] wrote:

Not that it’s going to change, and it’s all water long under the bridge, but…

Those predicates are usually part of a larger expression.

We wouldn’t say

Give me my nine-iron, if does my bag have my nine-iron.

…if it’s true that my bag does have my nine-iron

“has”, “starts” and so on eliminate the ‘be’ verb in favor of
complicating (by conjugating) the original verb. Having lived as an
English speaker and studied other languages that both conjugate and do
not conjugate, I have to say I strongly prefer the latter. And before
you say it, yes we have to conjugate the verb ‘to be’ above, but
that’s all we’d ever have to conjugate.

On 9/28/06, Pete Y. [email protected] wrote:

because I’m a Ruby newbie AND a non-native english speaker, but I
that non-native English speakers tend to know way more about grammar
than native English speakers like me. :slight_smile:

by force of nature, we have to study it to learn,
OTOH method names ending in “?” are hardly imparative forms [ I guess
that
was what Pete was refering to]

but why not making things easier and being more tolerant :slight_smile:

in the beginning I had to correct #responds_to? with #respond_to? what
seemed a zillion times (I should have aliased it in Object anyway, but
when
I knew how to do that I did not need it anymore :wink:
.
Aliases are commonly used in Ruby Array#collect, Array#map etc

why not having them for flected forms
String#starts_with? <=> String#start_with?
personally I like String#prefix? and String#suffix? too, shorter and
very
precise.

Object#responds_to? <=> …

I guess it will make life easier for Newbies and let everybody use it’s
personal feeling for what sounds better.

Cheers
Rober

Pete Y.


Deux choses sont infinies : l’univers et la bêtise humaine ; en ce qui
concerne l’univers, je n’en ai pas acquis la certitude absolue.

  • Albert Einstein

On 28 sept. 06, at 02:04, Hal F. wrote:

Those who want an English mnemonic can mentally insert
the word “does”:

str.start_with?(foo)  #  Does str start with foo ?

Or since the semantic of a method call actually corresponds to
sending a message (in that case a question) to an object:

   str.start_with?(foo) # Hey, string! Yeah, you there! Do you

start with foo?

:slight_smile:

Rick DeNatale wrote:

or

do_something if a.starts_with?(‘foo’)
do_something if a.responds_to?(:fred)
do_something if a.includes?(:joe)

This is probably a consequence of Matz being Japanese. We should be
grateful that he used English at
all!

On 9/28/06, Robert D. [email protected] wrote:

personal feeling for what sounds better.
That was my first thought.

On the other hand it could lead to ethnic enclaves in the ruby
community based on different dialects or accents.

CockneyRuby, SouthernDrawlRuby, LanguedocRuby, SchweizerdeutschRuby?

I used to tell people I met in Zurich that I felt like I was Swiss
since my mother’s parents were German, my father’s parents were
Italian, et je parle un peu de francais!


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On 9/29/06, Rick DeNatale [email protected] wrote:

CockneyRuby, SouthernDrawlRuby, LanguedocRuby, SchweizerdeutschRuby?

I used to tell people I met in Zurich that I felt like I was Swiss
since my mother’s parents were German, my father’s parents were
Italian, et je parle un peu de francais!


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

And what a beautiful name “DeNatale” is, Napoletano?

Babylon 5 :wink:
Robert


Deux choses sont infinies : l’univers et la bêtise humaine ; en ce qui
concerne l’univers, je n’en ai pas acquis la certitude absolue.

  • Albert Einstein

On 9/29/06, George [email protected] wrote:

Rick DeNatale wrote:

We wouldn’t say

Give me my nine-iron, if does my bag have my nine-iron.

In your current form I’d rather use a eight!

In situ which of these sounds better to the English speaker?

do_something if a.start_with?(‘foo’)
do_something if a.respond_to?(:fred)

I always found that one troubeling, but I do not consider that a
problem,
especially in the light that Matz is Japanese as you pointed ou below,
we
too often forget that.

all!

Amen, and as I said before, after 20 years of Ruby programming I just
mastered method_alias, or was it alias_method (long live ri ;).
Robert


Deux choses sont infinies : l’univers et la bêtise humaine ; en ce qui
concerne l’univers, je n’en ai pas acquis la certitude absolue.

  • Albert Einstein