[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: Newbie question
From: Tim Hunter <TimHunter () nc ! rr ! com>
Date: 2007-11-01 21:40:46
Message-ID: 472A47D2.4040102 () nc ! rr ! com
[Download RAW message or body]
Dale Smith wrote:
> 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?
#each generally applies to collection of things, so you don't use it on
a single number. I think what you want is
(1..10).each {|x| puts x}
By surrounding the range 1..10 with parentheses you're telling Ruby that
you want the #each method for the range 1..10, not for the single number 10.
--
RMagick OS X Installer [http://rubyforge.org/projects/rmagick/]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618]
RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic