On 3/7/07, Brian Candler <B.Candler / pobox.com> wrote:
> On Wed, Mar 07, 2007 at 07:54:15PM +0900, 7stud 7stud wrote:
> > If I run the following code, I don't get any errors:
> >
> > class MegaGreeter
> >         attr_accessor :names
> >
> >         #constructor
> >         def initialize(names = "world")
> >                 @names = names
> >         end
> >
> >         #functions:
> >         def say_hi
> >                 if @names.nil?
> >                         puts "..."
> >                 elseif @names.respond_to?("each")
> >                         @names.each do |name|
> >                                 puts "Hello #{name}!"
> >                         end
> >                 else
> >                         puts "Hello #{@names}!"
> >                 end
> >         end
> > end
> > if __FILE__ == $0
> >         mg = MegaGreeter.new(["Sally", "Jane", "Bob"])
> >         mg.say_hi
> > end
>
> That's because you're not exercising the section under @names.nil?
>
> Try: mg = MegaGreeter.new(nil)
>
>
You spoiled it ;)
but this is a good way to explain it too...

-- 
We have not succeeded in answering all of our questions.
In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important things.
-Anonymous