From: 7stud -- Date: 2007-11-02T06:40:15+09:00 Subject: Re: Newbie question Dale Smith wrote: > Here's the issue I keep running into: > > C:\rubysandbox>irb > irb(main):001:0> 1..10.each { |x| puts x } > NoMethodError: undefined method 'each' for 10:Fixnum > from (irb):1 > irb(main):002:0> > > > Why do I keep getting a NoMethodError when I try to use the each() > method on a number? You aren't *trying* to use each on a number. A number looks like: 1 13.4 5 You are trying to use each on a Range, which looks like: 1..10 a..z Unfortunately, ruby thinks you are trying to use each on the number 10. To fix the problem, you need to put parentheses around the range: (1..10).each Personally I always type: 1..10.e and then remember I need the parentheses, which means using each() on a range requires too much typing. So, I try to do this instead: 10.times do |i| ... ... end -- Posted via http://www.ruby-forum.com/.