From: Eric Hodel Date: 2004-11-15T06:04:57+09:00 Subject: Re: assert --2eauhx3HRLXw1WRo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Michael Neumann (mneumann@ntecs.de) wrote: > On Sun, Nov 14, 2004 at 01:20:49AM +0900, Gavin Sinclair wrote: > > On Sunday, November 14, 2004, 2:48:24 AM, Florian wrote: > >=20 > > > Gavin Sinclair wrote: > >=20 > > >>>>>I have thought about changing the name to "assume" so it can be in= cluded > > >>>>>in dev-utils, but I'm not sure if that name is better. > > >>>I think that would be way too much magic. I'd expect the method to j= ust > > >>>take a block. > > >>=20 > > >> Why a block? The breakpoint code uses Binding.of_caller anyway, so a > > >> block is not needed for evaluation. I don't see any other reason, > > >> technical or stylistic, why a block should be preferred. > >=20 > > > Using strings for code is a bit ugly. We have blocks in Ruby, why not > > > use them? Using a String also causes a bit of escaping trouble (I know > > > this can be worked around via the %{} or <<-END syntax, but I still= =20 > > > think blocks are clearer than that.) > >=20 > > Agreed, but you can print strings. You can't print blocks. See > > below. >=20 > Hm, has someone tried ParseTree > (http://www.zenspider.com/ZSS/Products/ParseTree/) to print out blocks? >=20 > Would be really great if that works. >=20 > trace { x + y } #=3D> x+y =3D 5=20 > assert { x + y =3D=3D 0 } #=3D> assertion 'x+y=3D=3D0' failed... >=20 > Uhm, seems that's only possible to dump methods in classes, not > arbitrary code. But maybe, it's possible. $ parse_tree_show class Test def test trace { x + y } assert { x + y =3D=3D 0 } end end [[:defn, "test", [:scope, [:block, [:args], [:iter, [:fcall, "trace"], nil, [:call, [:vcall, "x"], "+", [:array, [:vcall, "y"]]]], [:iter, [:fcall, "assert"], nil, [:call, [:call, [:vcall, "x"], "+", [:array, [:vcall, "y"]]], "=3D=3D", [:array, [:lit, 0]]]]]]]] It is pretty easy to walk that tree to find the [:iter, [:fcall, "trace"], ...] or "assert" and then generate some reasonable english phrase from it. You could pull and walk the tree on failures to the assertion you wanted to generate a comment for... --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --2eauhx3HRLXw1WRo Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQFBl8h2MypVHHlsnwQRAhxqAKDiUd7q69zDdbysQ7/a0v5zIz6dswCg0YId iEI10sDk6XmzCSURDkP5JKU= =cePZ -----END PGP SIGNATURE----- --2eauhx3HRLXw1WRo--