From: Ari Brown Date: 2007-09-15T06:45:15+09:00 Subject: Re: metaprogramming to generate list of class-specific attributes On Sep 14, 2007, at 5:00 PM, Phlip wrote: > Rubyists: Here is one answering > class Kozmik > def self.acts_as_frog(species) > @frog_list ||= [] > @frog_list << species > self.class.send :attr_accessor, :frog_list > end > end > > Is that as clean and lean as it could be? Is there some way to do > this with > even fewer lines? I am not really sure if this works, but couldn't you do: class Kozmik def self.inherited module_eval do @frog_list = [] end end def self.acts_as_frog(species) @frog_list << species end end Also, does module_eval only work in a class method? Why can't I do def something; module_eval do puts 5 end; end ? Ari -------------------------------------------| Nietzsche is my copilot