Skip to content

Instantly share code, notes, and snippets.

@showaltb
Created November 22, 2018 17:38
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 showaltb/da9e8773211f9e7b62d2a52ec2047eb2 to your computer and use it in GitHub Desktop.
Save showaltb/da9e8773211f9e7b62d2a52ec2047eb2 to your computer and use it in GitHub Desktop.
Example of using define_method in a mixin to define a method in an including class/module
module MyMixin
def self.included(other)
other.instance_eval do
define_method :bar do
puts 'bar called'
end
end
end
end
class MyClass
include MyMixin
def foo
puts 'foo called'
end
end
p MyClass.instance_methods(false)
# => [:bar, :foo]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment