On 2/21/07, Michael Judge <mjudge / surveycomplete.com> wrote: > I seem to use blocks much differently from other people and that > frightens me a little. (Maybe I'm being really dumb and nobody wants > to say anything.) > > Before I get into what I do, let me define how normal people call a > block passed in to a method. They use "yield". And that's cool, > that's what yield is intended for. Their methods tend to look like > this when they're later put into practical use: > > create_table :users do |t| > t.column :first, :string > t.column :last, :string > end > > If I had programmed create_table though, I would have used > instance_eval, and you'd use create_table like this: amongst many other things instance eval would expose private methods, so there is for sure some reason why create_table calls the block with an object instead of instance_evalling it > > create_table :users do > column :first, :string > column :last, :string > end > Now of course instance_eval is not necessarily a bad idea, especially if you prepare the object well in which instance_eval is called. - which might be much work though. It is a well known DSL technique. > Am I being really dumb? I let you be the Judge of that statement ;) Is there something horrifying that I'm not > grasping? As I said there are some dangers you might not have thought of, but I would not be as extreme ;) Hopefully others will point out more issues. > > Thanks for your help! > > - Michael Judge > > Cheers Robert -- We have not succeeded in answering all of our questions. In fact, in some ways, we are more confused than ever. But we feel we are confused on a higher level and about more important things. -Anonymous