Skip to content

Instantly share code, notes, and snippets.

@tcocca
Created October 26, 2010 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcocca/647841 to your computer and use it in GitHub Desktop.
Save tcocca/647841 to your computer and use it in GitHub Desktop.
attr_accessor :features_as_hash
def method_missing(method_name, *args, &block)
name = method_name.to_s
if self.respond_to?(name)
super
elsif features_hash.has_key?(name)
return features_hash[name]
else
logger.debug("Attribute #{name} on property #{self.id} does not exist")
super
end
end
def features_hash
if features_as_hash.nil?
self.features_as_hash = {}
property_features.each do |prop_feature|
self.features_as_hash[prop_feature.feature.name] = prop_feature.value if prop_feature.feature
end
end
self.features_as_hash
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment