-
-
Save dminuoso/5de30a7b950db29889031ad10eebcb83 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'fiddle' | |
class Object | |
def _ptr_to_hex(ptr) | |
str = ptr.ref.to_str(_sizeof_value) | |
_str_to_hex(str) | |
end | |
def _str_to_hex(str) | |
sprintf("%#x", str.unpack("L")[0]) | |
end | |
def _cast(as) | |
as.new.send(:instance_variable_set, :@nil, nil) | |
self._klass_ptr = as._rbasic_ptr.ref.to_str(_sizeof_value) | |
end | |
def _sizeof_value | |
return Fiddle::SIZEOF_VOIDP | |
end | |
def _sizeof_rbasic | |
return 2 * _sizeof_value | |
end | |
def _klass_ptr | |
_rbasic_ptr[_sizeof_value, _sizeof_value] | |
end | |
def _klass_ptr=(new) | |
_rbasic_ptr[_sizeof_value, _sizeof_value] = new | |
end | |
def _superclass=(new) | |
self._superclass_ptr = new._rbasic_ptr.ref.to_str(_sizeof_value) | |
end | |
def _superclass_ptr | |
_rbasic_ptr[_sizeof_rbasic, _sizeof_value] | |
end | |
def _superclass_ptr=(new) | |
_rbasic_ptr[_sizeof_rbasic, _sizeof_value] = new | |
end | |
def _rbasic_ptr | |
@_rbasic ||= Fiddle::Pointer.new(__id__ << 1) | |
end | |
def _flags | |
_rbasic_ptr[0, _sizeof_value] | |
end | |
def _flags=(other) | |
_rbasic_ptr[0, _sizeof_value] = other | |
end | |
def _refresh_method_cache | |
self.send(:define_method, :_fiddlerino) {} | |
self.send(:undef_method, :_fiddlerino) | |
end | |
end | |
class Toxic | |
def include | |
puts "Death awaits us" | |
end | |
end | |
class Module | |
def bypass_super | |
tracker = Class.new | |
old_superclass = superclass | |
self._superclass = tracker | |
yield | |
ancestors[ancestors.index(tracker) - 1]._superclass = old_superclass | |
self._refresh_method_cache | |
end | |
end | |
module FunStuff | |
def hello | |
puts "hello world" | |
end | |
end | |
class Mine < Toxic | |
bypass_super do | |
include FunStuff | |
end | |
end | |
Mine.new.hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment