Forum: Ruby The evils of 0.each

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
michelle (Guest)
on 2005-11-22 10:10
(Received via mailing list)
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!
skaes (Guest)
on 2005-11-22 10:14
(Received via mailing list)
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.
timsuth (Guest)
on 2005-11-22 10:31
(Received via mailing list)
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, ...
nobuyoshi.nakada (Guest)
on 2005-11-22 10:35
(Received via mailing list)
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.
kero (Guest)
on 2005-11-22 10:51
(Received via mailing list)
>> 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.
This topic is locked and can not be replied to.