------ art_145_31948876.1321288863978
Content-Type: multipart/alternative;
boundary --- art_146_26743045.1321288863979"
------ art_146_26743045.1321288863979
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Well, this seems to work:
#
def with(_hash, &_yield)
_hash _hash || {}).to_hash
code <-END
define_method(:_with) do |#{_hash.keys.join(',')}|
binding
end
END
(class << self; self; end).class_eval(code)
b with(*_hash.values, &_yield)
(class << self; self; end).class_eval{ remove_method(:_with) }
return b
#eval("Proc.new{ |#{_hash.keys.join(',')}| binding
}").call(*_hash.values)
end
But alas, now I am loosing the context of original binding. Why is that? I
thought define_method kept closure.
------ art_146_26743045.1321288863979
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<div>Well, this seems to work:</div><div><br></div><div> #</div><div> def with(_hash, &_yield)</div><div> _hash _hash || {}).to_hash</div><div> code lt;<-END</div><div> define_method(:_with) do |#{_hash.keys.join(',')}|</div><div> binding</div><div> end</div><div> END</div><div> (class << self; self; end).class_eval(code)</div><div> b with(*_hash.values, &_yield)</div><div> (class << self; self; end).class_eval{ remove_method(:_with) }</div><div> return b</div><div> #eval("Proc.new{ |#{_hash.keys.join(',')}| binding }").call(*_hash.values)</div><div> end</div><div><br></div><div>But alas, now I am loosing the context of original binding. Why is that? I thought define_method kept closure.<br></div><div><br></div>
------ art_146_26743045.1321288863979--
------ art_145_31948876.1321288863978--