Skip to content

Instantly share code, notes, and snippets.

@supermomonga
Created June 10, 2013 01:24
Show Gist options
  • Save supermomonga/5745994 to your computer and use it in GitHub Desktop.
Save supermomonga/5745994 to your computer and use it in GitHub Desktop.
def godef(inputs, returns, &func)
Proc.new do | *args |
obj = Object.new
inputs.map.with_index{|v, i| obj.instance_variable_set(v, args[i])}
returns.map{|v| obj.instance_variable_set(v, nil) }
obj.instance_eval(&func)
returns.map{|v| obj.instance_variable_get(v) }
end
end
my_awesome_method = godef [:@n, :@p], [:@hoge,:@moge] do
@hoge = @n * 10
@moge = @p * 100
end
p my_awesome_method.call(2, 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment