From: Daniel Waite Date: 2008-05-02T12:35:42+09:00 Subject: Re: DSL - class-level methods that affect instances David A. Black wrote: > I'd say: don't think of it as any more of a barrier than exists > between any other two objects. That helps, actually. Viscerally, for now, but I'm sure the fullness of the stance will sink in with time. > (I know that sounds kind of doctrinaire, but I like to lay it on thick > since it usually takes some doing to chip away at the presumptive > class/instance special relationship :-) I love saturated opinions. (David West all the way!) I'm re-reading your book right now starting from chapter 5, and yes, I can already tell I've lost a forgotten a lot of my understanding of how Ruby works. (I suppose you could argue I never understood it if I forgot...?) > module Translator > attr_reader :translations > > def translate(target, actions) > @translations ||= [] > @translations.push("Translating #{target} to #{actions[:to]}") > end > end > > class C > extend Translator > > def translations > self.class.translations > end > > translate "this", :to => "that" > end > > p C.new.translations # ["Translating this to that"] Works beautifully. Amazing. I thought I was going to end up with some monolithic structure like ActiveRecord. ;) @Ken: Your solution works equally well! I like that yours is class-based so I don't have to call extend in the body of each inheriting class (of which there will be quite a few). I'm not worried about tertiary inheritance; I don't plan on needing it. (Famous last words, right?) Thank you both, Ken and David, very much! -- Posted via http://www.ruby-forum.com/.