Created
July 8, 2014 06:39
-
-
Save moro/d1c2efb7187bd26f1e4a 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
module Constructor | |
def constructor(*names) | |
define_method(:initialize) do |*args| | |
names.zip(args).each do |name, value| | |
instance_variable_set("@#{name}", value) | |
end | |
end | |
end | |
end | |
class Hi | |
extend Constructor | |
constructor :foo, :bar | |
def do | |
p @foo | |
p @bar | |
end | |
end | |
Hi.new('FOO', 'BAR').do |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment