Skip to content

Instantly share code, notes, and snippets.

@nanodeath
Created April 26, 2009 04:10
Show Gist options
  • Save nanodeath/101879 to your computer and use it in GitHub Desktop.
Save nanodeath/101879 to your computer and use it in GitHub Desktop.
def method_missing(meth, *args)
i = 0
attributes = args.map do
i += 1
"var#{i}"
end
st = Struct.new("TempVar", *attributes).new
target_inst = eval('self', @binding)
i = 1
while target_inst.respond_to? "__tmp_slate#{i}".to_sym
i += 1
end
method = "__tmp_slate#{i}".to_sym
target_inst.instance_eval "def #{method}; @#{method}; end"
target_inst.instance_eval "def #{method}=(val); @#{method}=val; end"
i = 0
eval_args = []
args.each do |a|
i += 1
st["var#{i}"] = a
eval_args << "#{method}['var#{i}']"
end
target_inst.send "#{method}=", st
eval_string = "%s(%s)" % [meth, eval_args.join(",")]
eval(eval_string, @binding)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment