From: Jim Menard Date: 2002-01-31T12:25:07+09:00 Subject: Re: integer method question "r . h a r l o s" writes: > Hi, all. I'm just learning Ruby and already I've come across a situation > that I don't understand. > > In irb, if I type: > 2.upto(5) { |n| print n, "-" | } > > I expect to see: > 2-3-4-5- > > but instead I see: > 2-3-4-5-2 > > Why does the initial value get tacked onto the end? I'm running ruby > 1.6.6 on Red Hat 7.2, irb version 0.7.4. > > Thanks in advance for help/answers :-) You see the last "2" because after irb executes the code it prints the value of the resulting object, in this case "2". On the command line, type "ruby -e '2.upto(5) { |n| print n, "-" | }" and you will not see the final "2". Jim -- Jim Menard, jimm@io.com, http://www.io.com/~jimm/ "Indeed, an upsettingly large part of academia right now seems to be working on bringing Java into the 1980s... sigh." -- Avi Bryant