The only problem is, that there’s no accessor methods. Let’s assume that our model (Product) need price and weight. We will have to write something like this:
moduleHstoreAccessorextendActiveSupport::ConcernmoduleClassMethods# Define accessors method for HStore field## @param [Symbol] hstore name of HStore field# @param [Array] fields list of accessors methods to definedefhstore_accessor(hstore,*fields)fields.eachdo|field|define_hstore_readerhstore,fielddefine_hstore_writerhstore,fieldendendprivatedefdefine_hstore_reader(hstore,field)define_methodfielddosend(hstore)&&send(hstore)[field]endenddefdefine_hstore_writer(hstore,field)define_method:"#{field}="do|val|val=(send(hstore)||{}).merge(field=>val)send(:"#{hstore}=",val)endendendend