From: "Ara.T.Howard" Date: 2003-11-19T12:42:20+09:00 Subject: Re: "stereotyping" (was: Re: Strong Typing (Re: Managing metadata about attribute types)LONGEST SUB? On Wed, 19 Nov 2003, T. Onoma wrote: > I wonder if it would be helpful to be able to ask a method what the > respond_to? requirements of its parameters will be. > > def read(io_object) io_object.read end > > method(:read).duck_signiture # => [ [:read] ] > > then you might > > def read(io_object) self.method(:read).duck_signiture[0].each { |m| fail > "Not Responsable Object" unless io_object.respond_to?(m) } io_object.read > end > > a shorthand would be nice. how about simply obj.respond_to? :read # => true obj.respond_to? :read, IO # => true obj.respond_to? :read, IO, Proc # => false in otherwords class Object def respond_to? meth # old stuff... end end becomes class Object def respond_to?(meth, *signature) # new stuff... end end nice and backward compatible. easy to remember. -a -- ATTN: please update your address books with address below! =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | STP :: http://www.ngdc.noaa.gov/stp/ | NGDC :: http://www.ngdc.noaa.gov/ | NESDIS :: http://www.nesdis.noaa.gov/ | NOAA :: http://www.noaa.gov/ | US DOC :: http://www.commerce.gov/ | | The difference between art and science is that science is what we | understand well enough to explain to a computer. | Art is everything else. | -- Donald Knuth, "Discover" | | /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done' ===============================================================================