Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created July 25, 2013 16:37
Show Gist options
  • Save tenderlove/6081499 to your computer and use it in GitHub Desktop.
Save tenderlove/6081499 to your computer and use it in GitHub Desktop.
require 'fiddle'
module Python
def __class__= k
value = _wrap self
[k.object_id<<1].pack('Q').unpack('C8').each_with_index {|n,i|value[i+8]=n}
end
def _wrap klass; Fiddle::Pointer.new Fiddle.dlwrap klass; end
end
class Object
include Python
end
x = Object.new
p x.class # => Object
x.__class__ = Class.new { def lol; 'lol'; end }
p x.class # => #<Class:0x007fccbb06df80>
p x.lol # => "lol"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment