Created
April 26, 2009 04:10
-
-
Save nanodeath/101879 to your computer and use it in GitHub Desktop.
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
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