Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created July 3, 2022 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/1a297c2e1fcedf9a8b5d557b6dea6b60 to your computer and use it in GitHub Desktop.
Save havenwood/1a297c2e1fcedf9a8b5d557b6dea6b60 to your computer and use it in GitHub Desktop.
My example for Ruby #irc showing how you can contort and mixin class methods.
require 'digest/md5'
class_name = Digest::MD5
module class_name::Mixin
end
class_name::Mixin.class_eval do
class_name.public_methods(false).each do |method_name|
define_method method_name, class_name.public_method(method_name).to_proc
end
end
# Example usage
include Digest::MD5::Mixin
p hexdigest 'foo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment