Hi,

I was just wondering: how do I react on a method-invocation with a 
nil-object instead of eg. String? How do I test it? And how can I assure 
that it is the right kind of object?

class AClass
  def a_method aString
     puts aString+aString
     puts aString.reverse
   end

end

an_object = AClass.new
an_object.a_method "hello"  # works
an_object.a_method          3#-> undefined method
an_object.a_method nil      #-> undefined method


Does Duck-Typing mean "ah, the programmer always knows, which kind of 
objects this method expects. Thus never an error will occur."? This 
seems very optimistic to me if not naiv. You cant just trust that the 
any programmer who uses your class knows what exactly is happening in 
your method and which type of object is required.

Thankful for any hint.

Regards,
Yochen

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