Skip to content

Instantly share code, notes, and snippets.

@moro
Created July 8, 2014 06:39
Show Gist options
  • Save moro/d1c2efb7187bd26f1e4a to your computer and use it in GitHub Desktop.
Save moro/d1c2efb7187bd26f1e4a to your computer and use it in GitHub Desktop.
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