The evils of 0.each


#1

Why doesn’t 0 (Fixnum) support .each ?
1 does, so does 2, 20, 200, and so on.
Why not 0? Why doesn’t 0.each simply do something 0 times?

NYARGH!


#2

Lady Michelle B. wrote:

Why doesn’t 0 (Fixnum) support .each ?
1 does, so does 2, 20, 200, and so on.
Why not 0? Why doesn’t 0.each simply do something 0 times?

NYARGH!

Probably a bug.


#3

Hi,

At Tue, 22 Nov 2005 17:07:25 +0900,
Lady Michelle B. wrote in [ruby-talk:166943]:

Why doesn’t 0 (Fixnum) support .each ?

Because Fixnum doesn’t have the method `each’.

1 does, so does 2, 20, 200, and so on.

All of them don’t.


#4

In article removed_email_address@domain.invalid, Lady Michelle B. wrote:

Why doesn’t 0 (Fixnum) support .each ?
1 does, so does 2, 20, 200, and so on.
Why not 0? Why doesn’t 0.each simply do something 0 times?

1#each doesn’t exist either.

You’re probably thinking of #times, which is defined for 0, 1, 2, …


#5

Why doesn’t 0 (Fixnum) support .each ?
1 does, so does 2, 20, 200, and so on.

They don’t, because they’re single items, not lists, sets or something.

Why not 0? Why doesn’t 0.each simply do something 0 times?

Because 0.times { } does that.
alternatively, Range#each works.