From: Sean O'Halpin Date: 2008-03-23T08:13:53+09:00 Subject: Re: #meta On Sat, Mar 22, 2008 at 1:39 PM, Robert Klemme wrote: > While I think about it you could even do: > > class Object > def meta(&b) > cl = class< cl.class_eval(&b) if b > cl > end > end > > class Some > meta do > attr_accessor :foo > > def incr > self.foo += 1 > end > end > end > > Kind regards > > robert > Indeed - I'm using almost identical code in doodle[1] but using the name #singleton_class instead of #meta :) def singleton_class(&block) sc = (class << self; self; end) sc.module_eval(&block) if block_given? sc end @Trans - doesn't #meta clash with an openuri attribute? I've just removed it as an alias to #singleton_class in doodle for that reason. FWIW, I'm considering renaming #singleton_class to avoid clashing with someone else's definition. Perhaps, something like #the_method_formerly_and_variously_known_as_singleton_eigen_or_meta_class ;) Regards, Sean [1] http://doodle.rubyforge.org