From: David Alan Black Date: 2002-02-20T03:15:58+09:00 Subject: Re: Anonymous class support Hello -- On Wed, 20 Feb 2002, Christoph wrote: > wrote in message > news:200202190622.g1J6MqX18863@sharui.nakada.kanuma.tochigi.jp... > > > Class.new(superclass).class_eval do > > def foo > > end > > end > > > > In 1.7, .class_eval isn't necessary. > > Unfortunately you cannot use the ladder idiom within method bodies - for > example .. > > ---- > class A > def foo(&body) > Class.new(type,&body) > end > def goo(&body) > res = Class.new(type) > res.class_eval &body # this works because &body is a string! > res > end > # > end > > > anon =A.new.foo { Pointless = "okay" } > puts anon.const_get :Pointless # => okay > # A.new.foo { def annoying_parse_error() end } > > > anon.new.goo { def okay(); puts "okay" end }.new.okay # => okay Playing around with this example, I can't seem to get the parse error (1.7.1). Where does it happen exactly? Also, isn't body a proc, rather than a string (inside method goo)? David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav