On Fri, 14 Jan 2005, David A. Black wrote:

>> def silly_example(str.to_str, count.to_int)
>>  # str and count are converted like in the example above
>>  s = ""
>>  count.times { s << str }
>>  s
>> end
>
>  obj = Object.new
>  def obj.times; 10; end
>  str = silly_example("hello", obj)
>
> Here you have an object that responds to 'times', so it's capable of
> being treated in a duck-typing way by simply being sent the message
> 'times' -- but if you intercept the object and do a to_int on it,
> there's trouble.
>
> (Of course you could document your method by saying that it requires
> an object that responds to to_int, but that seems a bit roundabout
> compared to just saying you want an object that responds to times.)

I don't see why there would be a need to add documentation indicating
that count must respond to times, since it's already written right there
in the code. We just need a type inference engine to find this and tell
us about it.

cjs
-- 
Curt Sampson  <cjs / cynic.net>   +81 90 7737 2974   http://www.NetBSD.org
      Make up enjoying your city life...produced by BIC CAMERA