Created
December 22, 2011 08:38
-
-
Save moro/1509540 to your computer and use it in GitHub Desktop.
include with arguments.
This file contains hidden or 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
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