From: Edward Faulkner Date: 2005-09-20T23:57:03+09:00 Subject: Block that takes a block --3MwIy2ne0vdjdPXF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable How can I make a block that takes a block argument? This doesn't parse: myproc =3D proc{|&blk| [1,2,3].each(&blk)} The main reason I want to do this is to create a method with 'define_method' that takes a block argument. =20 For example, the 'before' method below works fine, until you apply it to a method that takes a block. =20 class Object # Is there a built-in way to do this? def metaclass; class << self; self; end; end # Call blk before each invocation of method_name def before(method_name, &blk) oldblk =3D method(method_name) metaclass.instance_eval { define_method(method_name){|*args| blk.call(*args) oldblk.call(*args) } } end end thanks, Ed --3MwIy2ne0vdjdPXF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFDMCMJnhUz11p9MSARAqUKAJ44DiESJ4rZuLJOpLCfvMeWV9YE2wCeJnsP 0XRKv+gGaRZYL+qzRjjJHBw= =kqJd -----END PGP SIGNATURE----- --3MwIy2ne0vdjdPXF--