From: Warren Brown Date: 2004-03-06T08:44:40+09:00 Subject: Re: Duck typing chapter Dave, > I've posted a rough first pass at a chapter about duck typing (and > other typing issues in Ruby). It covers > > - what a type is > - duck typing > - Ruby's built-in protocols (to_str, to_proc, etc) > - coercion and double dispatch > > http://www.pragmaticprogrammer.com/extracts/ducktyping.pdf > > It isn't typeset, and I haven't really read it through for typos. I'd > be interested to see what folks think. Again, all feedback gratefully > received. One thing that stuck out to me is that after explaining that in Ruby the class is not the type, the class Roman tests the class of its parameters (i.e. "if Integer === other"). In this case you could (and probably will) argue that the class *is* the type, but this should probably be specifically stated to the reader to avoid confusion. I'm sure you'll find all of the easy typos, but there is a subtle one in the Roman#initialize method (no not the "muts" one). The error message should say "<= #{MAX_ROMAN}", not "< #{MAX_ROMAN}". The only other thing that struck me as odd was the assumption in Roman#coerce that any parameter that is not a Fixnum should be converted to a Float. This seems a bit simplistic, especially with Bignum as a built-in class, and would seem to preclude using some other Integer-like class (Chinese number?). Perhaps a check for a to_int method would be more appropriate? Anyway, the rest looks good. I look forward to the next edition! - Warren Brown