From: dblack@... Date: 2007-02-22T07:38:19+09:00 Subject: Re: Please illuminate how stupid I am re: initialization blocks. Hi -- On Thu, 22 Feb 2007, Michael Judge 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: > > create_table :users do > column :first, :string > column :last, :string > end > > Am I being really dumb? Is there something horrifying that I'm not > grasping? People do it that way too. I personally don't like it, because it's weird to me to have 'self' change in a way that I can't see: @x = :first create_table :users do column @x, :string # different @x! end I think instance_eval works best as a big clunky method name that draws attention to itself, and not as something folded away invisibly. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)