From: Logan Capaldo Date: 2006-07-22T23:56:49+09:00 Subject: Re: [ANN] Mongoose 0.2.0 On Jul 21, 2006, at 11:10 PM, John W. Long wrote: > Jamey Cribbs wrote: >> The way it works is that in the Plane.find method, I grab the >> block and pass it to #instance_eval. This executes the block in >> the Plane classes environment, so it knows that when it sees the >> attribute "speed" or "country" in the block, it knows to call >> Plane.speed and Plane.country. Planes.speed happens to be a >> reference to a SkiplistColumn instance and it knows how to handle >> the "> 350" passed to it. > > The problem with this approach is that you loose access to instance > variables. For instance: > > >> class Object > >> def with(&block) > >> instance_eval(&block) > >> end > >> end > => nil > >> @test = 1 > => 1 > >> Object.new.with { puts @test } > => nil > > In the above example @test when used within the context of the with > block is thought to be an instance variable of the object, which is > why it returns nil instead of 1. I consider this behavior undesirable. > I can think of how to do and operations with a parameter passing style w/o instance_eval, and how to do _ors_ but not both at the same time. Unless we want to get rid of the any method and use pipe as logical or. The problem with that is now you can't do bitfield comparisons. Say you store a Fixnum with some flags in the the db: find do |plane| ( plane.bitfield | 0b100 ) == 0b100 end How do we do ors now w/o instance_eval? any could be toplevel, but that's very polluting of the global namespace. *shrug* > -- > John Long > http://wiseheartdesign.com >