Skip to content

Instantly share code, notes, and snippets.

@0x1eef

0x1eef/blah.rb Secret

Created July 3, 2022 07:33
Show Gist options
  • Save 0x1eef/d3224941c61846298be26396c7209d0b to your computer and use it in GitHub Desktop.
Save 0x1eef/d3224941c61846298be26396c7209d0b to your computer and use it in GitHub Desktop.
require 'digest/md5'
def mixin(obj)
m, k = Module.new {}, obj
k.methods.each do |x|
m.define_method(x, proc { |*args, &b| k.method(x).call(*args, &b) })
end
m
end
class Foo
def initialize
@bar = 1
end
def foobar
[self, @bar]
end
end
class Bar
include mixin(Foo.new)
end
bar = Bar.new
p bar.foobar
class Baz
include mixin(Digest::MD5)
end
baz = Baz.new
p baz.hexdigest('foo')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment