From: Paul Brannan Date: 2002-09-20T09:42:34+09:00 Subject: Re: Is better to subclass or to add methods to an existing class? On Fri, Sep 20, 2002 at 07:38:40AM +0900, Christoph wrote: > ``proc type'' class_eval's do not change the scope. In other > words there is only one (the top) Beast around - hence This must have changed from 1.6 to 1.7. / test.rb Beast = self (@temptation = Class.new String).class_eval <<-Body Beast = self def six_six_six; Beast end Body t = @temptation.new("foo") p t.six_six_six p Beast Beast = self (@temptation = Class.new String).class_eval do Beast = self def six_six_six; Beast end end t = @temptation.new("foo") p t.six_six_six p Beast \ end test.rb [pbrannan@zaphod tmp]$ ruby -v test.rb ruby 1.6.7 (2002-03-01) [i686-linux] # #> test.rb:11: warning: already initialized constant Beast # #> [pbrannan@zaphod tmp]$ ruby-1.7 -v test.rb ruby 1.7.3 (2002-09-04) [i686-linux] # #> test.rb:11: warning: already initialized constant Beast test.rb:13: warning: already initialized constant Beast Beast Beast > A ``string type'' class_eval creates the expected two > Beasts and six_sx_six picks up the inner Beast - hence I guess the string-type eval will work on both 1.6 and 1.7. I wonder if there's a way to get the same functionality on both 1.6 and 1.7 without evaling a string. Paul