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.
C605452af20ce437a83a9012bb8d3d83?d=identicon&s=25 michelle (Guest)
on 2005-11-22 09: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!
E555e7c34196967444a47a96395a23ab?d=identicon&s=25 skaes (Guest)
on 2005-11-22 09:14
(Received via mailing list)
Lady Michelle Bhaal 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.
0c054cee68f9a50d18af7d7f1e526a15?d=identicon&s=25 timsuth (Guest)
on 2005-11-22 09:31
(Received via mailing list)
In article <4382D1B8.9010202@corax.com.au>, Lady Michelle Bhaal 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, ...
04a56914cc09f0858d3fca2bf4cbde34?d=identicon&s=25 nobuyoshi.nakada (Guest)
on 2005-11-22 09:35
(Received via mailing list)
Hi,

At Tue, 22 Nov 2005 17:07:25 +0900,
Lady Michelle Bhaal 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.
Dd54c22454b4e3c21cadf3bdb5192e28?d=identicon&s=25 kero (Guest)
on 2005-11-22 09: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.