Foo wrote: >Hi- > >I am new to ruby and I am reading the SAMS "Teach yourself Ruby in 21 >days" book. I've gotten to the part where the book discusses the >operating system and Ruby. I'm having trouble with an example in the >book and was hoping someone could help. The script is spinnertest.rb: > >#!/usr/bin/env ruby > >require 'spinner2' # Edit this line for different spinners > ># Our slow recursive Fibonacci function. >def fib(n) (n<=2) ? 1 : (fib(n-2)+fib(n-1)) end > >print "Please wait while I calculate a large Fibonacci number. " > >animation = Spinner.new >result = fib(28) >animation.stop > >puts >puts result > > >The class is called spinner2.rb: > >class Spinner > Baton = '\|/-' > def initilaize > > ^^^^^^ this should be def initialize > STDOUT.flush > @child = IO.popen('-', 'w+') > if @child.nil? > rotation = 0 > until select([$stdin], nil, nil, 0.2) > STDERR.printf "%c\b", Baton[(rotation+=1) &3] > end > gets #read the 'stop' message > STDERR.printf " \b" # erase the last Baton character > exit! > end > end > > def stop > @child.puts("stop yer rotation") # message content is unimportant > @child.close > end >end > >When I run spinnertest.rb I get a blank screen for awhile, then after >the calculation is complete I get the following: > >../spinner2.rb:18:in `stop': private method `puts' called for >nil:NilClass (NoMethodError) > from ./spinnertest.rb:12 >Please wait while I calculate a large Fibonacci number. > >I am guessing that ruby is having trouble with 'puts' being used this >way, but I do not understand why, nor, how to fix it. Can someone >please help me with this item? > >:)Thanks. > >SA > > > >