The evils of 0.each

  • Thread starter Lady Michelle Bhaal
  • Start date
L

Lady Michelle Bhaal

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!
 
S

Stefan Kaes

Lady said:
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.
 
T

Tim Sutherland

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, ...
 
N

nobuyoshi nakada

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.
 
K

Kero

Why doesn't 0 (Fixnum) support .each ?
They don't, because they're single items, not lists, sets or something.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top