From: Trans Date: 2008-03-23T04:21:17+09:00 Subject: Re: #meta Hi Robert, On Mar 22, 9:39 am, Robert Klemme wrote: > I am feeling stupid because I seem to overlook something: what is the > advantage of your approach vs. > > class Object > def meta > class< end > end > > ? As far as I can see your functor in this case simply delegates all > method invocations to the singleton class. Why not directly use / > return it? Try it: >> class X >> meta.attr_accessor >> end NoMethodError: private method `attr_accessor' called for # from (irb):7 > 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 There's no need for meta at all, you could just use "class << self" directly, class Some class << self attr_accessor :foo def incr self.foo += 1 end end end But just as some people prefer to use "def self.foo", it's nice to use module level methods like #class_attr_accessor. That's were #meta comes in as generalized form rather than defining class level equivalents for all possible methods. T.