Skip to content

Instantly share code, notes, and snippets.

@lsegal
Created March 26, 2010 04:19
Show Gist options
  • Select an option

  • Save lsegal/344517 to your computer and use it in GitHub Desktop.

Select an option

Save lsegal/344517 to your computer and use it in GitHub Desktop.
class Object
def self.method_added(name)
return if name == :initialize
const_set(:InstanceMethods, Module.new) unless defined?(self::InstanceMethods)
self::InstanceMethods.send(:define_method, name, &instance_method(name).bind(self.allocate))
remove_method(name)
include self::InstanceMethods
end
end
class A
def initialize; @a = "X" end
end
class B < A
def foo; @a end
end
p B.new.foo # => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment