Ari Brown
9/14/2007 9:45:00 PM
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