From: jzakiya Date: 2008-06-10T07:10:04+09:00 Subject: Re: eval bug? On Jun 8, 3:22 pm, Mike Cargal wrote: > of course... it's very "unruby" to say return, so... > > def tm > start = Time.now > yield > Time.now - start > end > > or (if you seem to prefer the one line syntax... > > def tm; s=Time.now;yield;Time.now-s end > > On Jun 8, 2008, at 12:10 PM, Mike Cargal wrote: > > > > > I think a more "ruby" implementation of tm would be... > > > def tm > > start = Time.now > > yield > > return Time.now - start > > end > > > duration = tm { > > # any code you want to time goes here > > } > > On Jun 7, 2008, at 11:33 PM, jzakiya wrote: > > >> I have this code to do timing tests: > > >> def tm(code); s=Time.now; eval code; Time.now-s end > > >> I use it like this: > > >> tm 'some code' > > >> I have this function that can take two inputs. > >> When I run it with just one input like this: > > >> tm 'Pn(130)' > > >> I can time it with no problems. > > >> When I use a second input like this, > > >> tm 'Pn(130, mcps)' > > >> running in irb (1.8.6 and 1.9.0-1) it returns an > >> unknown method or variable message for the > >> second input. > > >> Is this a bug, or expected behavior? > >> Can I work around this? > > >> Thanks in advance. > > Mike Cargal > m...@cargal.nethttp://www.cargal.net Thanks, this works great. I learned something. ;-) It sort of acts like a lamda. But is that still a bug in eval? Jabari