Created
April 1, 2014 03:50
-
-
Save wethu/9907383 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Job < ActiveRecord::Base | |
| serialize :properties, Hash | |
| attr_accessor :fields | |
| def initialize | |
| @fields = property_fields | |
| super | |
| end | |
| def property_fields | |
| Array self.job_type.field_names | |
| end | |
| # This doesnt work NoMethodError: undefined method `each' for nil:NilClass | |
| @fields.each do |meth| | |
| define_method(meth) { @properties[meth.to_sym] } | |
| end | |
| # This works, however I get undefined method on [], | |
| # which is probably expected since @properties would not contain foo or bar | |
| %w[foo bar].each do |meth| | |
| define_method(meth) { @properties[meth.to_sym] } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment