ara.t.howard wrote: > > On Nov 12, 2007, at 11:38 AM, Rick DeNatale wrote: > >> a = MyObject.new.tap do |o| # or returning, or affect >> o.foo = 1 >> o.bar = "whatever" >> end > > just as easy to do this though: > > a = MyObject.new.instance_eval{ > foo 1 > bar 'whatever' > self > } > > no special methods needed... > > returning is, imho, over rated. Really? There is the scope issue. I use this construct sometimes: def socket @socket ||= UDPSocket.open.then do |s| s.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true) s.connect(@svr_addr, @svr_port) end end def initialize @svr_addr, @svr_port = ... end def run loop { socket.send(...) } end #instance_eval makes it unnatural to access instance variables of the outer scope (you have to pass them through locals). (#then is my own personal preference to #tap, which usually makes me start thinking about Spinal Tap, and I have to laugh for a while.) -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407