Skip to content

Instantly share code, notes, and snippets.

@jamesmacaulay
Created May 29, 2014 16:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmacaulay/76a7362589a37cf4d618 to your computer and use it in GitHub Desktop.
Save jamesmacaulay/76a7362589a37cf4d618 to your computer and use it in GitHub Desktop.
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