Created
May 29, 2014 16:25
-
-
Save jamesmacaulay/76a7362589a37cf4d618 to your computer and use it in GitHub Desktop.
This file contains 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
class Module | |
# Takes symbols representing instance methods defined in the module. | |
# Returns a new anonymous module with only those instance methods defined. | |
def slice(*methods) | |
src = self | |
Module.new do | |
methods.each do |sym| | |
define_method(sym, src.instance_method(sym)) | |
end | |
end | |
end | |
alias_method :only, :slice | |
end | |
class SomeClass | |
# yay for being explicit! | |
include SomeModule.only(:some_method) | |
include SomeOtherModule.only(:some_other_method) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment