Whaaaaat?


#1

p [0…5].include? 0
false
p [0…5].member? 0
false

This is nuts. The world is flat, evidently.

Can someone explain this nonsense?

t.

Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

#2

Tom C. wrote:

Sorry - inadequate details: running ruby 1.8.7 (2008-08-11 patchlevel
72) [i486-linux]

t.

Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

#3

On Tue, May 12, 2009 at 4:39 PM, Tom C. removed_email_address@domain.invalid wrote:

p [0…5].include? 0
false
p [0…5].member? 0
false

This is nuts. The world is flat, evidently.

Nope.

Can someone explain this nonsense?

Yep. You’ve got an array with a single member… the range 0…5.

I think what you meant is:

(0…5).include? 0
=> true

:slight_smile:

Ben


#4

On Tue, May 12, 2009 at 5:39 PM, Tom C. removed_email_address@domain.invalid wrote:

p [0…5].include? 0
false
p [0…5].member? 0
false

This is nuts. The world is flat, evidently.

Can someone explain this nonsense?

[0…5] is an array with a single element, a Range object representing
the range from 0 to 5.

(0…5).to_a gives you [0,1,2,3,4,5] which is probably what you assumed
you got with [0…5]

(0…5).include?(0) will work, as well, because ranges support the
include? method.

Kirk H.


#5

From: “Tom C.” removed_email_address@domain.invalid

p [0…5].include? 0
false
p [0…5].member? 0
false

This is nuts. The world is flat, evidently.

Can someone explain this nonsense?

Same reason as this:

[“hello world”].include? “hell”
=> false

We’re asking whether the array contains a particular
object.

Regards,

bill


#6

Ben B. wrote:

Nope.
=> true

:slight_smile:

Ben

Well, nuts.

This clarifies it a bit:

irb(main):009:0> (1…10).class
=> Range
irb(main):010:0> [1…10].class
=> Array
irb(main):011:0>

Why can’t ruby just do what I mean, rather than what I say? Is that
asking too much? (heh heh)

Thanks for the clarifications. This list has not equal for speedy
answers (usually).

t.

Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

#7

Kirk H. wrote:

Kirk H.

Thanks, Kirk. That’s the best answer yet. Very helpful.

t.

Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

#8

On Wed, May 13, 2009 at 1:57 AM, Tom C. removed_email_address@domain.invalid wrote:

Why can’t ruby just do what I mean, rather than what I say? Is that asking
too much? (heh heh)
But it does, I am sure you just forgot the *, right?
[*0…5].include? 42
–> false
Cheers
Robert


#9

Robert D. wrote:

Robert,

Interesting, but obscure. I just did a quick dig into Thomas (Pickaxe,
3rd ed.), to try to figure out what [*1…5] does, and I still don’t get
it. Can you explain?

t.

Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

#10

On Wed, May 13, 2009 at 4:02 AM, Todd B. removed_email_address@domain.invalid
wrote:

that nomenclature (much like getting rid of #inject; if so, goodbye
Ruby for me).
I do not believe I have ever heard of that intention, if they get rid
of *0…3 than there is nothing one can do, if they get rid of inject
we will just reimplement it :wink:
Robert


Si tu veux construire un bateau …
Ne rassemble pas des hommes pour aller chercher du bois, préparer des
outils, répartir les tâches, alléger le travail… mais enseigne aux
gens la nostalgie de l’infini de la mer.

If you want to build a ship, don’t herd people together to collect
wood and don’t assign them tasks and work, but rather teach them to
long for the endless immensity of the sea.


#11

On Tue, May 12, 2009 at 8:34 PM, Tom C. removed_email_address@domain.invalid wrote:

But it does, I am sure you just forgot the *, right?
Interesting, but obscure. I just did a quick dig into Thomas (Pickaxe, 3rd
ed.), to try to figure out what [*1…5] does, and I still don’t get it. Can
you explain?

The"pre-appending" (yes I’m aware that’s not a word or proper
conjuction) star flattens arrays/ranges. Well, not exactly; it
allows you to use a “list” of things. Some people avoid it because of
a supposed performance issue. Pick your battle, I guess.

It happens to be useful to me. I really hope they don’t get rid of
that nomenclature (much like getting rid of #inject; if so, goodbye
Ruby for me).

Todd


#12

On Wed, May 13, 2009 at 11:02:45AM +0900, Todd B. wrote:

The"pre-appending" (yes I’m aware that’s not a word or proper
conjuction) star flattens arrays/ranges. Well, not exactly; it

I’m pretty sure the word you want is either “prefixing” or, if you like
the hypercorrect neologism, “prepending”.


#13

Adam G. wrote:

Hrm. I had always thought of ‘prepend’ as a commonplace, dictionary
word, and was about to point out that it was such, until I accidentally
looked it. Neologismtastic!

Actually, this is all unnecessary. In linguistics, for eons, we have
spoken of prefix and suffix usage, So, this is a prefix asterisk, as in
“…the meaning of this prefix asterisk is blah blah…”. That says it
just fine, with no new language. Travel light.

t.

Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

#14

Chad P. wrote:

On Wed, May 13, 2009 at 11:02:45AM +0900, Todd B. wrote:

The"pre-appending" (yes I’m aware that’s not a word or proper
conjuction) star flattens arrays/ranges. Well, not exactly; it

I’m pretty sure the word you want is either “prefixing” or, if you like
the hypercorrect neologism, “prepending”.

Hrm. I had always thought of ‘prepend’ as a commonplace, dictionary
word, and was about to point out that it was such, until I accidentally
looked it. Neologismtastic!


#15

Todd B. wrote:

It happens to be useful to me. I really hope they don’t get rid of
that nomenclature (much like getting rid of #inject; if so, goodbye
Ruby for me).

I never heard any proposal to get rid of Enumberable#inject, and I don’t
think it’s something you need to worry about. Ruby 1.9 has been adding
hundreds of new methods, not taking them away.


#16

On 2009-05-14, Jeff M. removed_email_address@domain.invalid wrote:

1.9.1 adds Enumerable#reduce as synonym (which makes more sense to
me) and still retains inject

Is one of #reduce or #inject deprecated in 1.9.1?

Regards,

Jeremy H.


#17

Brian C. wrote:

Todd B. wrote:

It happens to be useful to me. I really hope they don’t get rid of
that nomenclature (much like getting rid of #inject; if so, goodbye
Ruby for me).

I never heard any proposal to get rid of Enumberable#inject, and I don’t
think it’s something you need to worry about. Ruby 1.9 has been adding
hundreds of new methods, not taking them away.

1.9.1 adds Enumerable#reduce as synonym (which makes more sense to me)
and
still retains inject


#18

On Fri, May 15, 2009 at 7:25 AM, Jeremy H. removed_email_address@domain.invalid
wrote:

On 2009-05-14, Jeff M. removed_email_address@domain.invalid wrote:

1.9.1 adds Enumerable#reduce as synonym (which makes more sense to
me) and still retains inject

Is one of #reduce or #inject deprecated in 1.9.1?

Don’t think so.

Actually IMHO which makes more sense is situational. To me reduce
makes sense when the optional initial argument is not used, and inject
makes more sense when it is:

collection.reduce {|memo, element| …}
vs
collection.inject(initial_value) {|memo, element| …}

Several of the Enumerable method names were pretty obviously inspired
by the Smalltalk collection hierarcy, select, detect, reject, and
inject among them. The Smalltalk method is inject:info: which makes
the meaning of inject a bit clearer, in Smalltalk you would write the
second example as:

collection inject: initialValue into: [memo, element| …]

You are injecting the initialValue into the sequence given to the block.

And there are other instances of long-standing aliases like find for
detect.

Personally I think it’s good to have such synonyms, they make it
easier to be express subtleties just as they do for authors in natural
languages.


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale


#19

Rick DeNatale wrote:

On Fri, May 15, 2009 at 7:25 AM, Jeremy H. removed_email_address@domain.invalid wrote:

On 2009-05-14, Jeff M. removed_email_address@domain.invalid wrote:

1.9.1 adds Enumerable#reduce as synonym (which makes more sense to
me) and still retains inject
Is one of #reduce or #inject deprecated in 1.9.1?

Don’t think so.

Actually IMHO which makes more sense is situational.

Really? I never heard of “inject” in any other language. It was always
“reduce” to me. I got the impression that “inject” was just a cutesy
way of making the method name similar to detect, select, collect, and
reject.


#20

On Fri, May 15, 2009 at 2:51 PM, Rick DeNatale removed_email_address@domain.invalid
wrote:
nt| …}

Personally I think it’s good to have such synonyms, they make it
easier to be express subtleties just as they do for authors in natural
languages.
In my humble opinion I believe that having different words meaning the
same thing is not bad. It enables a certain ease to adapt our programs
slightly accordingly to slightly different cases. This is exactly what
they do for people expressing themselves in human idioms.

I guess that was what you meant, though I apologize for a certain lack
of subtlety.
:wink:
R.