Skip to content

Instantly share code, notes, and snippets.

@wethu
Created April 1, 2014 03:50
Show Gist options
  • Select an option

  • Save wethu/9907383 to your computer and use it in GitHub Desktop.

Select an option

Save wethu/9907383 to your computer and use it in GitHub Desktop.
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