Am Mittwoch, 12. Jan 2005, 05:06:36 +0900 schrieb E S: > > LçÉettçËäº Bertram Scharpf <lists / bertram-scharpf.de> > > Aihe: Kernel#eval and class definition > > > > Hi, > > > > I try to understand more deeply what Ruby does. > > Why here is the first line forbidden, the second allowed? > > > > def f ; class C ; end ; end > > def f ; eval "class C ; end", binding ; end > > > > Thanks for your answers in advance. > > I'm assuming you have something passed to the function that you need > the binding for? Are you getting an error? You may want to try to > establish the binding before the eval call and see if that helps. That shouldn't make a difference and, as far as I see, it doesn't. irb(main):001:0> def f ; class C ; end ; end SyntaxError: compile error (irb):1: class definition in method body def f ; class C ; end ; end ^ from (irb):1 irb(main):002:0> def f ; eval "class C ; end", binding ; end => nil irb(main):003:0> def f x ; y = x ; eval "class C ; end", binding ; end => nil irb(main):004:0> Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de