On Sat, 22 Nov 2003, Yukihiro Matsumoto wrote: > |I've been thinking about DbC stuff for some time and something in Matz Ruby > |2 talk last Saturday sparked an idea along these lines ... > | > | class Person > | def greet(other_person) > | marry(other_person) > | end > | end > | > |Then specify the contract in a separate file ... > | > | class Person > | def greet:pre(other_person) > | assert ! self.married? > | assert ! other_person.married? > | end > | > | def greet:post(other_person) > | assert other_person.married? > | assert self.married? > | assert_equal self, other_person.spouse > | assert_equal other_person, self.spouse > | end > | end > > I'd be second to Chad. Cool. > > |An aside: Unfortunately, the post method doesn't have access to the result > |returned from the function. In this case it doesn't matter, but many post > |conditions assert something interesting about the result. I guess I would > |have to use a wrap method for that. > > The only reason the result is _not_ available from post method is we > don't have neat syntax construct. Any proposal? > > matz. i remeber some talk of 'def' returning values. this leads nicely into setting the atrributes for a method via a 'Method' object: class Method # beautiful thing that matz will write end class Person greet_method = def greet # ... end greet_method.pre = lambda{|args, block|...} #greet_method.pre = :name_of_greet_pre_checker #greet_method.pre = another Method object greet_method.post = lambda{|result, args, block|...} #greet_method.post = :name_of_greet_post_checker #greet_method.post = another Method object end if this existed one could do (in person_if.rb) class Person greet_method = method(:greet) greet_method.pre = def greet_pre; end greet_method.post = def greet_post; end ... end something that objectified methods and gave them :pre and :post methods would lead to all sorts of possibilities .... just another idea ... -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' ===============================================================================