Skip to content

Instantly share code, notes, and snippets.

View cameron-martin's full-sized avatar

Cameron Martin cameron-martin

View GitHub Profile
# include from an initializer
module HstoreAccessor
def hstore_accessor(hstore_attribute, *keys)
Array(keys).flatten.each do |key|
define_method("#{key}=") do |value|
send("#{hstore_attribute}_will_change!")
send("#{hstore_attribute}=", (send(hstore_attribute) || {}).merge(key.to_s => value))
end
define_method(key) do