johanatan <zjll9 / imail.etsu.edu> <zjll9 / imail.etsu.edu> wrote: > transfire wrote: > > If you don't mind while I'm at this I'm going to touch up the code to > > follow ruby conventions. > > I don't mind at all. I'm new to ruby so I haven't picked up on the > extensions yet. :) Understandable. As you've noticed Matz prefers underscores and lowercase over camelcase for methd names, so that's become the general convention. There's alos a tendency to get them as small as possible while still being human readable/self-documenting. > > > > > def initialize( attr_and_sizes_hash, consumer_class ) > > attr_and_sizes_hash.each {|attr_name, max_size| > > code = %{ > > def #{attr_name}=( file ) > > write_attribute( '#{attr_name}', ImageBlob.getBlob( file, > > #{max_size} ) ) > > end > > } > > consumer_class.class_eval code > > end > > > > I didn't try class_eval. Did you test this or is it just a theory? :) > Seemed like regular eval and extend should work. I didn't test, but I've used it enough times to know that the way to go about it (even I made a booboo in my code) You'll notice David used it in his variation too. > > BTW it seems odd to use the #initialize method of ImageBob to do this. > > It is odd, but the ImageBlob class contains only one class method (i.e., > static method) and no data members, so no actual memory should be > defined for it. I suppose it could have contained two class methods > instead of using initialize (that is better so I'll change that). At > first, I was trying to store a ptr to the ImageBlob instance in the > consumer class but realized it wasn't necessary. If ImagaBob is not instantiable then a module would be better than a class. > Much thanks for the answers. No problemo. T.