On Oct 20, 9:45 pm, cult hero <[email protected]> wrote: > Thanks! I was just making sure I wasn't going to have to reinvent the > wheel. > > There is a slight problem with the code you provided though. This one > works: > > module Sequel::Model::ClassMethods > def def_column_accessor(*columns) > columns.each do |column| > meth = column.to_s.underscore > overridable_methods_module.module_eval("def #{meth}; > self[:#{column}] end", __FILE__, __LINE__) > overridable_methods_module.module_eval("def #{meth}=(v); > self[:#{column}] = v end", __FILE__, __LINE__) > end > end > end > > You just overrode the wrong module.
Yeah. I obviously didn't test it first, I was just laying out the general idea. > Also, where are you getting String.underscore? I know ActiveSupport > supplies that but I'm not using it. (I used my own method in this > case.) You can use underscore(column) instead of column.to_s.underscore. Note that I left off most of the error checking code done by def_column_accessor. You should probably read the source code of the method to see what checks it makes if you plan on overriding it in production. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
