--0016364ee4e2a5762f049d24a1b6
Content-Type: text/plain; charset=ISO-8859-1

Good Afternoon,

On Fri, Feb 25, 2011 at 4:12 PM, 7stud -- <bbxx789_05ss / yahoo.com> wrote:

> Ok, the following code exhibits the problem I was trying to demonstrate:
>
> class Roulette
>  def method_missing(name, *args)
>    person  ame.to_s.capitalize
>
>    3.times do
>      number  and(10) + 1
>      puts "#{number}..."
>    end
>
>    #puts "#{person} got a #{number}"
>
>  end
> end
>
> Roulette.new.xxx
>
> If I uncomment the commented line, I get an infinite loop.  Why?  I'm
> pretty sure that is a local variable assignment v. setter problem.
>
>
It's not a problem - the issue is that number is scoped only to the 3.times
do block. That means that by the time you get to the puts, number is already
out of scope. Thus Ruby looks for the next alternative which is a instance
method by the name of number - not finding one it ends up back at
method_missing and thus the loop of death ensues.

Try this instead

class Roulette
 def method_missing(name, *args)
   person  ame.to_s.capitalize

   number  il #you now have "number" scoped at the method level instead of
the block level

   3.times do
     number  and(10) + 1
     puts "#{number}..."
   end

   puts "#{person} got a #{number}"

 end
end

Roulette.new.xxx


John



> --
> Posted via http://www.ruby-forum.com/.
>
>

--0016364ee4e2a5762f049d24a1b6--