From: ara.t.howard@... Date: 2007-02-16T15:34:22+09:00 Subject: Re: functional.rb On Fri, 16 Feb 2007, Gregory Brown wrote: > On 2/16/07, ara.t.howard@noaa.gov wrote: > >> why not >> >> harp:~ > cat a.rb >> class Object >> def tap &b >> instance_eval &b >> return self >> end >> end >> >> puts "foobar".tap{ gsub! /bar/, '' } #=> foo > > Well that prevents you from being able to access the enclosing scope, > but maybe that's okay for a tap. You could always offer both by > checking block arity. > hrrrmmm. i wouldn't say 'prevents' - but confuses ;-) harp:~ > cat a.rb class Object def tap &b b.arity == 1 ? yield(self) : instance_eval(&b) return self end end s, re = "foobar", /bar/ puts s.tap{ gsub! re, nil.to_s }.upcase #=> FOO harp:~ > ruby a.rb FOO good idea on the arity btw. -a -- we can deny everything, except that we have the possibility of being better. simply reflect on that. - the dalai lama