Created
October 14, 2011 05:55
-
-
Save gamov/1286351 to your computer and use it in GitHub Desktop.
Adding setter and getter of attributes of a AR model backed by an Hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel < ActiveRecord::Base | |
serialize :preferences, Hash | |
PREFS_KEYS = [:hostname, :has_retail] | |
PREFS_KEYS.each do |key| | |
define_method(key) do | |
preferences[key] | |
end | |
define_method("#{key}=") do |value| | |
preferences[key]= value | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment