The fundamental implementation of the two approaches is different. In the first (and actual) case create_table calls yield with a TableDefinition object. So t in your example block points to that TableDefinition The alternative method is to use instance_eval.
This would look something like.
The fundamental implementation of the two approaches is different. In the first (and actual) case, create_table calls yield with a TableDefinition object. So t in your example block points to that TableDefinition.
The alternative method is to use instance_eval. This would look something like: def create_table(name, &block) table_definition = TableDefinition. New # Other setup table_definition.
Instance_eval(&block) # More work end Which way you do it is partially a matter of preference. However, some people are not fans of eval so they like to avoid this. Also, using the yield method makes it clearer what object you're working with.
You could use a technique like mixico github. Com/coderrr/mixico and avoid the self remapping and instance_eval. Nonetheless, I do not follow why you would need access to self during your column defs.
– Sam Saffron? Oct 5 '09 at 1:30 I do however think its peoples blanket dislike of instance_eval that lead to that decision, so will +1 you for that. – Sam Saffron?
Oct 5 '09 at 1:34 I'm sort of on the fence myself. I am drawn to the cleanness of the instance_eval option, but at the same time I get the feeling that maybe it's a good idea to avoid it. It's something I'll need to think about more.
– Peter Wagenet Oct 5 '09 at 1:42.
My understanding is that ruby is lexically scoped, meaning that "integer" has to refer to something defined at the point it occurs in the code. You'd need dynamic scoping to accomplish what you're asking for. It may be that I'm wrong and at least one of procs, blocks and lambdas is dynamically scoped, but then you still have your answer -- obscure details of how scope behaves is not a good thing to expect a programmer to know.
I'm not sure how this answers the question. – Peter Wagenet Oct 5 '09 at 1:04 The mere presence of a block defines a scope... you could access it in create_table and give integer context to that table. I don't see why not... – Jamie Rumbelow Oct 5 '09 at 1:04 You can bring the block (more or less) into the scope where it's called with instance_eval.
– Chuck Oct 5 '09 at 1:15 You could also simply define integer, string etc.. before the yield and undef them at the end. – Sam Saffron? Oct 5 '09 at 1:33.
Basically the interface designer should have chosen to do so due to this little trick regarding scopes and how eval and instance_eval work, check this example: Having 2 classes Foo and Boo with the following definitions: class Foo def speak(phrase) puts phrase end def self. Generate(&block) f = Foo. New f.
Instance_eval(&block) end end class Boo attr_reader :name def initialize(name) ; @name = name ; end def express Foo. Generate { speak name} end end Generally this should work fine for most cases, but some situations like the following statement will issue an error: Boo. New("someone").
Express #`express': undefined local variable or method `name' for # (NameError) We don't have access here to the instance methods of Boo inside Foo instances that's because we are using instance_eval, so the method name which is defined for Boo instances is not in the scope for Foo instances. To overcome such problems it’s better to redefine generate as follows: class Foo def speak(phrase) puts phrase end def self. Generate(&block) f = Foo.
New block. Arity someone Boo. New("someone").
Talk("whatever") #=> whatever.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.