[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Newbie question
From:       "Felix Windt" <fwmailinglists () gmail ! com>
Date:       2007-11-01 21:42:23
Message-ID: 0c1a01c81ccf$554fa4b0$3338000a () tehgeek
[Download RAW message or body]


> -----Original Message-----
> From: list-bounce@example.com 
> [mailto:list-bounce@example.com] On Behalf Of Dale Smith
> Sent: Thursday, November 01, 2007 2:29 PM
> To: ruby-talk ML
> Subject: Newbie question
> 
> First thing's first - if there's a newbie forum where a question like
> this would be more appropriate, somebody please point it out to me.
> 
> I'm new to Ruby, and I'm trying to pick it up specifically for Watir
> testing.  I've installed Ruby from the One Click Installer for Windows
> three times now, but I keep running into the same issue, so at this
> point I figure it must be operator error.  The versions I've 
> used so far
> are:
> 
> ruby186-25.exe
> ruby185-24.exe
> ruby185-22.exe
> 
> 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?
> -- 
> Posted via http://www.ruby-forum.com/.
> 

Because numbers (Fixnums) do not implement the each method as numbers are
not collections - ranges do, though. To call the method on the range instead
of the last Fixnum that forms the range, enclose it in parantheses:

$ 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> (1..10).each {|x| puts x}
1
2
3
4
5
6
7
8
9
10
=> 1..10

HTH,

Felix

["smime.p7s" (application/x-pkcs7-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic