Skip to content

Instantly share code, notes, and snippets.

@moro
Created December 22, 2011 08:38
Show Gist options
  • Save moro/1509540 to your computer and use it in GitHub Desktop.
Save moro/1509540 to your computer and use it in GitHub Desktop.
include with arguments.
module IncludeWithArgs
def self.extended(mod)
Kernel.send(:define_method, mod.name) do |*args|
Module.new do
include mod
define_method :args do args end
private :args
end
end
end
end
module Foo
extend IncludeWithArgs
def foo
args.first
end
end
class Hoge
include Foo(:foo, :bar)
end
puts Hoge.new.foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment