Created
July 7, 2014 03:21
-
-
Save jdjkelly/e517ba31c1f4c007651b to your computer and use it in GitHub Desktop.
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 ObjectBuilder | |
def prototype(proto) | |
# Leave method implementations on the proto object | |
ivars = proto.instance_variables.reject{ |ivar_name| | |
proto.respond_to?(ivar_name.to_s[1..-1]) && | |
proto.instance_variable_get(ivar_name).is_a?(Proc) | |
} | |
ivars.each do |ivar_name| | |
unless @object.instance_variable_defined?(ivar_name) | |
@object.instance_variable_set( | |
ivar_name, | |
proto.instance_variable_get(ivar_name).dup) | |
end | |
end | |
@object.extend(Prototype.new(proto)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment