Skip to content

Instantly share code, notes, and snippets.

@stansidel
Created January 23, 2014 10:27
Show Gist options
  • Save stansidel/8576264 to your computer and use it in GitHub Desktop.
Save stansidel/8576264 to your computer and use it in GitHub Desktop.
Calling the overriden method from the new implementation
module Populator
class Record
# See http://stackoverflow.com/questions/4470108/when-monkey-patching-a-method-can-you-call-the-overridden-method-from-the-new-i
old_initialize = instance_method(:initialize)
define_method(:initialize) do |class_name, id|
old_initialize.bind(self).(class_name, id)
@class_name = class_name
end
def from_factory
self.attributes = FactoryGirl.build(@class_name.to_s.downcase.to_sym).attributes.delete_if { |k, v| v.blank? }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment