From: Maurice Codik Date: 2006-02-08T09:54:03+09:00 Subject: Re: Meta-Meta-Programming ------=_Part_14829_16318285.1139360026835 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Yet another suggestion-- I wrote a little library that lets you define simple contracts for function inputs... useful if you dont want to repeat the same duck-type assertions over and over again. here's an example of how it works: require "contracts" class TestContracts extend Contracts define_data :writable =3D> lambda {|x| x.respond_to?("write") and x.respond_to?("closed?") and not x.closed? }, :positive =3D> lambda {|x| x >=3D 0 } contract :hello, [:positive, :string, :writable] def hello(n, s, f) n.times { f.write "hello #{s}!\n" } end end tc =3D TestContracts.new tc.hello(2, "world", $stdout) # -> hello world! # -> hello world! # tc.hello(2, 3, $stdout) # -> test-contracts.rb:22: argument 2 of method 'hello' must satisfy the 'string' contract (Contracts::ContractViolation) You can download it at: : http://mauricecodik.com/projects/ruby/contracts.r= b Maurice On 2/7/06, Trans wrote: > > > So I have to replace every Foo.new to JustWrap.new, just to > > activate the debugging? Kidding? > > No you do not. A cut is a _transparent_ class. You would still use > Foo.new. > > T. > > > ------=_Part_14829_16318285.1139360026835--