From: Albert Schlef Date: 2010-02-05T06:42:59+09:00 Subject: Re: Where is the magic? Ilya Lopatkin wrote: > Robert Klemme wrote: >> Struct.new uses instance_eval internally: >> > > Thanks for your response. I've almost grasped the idea. :) Here's an explanation is other words: When you create a block you create a parcel that contains three things: - The code itself. - The "binding" (links to the surrounding variables). - The value of 'self' (this is how ruby knows which object to invoke methods on). When you normally 'yield' to a block, the block uses the value of 'self' saved in that parcel. On the other hand, when you do 'somebody.eval_instance()', the 'self' in that parcel is set to 'somebody'. It is common in GUI frameworks to use eval_instance() to make the code look like DSL (google for "DSL"). -- Posted via http://www.ruby-forum.com/.